<commit_before># vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""
Rackspace API Endpoint
"""

import json
import time

import webob.dec
import webob.exc

from nova import flags
from nova import rpc
from nova import utils
from nova import wsgi
from nova.auth import manager
from nova.compute import model as compute
from nova.network import model as network


FLAGS = flags.FLAGS
flags.DEFINE_string('cloud_topic', 'cloud', 'the topic clouds listen on')


class API(wsgi.Middleware):
    """Entry point for all requests."""

    def __init__(self):
        super(API, self).__init__(Router(webob.exc.HTTPNotFound()))

    def __call__(self, environ, start_response):
        context = {}
        if "HTTP_X_AUTH_TOKEN" in environ:
            context['user'] = manager.AuthManager().get_user_from_access_key(
                              environ['HTTP_X_AUTH_TOKEN'])
            if context['user']:
                context['project'] = manager.AuthManager().get_project(
                                     context['user'].name)
        if "user" not in context:
            return webob.exc.HTTPForbidden()(environ, start_response)
        environ['nova.context'] = context
        return self.application(environ, start_response)


class Router(wsgi.Router):
    """Route requests to the next WSGI application."""

    def _build_map(self):
        """Build routing map for authentication and cloud."""
        self._connect("/v1.0", controller=AuthenticationAPI())
        cloud = CloudServerAPI()
        self._connect("/servers", controller=cloud.launch_server,
                      conditions={"method": ["POST"]})
        self._connect("/servers/{server_id}", controller=cloud.delete_server,
                      conditions={'method': ["DELETE"]})
        self._connect("/servers", controller=cloud)


class AuthenticationAPI(wsgi.Application):
    """Handle all authorization requests through WSGI applications."""

    @webob.dec.wsgify<commit_msg>work on a router that works with wsgi and non-wsgi routing<commit_after># vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""
Rackspace API Endpoint
"""

import json
import time

import webob.dec
import webob.exc

from nova import flags
from nova import rpc
from nova import utils
from nova import wsgi
from nova.auth import manager
from nova.compute import model as compute
from nova.network import model as network


FLAGS = flags.FLAGS
flags.DEFINE_string('cloud_topic', 'cloud', 'the topic clouds listen on')


class API(wsgi.Middleware):
    """Entry point for all requests."""

    def __init__(self):
        super(API, self).__init__(Router(webob.exc.HTTPNotFound()))

    @webob.dec.wsgify
    def __call__(self, req):
        return self.application
        context = {}
        if "HTTP_X_AUTH_TOKEN" in req.environ:
            context['user'] = manager.AuthManager().get_user_from_access_key(
                              req.environ['HTTP_X_AUTH_TOKEN'])
            if context['user']:
                context['project'] = manager.AuthManager().get_project(
                                     context['user'].name)
        if "user" not in context:
            return webob.exc.HTTPForbidden()
        environ['nova.context'] = context
        return self.application


class Router(wsgi.Router):
    """Route requests to the next WSGI application."""

    def _build_map(self):
        """Build routing map for authentication and cloud."""
        self.map.resource("server", "servers", controller=CloudServerAPI())
        #self._connect("/v1.0", controller=AuthenticationAPI())
        #cloud = CloudServerAPI()
        #self._connect("/servers", controller=cloud.launch_server,
        #              conditions={"method": ["POST"]})
        #self._connect("/servers/{server_id}", controller=cloud.delete_server,
        #              conditions={'method': ["DELETE"]})
        #self._connect("/servers", controller=cloud)


class AuthenticationAPI(wsgi.Application):
    """Handle all authorization requests through WSGI applications."""

    @webob.dec.wsgify
{'fraction_non_alphanumeric': 0.10032715376226826, 'fraction_numerical': 0.004725554343874954, 'mean_word_length': 3.0944940476190474, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3596173', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1451, 'n_words': 488}