• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python wsgi.Route类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pulsar.apps.wsgi.Route的典型用法代码示例。如果您正苦于以下问题:Python Route类的具体用法?Python Route怎么用?Python Route使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: testSplitLeaf

 def testSplitLeaf(self):
     r = Route('bla/foo/<id>/pluto/leaf')
     p, l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertTrue(l.is_leaf)
     self.assertEqual(p.path, '/bla/foo/<id>/pluto/')
     self.assertEqual(l.path, '/leaf')
开发者ID:Danzeer,项目名称:pulsar,代码行数:7,代码来源:route.py


示例2: testIntVariable

 def testIntVariable(self):
     r = Route('<int:id>/')
     self.assertEqual(str(r), '/<int:id>/')
     self.assertEqual(r.variables, set(['id']))
     self.assertEqual(r.breadcrumbs, ((True, 'id'),))
     self.assertEqual(r.match('35/'), {'id': 35})
     self.assertEqual(r.url(id=1), '/1/')
     self.assertRaises(ValueError, r.url, id='bla')
开发者ID:Danzeer,项目名称:pulsar,代码行数:8,代码来源:route.py


示例3: testSplitDir

 def testSplitDir(self):
     r = Route('bla/foo/<id>/pluto/')
     self.assertEqual(r.level, 4)
     p, l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertFalse(l.is_leaf)
     self.assertEqual(p.path, '/bla/foo/<id>/')
     self.assertEqual(l.path, '/pluto/')
开发者ID:Danzeer,项目名称:pulsar,代码行数:8,代码来源:route.py


示例4: testRoot

 def testRoot(self):
     r = Route('/')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.rule, '')
     r = Route('////')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.rule, '')
     self.assertEqual(r.match(''), {})
     self.assertEqual(r.match('bee/'), {'__remaining__': 'bee/'})
开发者ID:Danzeer,项目名称:pulsar,代码行数:9,代码来源:route.py


示例5: testPathVaiable

 def testPathVaiable(self):
     r = Route('bla/<path:rest>', defaults={'rest': ''})
     self.assertEqual(r.variables, set(['rest']))
     self.assertEqual(r.level, 2)
     self.assertTrue(r.is_leaf)
     self.assertEqual(r.match('bla/a/b/c.html'), {'rest': 'a/b/c.html'})
     self.assertEqual(r.match('bla/'), {'rest': ''})
     self.assertEqual(r.url(rest='a/'), '/bla/a/')
     self.assertEqual(r.url(), '/bla/')
开发者ID:Danzeer,项目名称:pulsar,代码行数:9,代码来源:route.py


示例6: testSimple

 def testSimple(self):
     r = Route('bla/')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.level,1)
     self.assertEqual(len(r.variables), 0)
     self.assertEqual(r.rule,'bla/')
     self.assertEqual(r.match('bla/'),{})
     self.assertEqual(r.match('bladdd/'),None)
     self.assertEqual(r.match('bla/another/'), {'__remaining__':'another/'})
开发者ID:BazookaShao,项目名称:pulsar,代码行数:9,代码来源:route.py


示例7: testStringVariable

 def testStringVariable(self):
     r = Route('<name>/')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.variables, set(['name']))
     self.assertEqual(r.breadcrumbs, ((True, 'name'),))
     self.assertEqual(r.rule, '<name>/')
     self.assertEqual(r.match('bla-foo/'), {'name': 'bla-foo'})
     self.assertEqual(r.match('bla/another/'),
                      {'name': 'bla', '__remaining__': 'another/'})
     self.assertEqual(r.url(name='luca'), '/luca/')
开发者ID:Danzeer,项目名称:pulsar,代码行数:10,代码来源:route.py


示例8: test2StringVariables

 def test2StringVariables(self):
     r = Route('<name>/<child>/')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.level, 2)
     self.assertEqual(r.variables, set(['name', 'child']))
     self.assertEqual(r.breadcrumbs, ((True, 'name'), (True, 'child')))
     self.assertEqual(r.rule, '<name>/<child>/')
     self.assertEqual(r.match('bla/foo/'), {'name': 'bla', 'child': 'foo'})
     self.assertEqual(r.match('bla/foo/another/'),
                      {'name': 'bla',
                       'child': 'foo',
                       '__remaining__': 'another/'})
     self.assertRaises(KeyError, r.url, name='luca')
     self.assertEqual(r.url(name='luca', child='joshua'), '/luca/joshua/')
开发者ID:Danzeer,项目名称:pulsar,代码行数:14,代码来源:route.py


示例9: testIntVariableFixDigits

 def testIntVariableFixDigits(self):
     r = Route('<int(2):id>/')
     self.assertEqual(str(r),'/<int(2):id>/')
     self.assertEqual(r.variables, set(['id']))
     self.assertEqual(r.breadcrumbs, ((True,'id'),))
     self.assertEqual(r.match('35/'),{'id':35})
     self.assertEqual(r.match('355/'),None)
     self.assertEqual(r.match('6/'),None)
     self.assertEqual(r.match('ch/'),None)
     self.assertEqual(r.url(id = 13), '/13/')
     self.assertEqual(r.url(id = 1), '/01/')
     self.assertRaises(ValueError,lambda : r.url(id = 134))
     self.assertRaises(ValueError,lambda : r.url(id = 'bl'))
     self.assertRaises(ValueError,lambda : r.url(id = 'bla'))
开发者ID:BazookaShao,项目名称:pulsar,代码行数:14,代码来源:route.py


示例10: testIntVariableMinMax

 def testIntVariableMinMax(self):
     r = Route('<int(min=1):cid>/')
     self.assertEqual(str(r),'/<int(min=1):cid>/')
     self.assertEqual(r.variables, set(['cid']))
     self.assertEqual(r.breadcrumbs,((True,'cid'),))
     self.assertEqual(r.match('1/'),{'cid':1})
     self.assertEqual(r.match('476876/'),{'cid':476876})
     self.assertEqual(r.match('0/'),None)
     self.assertEqual(r.match('-5/'),None)
     self.assertEqual(r.url(cid = 13), '/13/')
     self.assertEqual(r.url(cid = 1), '/1/')
     self.assertRaises(ValueError,lambda : r.url(cid = 0))
     self.assertRaises(ValueError,lambda : r.url(cid = -10))
     self.assertRaises(ValueError,lambda : r.url(cid = 'bla'))
开发者ID:BazookaShao,项目名称:pulsar,代码行数:14,代码来源:route.py


示例11: page

    def page(self, path):
        '''Obtain a page object from a path
        '''
        key = self.cache_key()
        try:
            sitemap = self.app.cache_server.get_json(key)
            assert isinstance(sitemap, list)
        except Exception:
            sitemap = None

        if not sitemap:
            sitemap = self.build_map()
            self.app.cache_server.set_json(key, sitemap)

        for page in sitemap:
            route = Route(page['path'])
            if route.match(path):
                return page
开发者ID:victor3rc,项目名称:lux,代码行数:18,代码来源:views.py


示例12: match

    def match(self, path, sitemap=None):
        '''Match a path with a page form ``sitemap``

        If no sitemap is given, use the default sitemap
        form the :meth:`site_map` method.

        If no page is matched returns Nothing.
        '''
        if sitemap is None:
            sitemap = self.site_map(self.app)

        for page in sitemap:
            route = Route(page['path'])
            if isinstance(path, Route):
                if path == route:
                    return page
            else:
                matched = route.match(path)
                if matched is not None and '__remaining__' not in matched:
                    return page
开发者ID:pvanderlinden,项目名称:lux,代码行数:20,代码来源:cms.py


示例13: Proxy

class Proxy(LocalMixin):
    '''Proxy requests to another server
    '''
    def __init__(self, route, url):
        self.route = Route(route)
        self.url = url

    @local_property
    def http_client(self):
        '''The :class:`.HttpClient` used by this proxy middleware for
        accessing upstream resources'''
        return HttpClient(decompress=False, store_cookies=False)

    def __call__(self, environ, start_response):
        request = wsgi_request(environ)
        path = request.path
        match = self.route.match(path[1:])
        if match is not None:
            query = request.get('QUERY_STRING', '')
            path = urljoin(self.url, match.pop('__remaining__', ''))
            if query:
                path = '%s?%s' % (path, query)
            return self._call(request, path, start_response)

    @task
    def _call(self, request, path, start_response):
        data, files = yield from as_coroutine(request.data_and_files())
        response = yield from self.http_client.request(
            request.method, path, data=data, files=files,
            headers=self.request_headers(request.environ),
            version=request.get('SERVER_PROTOCOL'))
        response.raise_for_status()
        start_response(response.get_status(), list(response.headers))
        return [response.get_content()]

    def request_headers(self, environ):
        '''Fill request headers from the environ dictionary and
        modify them via the list of :attr:`headers_middleware`.
        The returned headers will be sent to the target uri.
        '''
        headers = Headers(kind='client')
        for k in environ:
            if k.startswith('HTTP_'):
                head = k[5:].replace('_', '-')
                headers[head] = environ[k]
        for head in ENVIRON_HEADERS:
            k = head.replace('-', '_').upper()
            v = environ.get(k)
            if v:
                headers[head] = v
        return headers
开发者ID:Danzeer,项目名称:pulsar,代码行数:51,代码来源:__init__.py


示例14: __init__

 def __init__(self, app, name, spec, spec_path, url, jwt=None, cors=True):
     self.init_app(app)
     if name == '*':
         name = ''
     self.spec = spec
     self.route = Route('%s/<path:path>' % name)
     self.url = url
     self.jwt = jwt
     self.cors = cors
     self.registry = {}
     self._spec_path = spec_path
     self._router = [Specification(spec_path, api=self)]
     self.spec.add_schema(ErrorSchema)
     self.spec.add_schema(ErrorMessageSchema)
开发者ID:quantmind,项目名称:lux,代码行数:14,代码来源:apis.py


示例15: testSplitRoot

 def testSplitRoot(self):
     r = Route('')
     self.assertEqual(r.level, 0)
     p, l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertEqual(p.path, '/')
     self.assertEqual(l, None)
     r = Route('bla')
     p, l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertTrue(l.is_leaf)
     self.assertEqual(p.path, '/')
     self.assertEqual(l.path, '/bla')
     r = Route('bla/')
     p, l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertFalse(l.is_leaf)
     self.assertEqual(p.path, '/')
     self.assertEqual(l.path, '/bla/')
开发者ID:Danzeer,项目名称:pulsar,代码行数:19,代码来源:route.py


示例16: Api

class Api(models.Component):
    """An Api is a set of OpenAPI paths under a base Url
    """
    def __init__(self, app, name, spec, spec_path, url, jwt=None, cors=True):
        self.init_app(app)
        if name == '*':
            name = ''
        self.spec = spec
        self.route = Route('%s/<path:path>' % name)
        self.url = url
        self.jwt = jwt
        self.cors = cors
        self.registry = {}
        self._spec_path = spec_path
        self._router = [Specification(spec_path, api=self)]
        self.spec.add_schema(ErrorSchema)
        self.spec.add_schema(ErrorMessageSchema)

    @property
    def spec_path(self):
        """Full path to Api Spec document
        """
        return (
            '%s/%s' % (self.url.path, self._spec_path) if self.url.path
            else self._spec_path
        )

    @classmethod
    def from_cfg(cls, app, cfg):
        schema = api_schema.load(cfg)
        if schema.errors:
            app.logger.error('Could not create Api: %s', schema.errors)
            return
        data = api_schema.dump(schema.data).data
        url = urlparse(data['BASE_PATH'])
        spec = OpenAPI(
            data['TITLE'],
            version=data['VERSION'],
            info=dict(description=data.get('DESCRIPTION', '')),
            plugins=data['SPEC_PLUGINS'],
            default_responses=app.config['DEFAULT_REST_RESPONSES']
        )
        return cls(app, data['MODEL'], spec, data['SPEC_PATH'], url,
                   cors=data['CORS'])

    def __repr__(self):
        return self.path
    __str__ = __repr__

    @property
    def path(self):
        return self.route.path

    @property
    def netloc(self):
        return self.spec.doc.get('host')

    @property
    def scheme(self):
        schemes = self.spec.doc.get('schemes')
        if schemes:
            return schemes[-1]

    def match(self, path):
        return self.route.match(path)

    def add_child(self, router):
        assert isinstance(self._router, list), 'Cannot add child'
        self._router.append(router)

    def router(self):
        """Return the base router of this API.

        If the base router is not available it first builds the paths and
        subsequently returns it
        """
        if isinstance(self._router, list):
            # base router
            root = RestRoot(self.url.path)
            for router in self._router:
                root.add_child(self._prepare_router(router))
            self._router = root
            # build the spec so that all lazy operations are done here
            json.dumps(self.spec_dict())
        return self._router

    def spec_dict(self):
        return self.spec.to_dict()

    # INTERNALS

    def _prepare_router(self, router):
        path = self.spec.add_path(router)
        #
        # inject api spec in the router
        router.api_spec = self.spec
        #
        # add CORS route to the router
        if self.cors:
            router.options = cors(
#.........这里部分代码省略.........
开发者ID:quantmind,项目名称:lux,代码行数:101,代码来源:apis.py


示例17: __init__

 def __init__(self, route, url):
     self.route = Route(route)
     self.url = url
开发者ID:Danzeer,项目名称:pulsar,代码行数:3,代码来源:__init__.py


示例18: testDefaults

 def testDefaults(self):
     r = Route('bla/<id>/add/<path:path>', {'path': ''})
     self.assertEqual(r.url(id=10), '/bla/10/add/')
     self.assertEqual(r.url(id=10, path='ciao/luca'),
                      '/bla/10/add/ciao/luca')
开发者ID:Danzeer,项目名称:pulsar,代码行数:5,代码来源:route.py


示例19: test_empty_url

 def test_empty_url(self):
     r = Route('')
     self.assertEqual(r.rule, '')
     self.assertEqual(r.url(), '/')
     self.assertEqual(r.path, '/')
开发者ID:Danzeer,项目名称:pulsar,代码行数:5,代码来源:route.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python provider.notify函数代码示例发布时间:2022-05-25
下一篇:
Python http.HttpClient类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap