當前位置: 首頁>>代碼示例>>Python>>正文


Python routing.Map方法代碼示例

本文整理匯總了Python中werkzeug.routing.Map方法的典型用法代碼示例。如果您正苦於以下問題:Python routing.Map方法的具體用法?Python routing.Map怎麽用?Python routing.Map使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在werkzeug.routing的用法示例。


在下文中一共展示了routing.Map方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def __init__(self, config, duration, errors):
        self._config = config
        self._duration = duration
        self._errors = errors

        self._url_map = Map([
            Rule('/', endpoint='index'),
            Rule('/metrics', endpoint='metrics'),
            Rule('/pve', endpoint='pve'),
        ])

        self._args = {
            'pve': ['module', 'target']
        }

        self._views = {
            'index': self.on_index,
            'metrics': self.on_metrics,
            'pve': self.on_pve,
        }

        self._log = logging.getLogger(__name__) 
開發者ID:prometheus-pve,項目名稱:prometheus-pve-exporter,代碼行數:24,代碼來源:http.py

示例2: __init__

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def __init__(self, imageserver: Server,
                 hostname: str, port: int,
                 *,
                 developer_mode: bool = False) -> None:  # pragma: no cover
        """
        :param imageserver: The imageserver to represent.
        :param hostname: The hostname to bind to.
        :param port: The port to bind to.
        :param developer_mode: Run in insecure web-developer mode; sets CORS to "*".
        """
        self.developer_mode = developer_mode
        self.imageserver = imageserver
        self.hostname = hostname
        self.port = port
        self.url_map = Map([
            Rule('/', endpoint='root'),
            Rule('/get', endpoint='get'),
            Rule('/status', endpoint='status'),
            Rule('/status/<what>', endpoint='status_what'),
            Rule('/reset', endpoint='reset'),
            Rule('/css/sourceIcons.css', endpoint='sourceicons')
        ]) 
開發者ID:k4cg,項目名稱:nichtparasoup,代碼行數:24,代碼來源:webserver.py

示例3: _init_app

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def _init_app(self, middleware=None):
        """Initialize a WSGI application for handling POST to '/'.

        `middleware` may be provided as WSGI middleware.

        """
        routes = routing.Map([
            routing.Rule('/', endpoint=self._handle_inference),
            routing.Rule('/ping', endpoint=self._handle_ping),
            routing.Rule('/shutdown', endpoint=self._handle_shutdown),
        ])
        def app(env, start_resp):
            """WSGI application to handle server requests.

            """
            urls = routes.bind_to_environ(env)
            try:
                handler, _kw = urls.match()
                req = Request(env)
                if middleware:
                    return middleware(handler, req)(env, start_resp)
                return handler(req)(env, start_resp)
            except HTTPException as e:
                return e(env, start_resp)
        return app 
開發者ID:iitzco,項目名稱:tfserve,代碼行數:27,代碼來源:tfserve.py

示例4: __init__

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def __init__(self, app=None):
        #: Compatibility with 'Flask' application.
        #: The :class:`~werkzeug.routing.Map` for this instance. You can use
        #: this to change the routing converters after the class was created
        #: but before any routes are connected.
        self.url_map = Map()

        #: Compatibility with 'Flask' application.
        #: All the attached blueprints in a dictionary by name. Blueprints
        #: can be attached multiple times so this dictionary does not tell
        #: you how often they got attached.
        self.blueprints = {}
        self._blueprint_order = []

        if app:
            self.init_app(app) 
開發者ID:priyankark,項目名稱:PhonePi_SampleServer,代碼行數:18,代碼來源:flask_sockets.py

示例5: test_dispatch

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def test_dispatch(self):
        env = create_environ('/')
        map = r.Map([
            r.Rule('/', endpoint='root'),
            r.Rule('/foo/', endpoint='foo')
        ])
        adapter = map.bind_to_environ(env)

        raise_this = None
        def view_func(endpoint, values):
            if raise_this is not None:
                raise raise_this
            return Response(repr((endpoint, values)))
        dispatch = lambda p, q=False: Response.force_type(adapter.dispatch(view_func, p,
                                                          catch_http_exceptions=q), env)

        assert dispatch('/').data == b"('root', {})"
        assert dispatch('/foo').status_code == 301
        raise_this = r.NotFound()
        self.assert_raises(r.NotFound, lambda: dispatch('/bar'))
        assert dispatch('/bar', True).status_code == 404 
開發者ID:GeekTrainer,項目名稱:Flask,代碼行數:23,代碼來源:routing.py

示例6: test_http_host_before_server_name

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def test_http_host_before_server_name(self):
        env = {
            'HTTP_HOST':            'wiki.example.com',
            'SERVER_NAME':          'web0.example.com',
            'SERVER_PORT':          '80',
            'SCRIPT_NAME':          '',
            'PATH_INFO':            '',
            'REQUEST_METHOD':       'GET',
            'wsgi.url_scheme':      'http'
        }
        map = r.Map([r.Rule('/', endpoint='index', subdomain='wiki')])
        adapter = map.bind_to_environ(env, server_name='example.com')
        assert adapter.match('/') == ('index', {})
        assert adapter.build('index', force_external=True) == 'http://wiki.example.com/'
        assert adapter.build('index') == '/'

        env['HTTP_HOST'] = 'admin.example.com'
        adapter = map.bind_to_environ(env, server_name='example.com')
        assert adapter.build('index') == 'http://wiki.example.com/' 
開發者ID:GeekTrainer,項目名稱:Flask,代碼行數:21,代碼來源:routing.py

示例7: test_server_name_interpolation

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def test_server_name_interpolation(self):
        server_name = 'example.invalid'
        map = r.Map([r.Rule('/', endpoint='index'),
                     r.Rule('/', endpoint='alt', subdomain='alt')])

        env = create_environ('/', 'http://%s/' % server_name)
        adapter = map.bind_to_environ(env, server_name=server_name)
        assert adapter.match() == ('index', {})

        env = create_environ('/', 'http://alt.%s/' % server_name)
        adapter = map.bind_to_environ(env, server_name=server_name)
        assert adapter.match() == ('alt', {})

        env = create_environ('/', 'http://%s/' % server_name)
        adapter = map.bind_to_environ(env, server_name='foo')
        assert adapter.subdomain == '<invalid>' 
開發者ID:GeekTrainer,項目名稱:Flask,代碼行數:18,代碼來源:routing.py

示例8: test_method_fallback

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def test_method_fallback(self):
        map = r.Map([
            r.Rule('/', endpoint='index', methods=['GET']),
            r.Rule('/<name>', endpoint='hello_name', methods=['GET']),
            r.Rule('/select', endpoint='hello_select', methods=['POST']),
            r.Rule('/search_get', endpoint='search', methods=['GET']),
            r.Rule('/search_post', endpoint='search', methods=['POST'])
        ])
        adapter = map.bind('example.com')
        assert adapter.build('index') == '/'
        assert adapter.build('index', method='GET') == '/'
        assert adapter.build('hello_name', {'name': 'foo'}) == '/foo'
        assert adapter.build('hello_select') == '/select'
        assert adapter.build('hello_select', method='POST') == '/select'
        assert adapter.build('search') == '/search_get'
        assert adapter.build('search', method='GET') == '/search_get'
        assert adapter.build('search', method='POST') == '/search_post' 
開發者ID:GeekTrainer,項目名稱:Flask,代碼行數:19,代碼來源:routing.py

示例9: test_double_defaults

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def test_double_defaults(self):
        for prefix in '', '/aaa':
            m = r.Map([
                r.Rule(prefix + '/', defaults={'foo': 1, 'bar': False}, endpoint='x'),
                r.Rule(prefix + '/<int:foo>', defaults={'bar': False}, endpoint='x'),
                r.Rule(prefix + '/bar/', defaults={'foo': 1, 'bar': True}, endpoint='x'),
                r.Rule(prefix + '/bar/<int:foo>', defaults={'bar': True}, endpoint='x')
            ])
            a = m.bind('example.com')

            assert a.match(prefix + '/') == ('x', {'foo': 1, 'bar': False})
            assert a.match(prefix + '/2') == ('x', {'foo': 2, 'bar': False})
            assert a.match(prefix + '/bar/') == ('x', {'foo': 1, 'bar': True})
            assert a.match(prefix + '/bar/2') == ('x', {'foo': 2, 'bar': True})

            assert a.build('x', {'foo': 1, 'bar': False}) == prefix + '/'
            assert a.build('x', {'foo': 2, 'bar': False}) == prefix + '/2'
            assert a.build('x', {'bar': False}) == prefix + '/'
            assert a.build('x', {'foo': 1, 'bar': True}) == prefix + '/bar/'
            assert a.build('x', {'foo': 2, 'bar': True}) == prefix + '/bar/2'
            assert a.build('x', {'bar': True}) == prefix + '/bar/' 
開發者ID:GeekTrainer,項目名稱:Flask,代碼行數:23,代碼來源:routing.py

示例10: test_server_name_casing

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def test_server_name_casing(self):
        m = r.Map([
            r.Rule('/', endpoint='index', subdomain='foo')
        ])

        env = create_environ()
        env['SERVER_NAME'] = env['HTTP_HOST'] = 'FOO.EXAMPLE.COM'
        a = m.bind_to_environ(env, server_name='example.com')
        assert a.match('/') == ('index', {})

        env = create_environ()
        env['SERVER_NAME'] = '127.0.0.1'
        env['SERVER_PORT'] = '5000'
        del env['HTTP_HOST']
        a = m.bind_to_environ(env, server_name='example.com')
        try:
            a.match()
        except r.NotFound:
            pass
        else:
            assert False, 'Expected not found exception' 
開發者ID:GeekTrainer,項目名稱:Flask,代碼行數:23,代碼來源:routing.py

示例11: fx_url_map

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def fx_url_map():
    return Map([
        Rule('/tokens/<token_id:token_id>', endpoint='create_session'),
        Rule('/fp/<fingerprint:fingerprint>', endpoint='get_key')
    ], converters={
        'token_id': TokenIdConverter,
        'fingerprint': FingerprintConverter
    }) 
開發者ID:spoqa,項目名稱:geofront,代碼行數:10,代碼來源:server_test.py

示例12: test_token_id_converter_match_success

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def test_token_id_converter_match_success(fx_url_map: Map, sample_id):
    path = '/tokens/' + sample_id
    urls = fx_url_map.bind('example.com', path)
    endpoint, values = urls.match(path)
    assert endpoint == 'create_session'
    assert values == {'token_id': sample_id} 
開發者ID:spoqa,項目名稱:geofront,代碼行數:8,代碼來源:server_test.py

示例13: test_token_id_converter_match_failure

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def test_token_id_converter_match_failure(fx_url_map: Map, sample_id):
    path = '/tokens/' + sample_id
    urls = fx_url_map.bind('example.com', path)
    with raises(NotFound):
        urls.match(path) 
開發者ID:spoqa,項目名稱:geofront,代碼行數:7,代碼來源:server_test.py

示例14: test_fingerprint_converter_match_success

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def test_fingerprint_converter_match_success(fx_url_map: Map, f_hex, f_bytes):
    path = '/fp/' + f_hex
    urls = fx_url_map.bind('example.com', path)
    endpoint, values = urls.match(path)
    assert endpoint == 'get_key'
    assert values == {'fingerprint': f_bytes} 
開發者ID:spoqa,項目名稱:geofront,代碼行數:8,代碼來源:server_test.py

示例15: test_fingerprint_converter_match_failure

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import Map [as 別名]
def test_fingerprint_converter_match_failure(fx_url_map: Map, sample_fp):
    path = '/fp/' + sample_fp
    urls = fx_url_map.bind('example.com', path)
    with raises(NotFound):
        urls.match(path) 
開發者ID:spoqa,項目名稱:geofront,代碼行數:7,代碼來源:server_test.py


注:本文中的werkzeug.routing.Map方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。