Example #1
0
 def __call__(self, environ, start_response):
     try:
         return self.application(environ, start_response)
     except Exception:
         import traceback;traceback.print_exc()
         return InternalServerError()(environ, start_response)
     finally:
         ContextLocals.purge()
Example #2
0
 def __call__(self, environ, start_response):
     try:
         return self.application(environ, start_response)
     except Exception:
         import traceback
         traceback.print_exc()
         return InternalServerError()(environ, start_response)
     finally:
         ContextLocals.purge()
Example #3
0
    def _execute_operation(self, request, subject=None, data=None):
        response = ServerResponse()
        controller = Controller()

        content = getattr(controller, request)(None, response, subject, data)
        if content and content is not response:
            response(content)
        if not response.status:
            response.status = OK

        ContextLocals.purge()
        return response
    def _execute_operation(self, request, subject=None, data=None):
        response = ServerResponse()
        controller = Controller()

        content = getattr(controller, request)(None, response, subject, data)
        if content and content is not response:
            response(content)
        if not response.status:
            response.status = OK

        ContextLocals.purge()
        return response
Example #5
0
 def __call__(self, environ, start_response):
     response = self.application(environ, start_response)
     ContextLocals.purge()
     return response
Example #6
0
from scheme import Sequence, Text, Tuple
from scheme.supplemental import ObjectReference
from werkzeug.exceptions import HTTPException, InternalServerError, NotFound
from werkzeug.local import Local, release_local
from werkzeug.routing import Map, RequestRedirect, Rule
from werkzeug.wrappers import Request as WsgiRequest, Response

from spire.core import *
from spire.local import ContextLocals
from spire.util import call_with_supported_params, enumerate_modules, is_class, is_module, is_package
from spire.wsgi.templates import TemplateEnvironment
from spire.wsgi.util import Mount

ContextLocal = ContextLocals.declare('wsgi.request')


class Request(WsgiRequest):
    """A WSGI request."""
    def __init__(self, application, environ, urls):
        super(Request, self).__init__(environ)
        self.application = application
        self.endpoint = None
        self.params = None
        self.template_context = {}
        self.urls = urls

        for name, value in environ.iteritems():
            if name[:8] == 'request.':
                setattr(self, name[8:], value)

    def bind(self):
Example #7
0
File: units.py Project: esho/spire
from scheme import *
from scheme.supplemental import ObjectReference
from scheme.surrogate import surrogate

from spire.core import *
from spire.context import ContextMiddleware, HeaderParser
from spire.local import ContextLocals
from spire.schema.fields import Column, TypeDecorator, types
from spire.wsgi.application import Request
from spire.wsgi.util import Mount

__all__ = ('Definition', 'DefinitionType', 'ExplicitContextManager', 'MeshClient',
    'MeshProxy', 'MeshDependency', 'MeshServer', 'Surrogate', 'SurrogateType')

CONTEXT_HEADER_PREFIX = 'X-SPIRE-'
ContextLocal = ContextLocals.declare('mesh.context')

class DefinitionType(TypeDecorator):
    impl = types.Text

    def process_bind_param(self, value, dialect):
        if value is not None:
            return json.dumps(value.describe(), sort_keys=True)

    def process_result_value(self, value, dialect):
        if value is not None:
            return Field.reconstruct(json.loads(value))

def Definition(**params):
    return Column(DefinitionType(), **params)
Example #8
0
from scheme.supplemental import ObjectReference
from scheme.surrogate import surrogate

from spire.core import *
from spire.context import ContextMiddleware, HeaderParser
from spire.local import ContextLocals
from spire.schema.fields import Column, TypeDecorator, types
from spire.wsgi.application import Request
from spire.wsgi.util import Mount

__all__ = ('Definition', 'DefinitionType', 'ExplicitContextManager',
           'MeshClient', 'MeshProxy', 'MeshDependency', 'MeshServer',
           'Surrogate', 'SurrogateType')

CONTEXT_HEADER_PREFIX = 'X-SPIRE-'
ContextLocal = ContextLocals.declare('mesh.context')


class DefinitionType(TypeDecorator):
    impl = types.Text

    def process_bind_param(self, value, dialect):
        if value is not None:
            return json.dumps(value.describe(), sort_keys=True)

    def process_result_value(self, value, dialect):
        if value is not None:
            return Field.reconstruct(json.loads(value))


def Definition(**params):
Example #9
0
from scheme import Sequence, Text, Tuple
from scheme.supplemental import ObjectReference
from werkzeug.exceptions import HTTPException, InternalServerError, NotFound
from werkzeug.local import Local, release_local
from werkzeug.routing import Map, RequestRedirect, Rule
from werkzeug.wrappers import Request as WsgiRequest, Response

from spire.core import *
from spire.local import ContextLocals
from spire.util import call_with_supported_params, enumerate_modules, is_class, is_module, is_package
from spire.wsgi.templates import TemplateEnvironment
from spire.wsgi.util import Mount

ContextLocal = ContextLocals.declare('wsgi.request')

class Request(WsgiRequest):
    """A WSGI request."""

    def __init__(self, application, environ, urls):
        super(Request, self).__init__(environ)
        self.application = application
        self.endpoint = None
        self.params = None
        self.template_context = {}
        self.urls = urls

        for name, value in environ.iteritems():
            if name[:8] == 'request.':
                setattr(self, name[8:], value)

    def bind(self):
Example #10
0
 def __call__(self, environ, start_response):
     response = self.application(environ, start_response)
     ContextLocals.purge()
     return response
Example #11
0
from scheme import Boolean, Text
from scheme.supplemental import ObjectReference
from sqlalchemy import MetaData, Table, create_engine, event
from sqlalchemy.engine.reflection import Inspector
from sqlalchemy.exc import NoSuchTableError
from sqlalchemy.orm.session import sessionmaker

from spire.core import *
from spire.local import ContextLocals
from spire.schema.dialect import get_dialect
from spire.schema.migration import MigrationInterface
from spire.util import get_package_path

__all__ = ('OperationError', 'Schema', 'SchemaDependency', 'SchemaInterface', 'ValidationError')

SessionLocals = ContextLocals.create_prefixed_proxy('schema.session')

class Schema(object):
    """A spire schema."""

    guard = Lock()
    schemas = {}

    def __new__(cls, name):
        cls.guard.acquire()
        try:
            try:
                return cls.schemas[name]
            except KeyError:
                instance = cls.schemas[name] = super(Schema, cls).__new__(cls)
                instance.constructors = []
Example #12
0
from scheme import Boolean, Text
from scheme.supplemental import ObjectReference
from sqlalchemy import MetaData, Table, create_engine, event
from sqlalchemy.engine.reflection import Inspector
from sqlalchemy.exc import NoSuchTableError
from sqlalchemy.orm.session import sessionmaker

from spire.core import *
from spire.local import ContextLocals
from spire.schema.dialect import get_dialect
from spire.schema.migration import MigrationInterface
from spire.util import get_package_path

__all__ = ('OperationError', 'Schema', 'SchemaDependency', 'SchemaInterface', 'ValidationError')

SessionLocals = ContextLocals.create_prefixed_proxy('schema.session')

class Schema(object):
    """A spire schema."""

    guard = Lock()
    schemas = {}

    def __new__(cls, name):
        cls.guard.acquire()
        try:
            try:
                return cls.schemas[name]
            except KeyError:
                instance = cls.schemas[name] = super(Schema, cls).__new__(cls)
                instance.constructors = []