本文整理汇总了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__)
示例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')
])
示例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
示例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)
示例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
示例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/'
示例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>'
示例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'
示例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/'
示例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'
示例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
})
示例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}
示例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)
示例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}
示例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)