Ejemplo n.º 1
0
 def __init__(self,
              version=None,
              base_url=None,
              discovery=False,
              cross_origin_enabled=False):
     self.metadata = Metadata(version=version, base_url=base_url)
     self.handlers = []
     self.discovery = discovery
     self.cross_origin_enabled = cross_origin_enabled
Ejemplo n.º 2
0
class TornadoRESTful(object):
    def __init__(self,
                 version=None,
                 base_url=None,
                 discovery=False,
                 cross_origin_enabled=False):
        self.metadata = Metadata(version=version, base_url=base_url)
        self.handlers = []
        self.discovery = discovery
        self.cross_origin_enabled = cross_origin_enabled

    def add_resource(self, path, handler, *args, **kw):
        normalized_path = path.rstrip('/').lstrip('/')
        handler.cross_origin_enabled = self.cross_origin_enabled
        self.add_url_mapping(normalized_path, handler)
        self.metadata.add(normalized_path, handler)

    def add_url_mapping(self, normalized_path, handler):
        self.handlers.append(('/{0}/?'.format(normalized_path), handler))
        self.handlers.append(
            ('/{0}\.(?P<force_return_type>\w+)'.format(normalized_path),
             handler))
        self.handlers.append(
            ('/{0}/(?P<key>[^.]+)\.(?P<force_return_type>\w+)'.format(
                normalized_path), handler))
        self.handlers.append(
            ('/{0}/(?P<key>.+)/?'.format(normalized_path), handler))

    def get_url_mapping(self):
        url_mapping = self.handlers
        if self.discovery:
            url_mapping = url_mapping + [
                ('/discovery\.(?P<force_return_type>\w+)', DiscoveryHandler, {
                    'api_spec': self.metadata.spec
                }),
                ('/discovery/(?P<resource_name>[\w_/]+)\.(?P<force_return_type>\w+)',
                 DiscoveryHandler, {
                     'api_spec': self.metadata.spec
                 })
            ]
        return url_mapping

    def get_spec(self):
        return self.metadata.spec
Ejemplo n.º 3
0
class TornadoRESTful(object):

    def __init__(self, version=None, base_url=None, discovery=False,
            cross_origin_enabled=False):
        self.metadata = Metadata(version=version, base_url=base_url)
        self.handlers = []
        self.discovery = discovery
        self.cross_origin_enabled = cross_origin_enabled

    def add_resource(self, path, handler, *args, **kw):
        normalized_path = path.rstrip('/').lstrip('/')
        handler.cross_origin_enabled = self.cross_origin_enabled
        self.add_url_mapping(normalized_path, handler)
        self.metadata.add(normalized_path, handler)

    def add_url_mapping(self, normalized_path, handler):
        self.handlers.append(('/{0}/?'.format(normalized_path), handler))
        self.handlers.append(('/{0}\.(?P<force_return_type>\w+)'
                .format(normalized_path), handler))
        self.handlers.append(('/{0}/(?P<key>[^.]+)\.(?P<force_return_type>\w+)'
                .format(normalized_path), handler))
        self.handlers.append(('/{0}/(?P<key>.+)/?'
                .format(normalized_path), handler))

    def get_url_mapping(self):
        url_mapping = self.handlers
        if self.discovery:
            url_mapping = url_mapping + [
            ('/discovery\.(?P<force_return_type>\w+)',
                DiscoveryHandler, {'api_spec': self.metadata.spec}),
            ('/discovery/(?P<resource_name>[\w_/]+)\.(?P<force_return_type>\w+)',
                DiscoveryHandler, {'api_spec': self.metadata.spec})
            ]
        return url_mapping

    def get_spec(self):
        return self.metadata.spec
Ejemplo n.º 4
0
 def __init__(self, version=None, base_url=None, discovery=False,
         cross_origin_enabled=False):
     self.metadata = Metadata(version=version, base_url=base_url)
     self.handlers = []
     self.discovery = discovery
     self.cross_origin_enabled = cross_origin_enabled