当前位置: 首页>>代码示例>>Python>>正文


Python routes.Mapper方法代码示例

本文整理汇总了Python中routes.Mapper方法的典型用法代码示例。如果您正苦于以下问题:Python routes.Mapper方法的具体用法?Python routes.Mapper怎么用?Python routes.Mapper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在routes的用法示例。


在下文中一共展示了routes.Mapper方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def __init__(self, root_directory, bucket_depth=0, mapper=None):
        if mapper is None:
            mapper = routes.Mapper()

        mapper.connect(
                '/',
                controller=lambda *a, **kw: RootHandler(self)(*a, **kw))
        mapper.connect(
                '/{bucket}/{object_name}',
                controller=lambda *a, **kw: ObjectHandler(self)(*a, **kw))
        mapper.connect(
                '/{bucket_name}',
                controller=lambda *a, **kw: BucketHandler(self)(*a, **kw),
                requirements={'bucket_name': '[^/]+/?'})
        self.directory = os.path.abspath(root_directory)
        fileutils.ensure_tree(self.directory)
        self.bucket_depth = bucket_depth
        super(S3Application, self).__init__(mapper) 
开发者ID:openstack,项目名称:ec2-api,代码行数:20,代码来源:s3server.py

示例2: test_router

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def test_router(self):

        class Application(common_wsgi.Application):
            """Test application to call from router."""

            def __call__(self, environ, start_response):
                start_response("200", [])
                return ['Router result']

        class Router(wsgi.Router):
            """Test router."""

            def __init__(self):
                mapper = routes.Mapper()
                mapper.connect("/test", controller=Application())
                super(Router, self).__init__(mapper)

        result = webob.Request.blank('/test').get_response(Router())
        self.assertEqual("Router result", result.body)
        result = webob.Request.blank('/bad').get_response(Router())
        self.assertNotEqual(result.body, "Router result") 
开发者ID:openstack,项目名称:manila,代码行数:23,代码来源:test_wsgi.py

示例3: __init__

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def __init__(self, full_result=False, **mapper_options):
        """
        Routes dispatcher

        Set full_result to True if you wish the controller
        and the action to be passed on to the page handler
        parameters. By default they won't be.
        """
        import routes
        self.full_result = full_result
        self.controllers = {}
        self.mapper = routes.Mapper(**mapper_options)
        self.mapper.controller_scan = self.controllers.keys 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:15,代码来源:_cpdispatch.py

示例4: routematch

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def routematch(self, url=None, environ=None):
        if url is "":
            result = self._match("", environ)
            return result[0], result[1]
        return routes.Mapper.routematch(self, url, environ) 
开发者ID:cloudbase,项目名称:vdi-broker,代码行数:7,代码来源:__init__.py

示例5: connect

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def connect(self, *args, **kwargs):
        # NOTE(inhye): Default the format part of a route to only accept json
        #             and xml so it doesn't eat all characters after a '.'
        #             in the url.
        kwargs.setdefault('requirements', {})
        if not kwargs['requirements'].get('format'):
            kwargs['requirements']['format'] = 'json|xml'
        return routes.Mapper.connect(self, *args, **kwargs) 
开发者ID:cloudbase,项目名称:vdi-broker,代码行数:10,代码来源:__init__.py

示例6: resource

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def resource(self, member_name, collection_name, **kwargs):
        if 'parent_resource' not in kwargs:
            kwargs['path_prefix'] = '{project_id}/'
        else:
            parent_resource = kwargs['parent_resource']
            p_collection = parent_resource['collection_name']
            p_member = parent_resource['member_name']
            kwargs['path_prefix'] = '{project_id}/%s/:%s_id' % (p_collection,
                                                                p_member)
        routes.Mapper.resource(self,
                               member_name,
                               collection_name,
                               **kwargs) 
开发者ID:cloudbase,项目名称:vdi-broker,代码行数:15,代码来源:__init__.py

示例7: __init__

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def __init__(self, mapper):
        """Create a router for the given routes.Mapper.

        Each route in `mapper` must specify a 'controller', which is a
        WSGI app to call.  You'll probably want to specify an 'action' as
        well and have your controller be an object that can route
        the request to the action-specific method.

        Examples:
          mapper = routes.Mapper()
          sc = ServerController()

          # Explicit mapping of one route to a controller+action
          mapper.connect(None, '/svrlist', controller=sc, action='list')

          # Actions are all implicitly defined
          mapper.resource('server', 'servers', controller=sc)

          # Pointing to an arbitrary WSGI app.  You can specify the
          # {path_info:.*} parameter so the target app can be handed just that
          # section of the URL.
          mapper.connect(None, '/v1.0/{path_info:.*}', controller=BlogApp())
        """
        mapper.redirect("", "/")
        self._mapper = mapper
        self._router = routes.middleware.RoutesMiddleware(self._dispatch, mapper) 
开发者ID:xgfone,项目名称:snippet,代码行数:28,代码来源:wsgi.py

示例8: routematch

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def routematch(self, url=None, environ=None):
        if url == "":
            result = self._match("", environ)
            return result[0], result[1]
        return routes.Mapper.routematch(self, url, environ) 
开发者ID:openstack,项目名称:searchlight,代码行数:7,代码来源:wsgi.py

示例9: __init__

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def __init__(self, mapper):
        """
        Create a router for the given routes.Mapper.

        Each route in `mapper` must specify a 'controller', which is a
        WSGI app to call.  You'll probably want to specify an 'action' as
        well and have your controller be a wsgi.Controller, who will route
        the request to the action method.

        Examples:
          mapper = routes.Mapper()
          sc = ServerController()

          # Explicit mapping of one route to a controller+action
          mapper.connect(None, "/svrlist", controller=sc, action="list")

          # Actions are all implicitly defined
          mapper.resource("server", "servers", controller=sc)

          # Pointing to an arbitrary WSGI app.  You can specify the
          # {path_info:.*} parameter so the target app can be handed just that
          # section of the URL.
          mapper.connect(None, "/v1.0/{path_info:.*}", controller=BlogApp())
        """
        mapper.redirect("", "/")
        self.map = mapper
        self._router = routes.middleware.RoutesMiddleware(self._dispatch,
                                                          self.map) 
开发者ID:openstack,项目名称:searchlight,代码行数:30,代码来源:wsgi.py

示例10: __init__

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def __init__(self, controller):
        mapper = routes.Mapper()
        mapper.resource("test", "tests",
                        controller=os_wsgi.Resource(controller))
        super(TestRouter, self).__init__(mapper) 
开发者ID:openstack,项目名称:manila,代码行数:7,代码来源:fakes.py

示例11: __init__

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def __init__(self, **config):
        self.config = config
        self.mapper = Mapper()
        self.registory = {}
        self._wsmanager = WebSocketManager()
        super(WSGIApplication, self).__init__()
        # XXX: Switch how to call the API of Routes for every version
        match_argspec = inspect.getargspec(self.mapper.match)
        if 'environ' in match_argspec.args:
            # New API
            self._match = self._match_with_environ
        else:
            # Old API
            self._match = self._match_with_path_info 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:16,代码来源:wsgi.py

示例12: connect

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def connect(self, *args, **kargs):
        kargs.setdefault('requirements', {})
        if not kargs['requirements'].get('format'):
            kargs['requirements']['format'] = 'json|xml'
        return routes.Mapper.connect(self, *args, **kargs) 
开发者ID:openstack,项目名称:masakari,代码行数:7,代码来源:__init__.py

示例13: resource

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def resource(self, member_name, collection_name, **kwargs):
        # NOTE(abhishekk): project_id parameter is only valid if its hex
        # or hex + dashes (note, integers are a subset of this). This
        # is required to hand our overlaping routes issues.
        project_id_regex = r'[0-9a-f\-]+'
        if CONF.osapi_v1.project_id_regex:
            project_id_regex = CONF.osapi_v1.project_id_regex

        project_id_token = '{project_id:%s}' % project_id_regex
        if 'parent_resource' not in kwargs:
            kwargs['path_prefix'] = '%s/' % project_id_token
        else:
            parent_resource = kwargs['parent_resource']
            p_collection = parent_resource['collection_name']
            p_member = parent_resource['member_name']
            kwargs['path_prefix'] = '%s/%s/:%s_id' % (
                project_id_token,
                p_collection,
                p_member)
        routes.Mapper.resource(
            self,
            member_name,
            collection_name,
            **kwargs)

        # while we are in transition mode, create additional routes
        # for the resource that do not include project_id.
        if 'parent_resource' not in kwargs:
            del kwargs['path_prefix']
        else:
            parent_resource = kwargs['parent_resource']
            p_collection = parent_resource['collection_name']
            p_member = parent_resource['member_name']
            kwargs['path_prefix'] = '%s/:%s_id' % (p_collection,
                                                   p_member)
        routes.Mapper.resource(self, member_name,
                               collection_name,
                               **kwargs) 
开发者ID:openstack,项目名称:masakari,代码行数:40,代码来源:__init__.py

示例14: __init__

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def __init__(self, controller, mapper=None):
        if not mapper:
            mapper = routes.Mapper()
        mapper.resource("test", "tests",
                        controller=os_wsgi.Resource(controller))
        super(TestRouter, self).__init__(mapper) 
开发者ID:openstack,项目名称:masakari,代码行数:8,代码来源:fakes.py

示例15: __init__

# 需要导入模块: import routes [as 别名]
# 或者: from routes import Mapper [as 别名]
def __init__(self, **local_config):
        mapper = routes_mapper.Mapper()
        ext_mgr = extensions.ExtensionManager.get_instance()
        ext_mgr.extend_resources("1.0", attributes.RESOURCE_ATTRIBUTE_MAP)
        super(APIRouter, self).__init__(mapper) 
开发者ID:openstack,项目名称:tacker,代码行数:7,代码来源:router.py


注:本文中的routes.Mapper方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。