本文整理汇总了Python中werkzeug.urls.iri_to_uri函数的典型用法代码示例。如果您正苦于以下问题:Python iri_to_uri函数的具体用法?Python iri_to_uri怎么用?Python iri_to_uri使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iri_to_uri函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_iri_safe_conversion
def test_iri_safe_conversion():
strict_eq(urls.iri_to_uri(u"magnet:?foo=bar"), "magnet:?foo=bar")
strict_eq(urls.iri_to_uri(u"itms-service://?foo=bar"), "itms-service:?foo=bar")
strict_eq(
urls.iri_to_uri(u"itms-service://?foo=bar", safe_conversion=True),
"itms-service://?foo=bar",
)
开发者ID:pallets,项目名称:werkzeug,代码行数:7,代码来源:test_urls.py
示例2: test_iri_support
def test_iri_support():
strict_eq(urls.uri_to_iri("http://xn--n3h.net/"), u"http://\u2603.net/")
strict_eq(
urls.uri_to_iri(b"http://%C3%BCser:p%C3%[email protected]/p%C3%A5th"),
u"http://\xfcser:p\[email protected]\u2603.net/p\xe5th",
)
strict_eq(urls.iri_to_uri(u"http://☃.net/"), "http://xn--n3h.net/")
strict_eq(
urls.iri_to_uri(u"http://üser:pä[email protected]☃.net/påth"),
"http://%C3%BCser:p%C3%[email protected]/p%C3%A5th",
)
strict_eq(
urls.uri_to_iri("http://test.com/%3Fmeh?foo=%26%2F"),
u"http://test.com/%3Fmeh?foo=%26%2F",
)
# this should work as well, might break on 2.4 because of a broken
# idna codec
strict_eq(urls.uri_to_iri(b"/foo"), u"/foo")
strict_eq(urls.iri_to_uri(u"/foo"), "/foo")
strict_eq(
urls.iri_to_uri(u"http://föö.com:8080/bam/baz"),
"http://xn--f-1gaa.com:8080/bam/baz",
)
开发者ID:pallets,项目名称:werkzeug,代码行数:26,代码来源:test_urls.py
示例3: __init__
def __init__(self, path='/', base_url=None, query_string=None,
method='GET', input_stream=None, content_type=None,
content_length=None, errors_stream=None, multithread=False,
multiprocess=False, run_once=False, headers=None, data=None,
environ_base=None, environ_overrides=None, charset='utf-8'):
path_s = make_literal_wrapper(path)
if query_string is None and path_s('?') in path:
path, query_string = path.split(path_s('?'), 1)
self.charset = charset
self.path = iri_to_uri(path)
if base_url is not None:
base_url = url_fix(iri_to_uri(base_url, charset), charset)
self.base_url = base_url
if isinstance(query_string, (bytes, text_type)):
self.query_string = query_string
else:
if query_string is None:
query_string = MultiDict()
elif not isinstance(query_string, MultiDict):
query_string = MultiDict(query_string)
self.args = query_string
self.method = method
if headers is None:
headers = Headers()
elif not isinstance(headers, Headers):
headers = Headers(headers)
self.headers = headers
if content_type is not None:
self.content_type = content_type
if errors_stream is None:
errors_stream = sys.stderr
self.errors_stream = errors_stream
self.multithread = multithread
self.multiprocess = multiprocess
self.run_once = run_once
self.environ_base = environ_base
self.environ_overrides = environ_overrides
self.input_stream = input_stream
self.content_length = content_length
self.closed = False
if data:
if input_stream is not None:
raise TypeError('can\'t provide input stream and data')
if hasattr(data, 'read'):
data = data.read()
if isinstance(data, text_type):
data = data.encode(self.charset)
if isinstance(data, bytes):
self.input_stream = BytesIO(data)
if self.content_length is None:
self.content_length = len(data)
else:
for key, value in _iter_data(data):
if isinstance(value, (tuple, dict)) or \
hasattr(value, 'read'):
self._add_file_from_data(key, value)
else:
self.form.setlistdefault(key).append(value)
开发者ID:Jiahui-Ruan,项目名称:Flask_SQL_Alchemy,代码行数:59,代码来源:test.py
示例4: test_iri_safe_conversion
def test_iri_safe_conversion(self):
self.assert_strict_equal(urls.iri_to_uri(u'magnet:?foo=bar'),
'magnet:?foo=bar')
self.assert_strict_equal(urls.iri_to_uri(u'itms-service://?foo=bar'),
'itms-service:?foo=bar')
self.assert_strict_equal(urls.iri_to_uri(u'itms-service://?foo=bar',
safe_conversion=True),
'itms-service://?foo=bar')
开发者ID:211sandiego,项目名称:calllog211,代码行数:8,代码来源:urls.py
示例5: test_iri_safe_conversion
def test_iri_safe_conversion():
strict_eq(urls.iri_to_uri(u'magnet:?foo=bar'),
'magnet:?foo=bar')
strict_eq(urls.iri_to_uri(u'itms-service://?foo=bar'),
'itms-service:?foo=bar')
strict_eq(urls.iri_to_uri(u'itms-service://?foo=bar',
safe_conversion=True),
'itms-service://?foo=bar')
开发者ID:char101,项目名称:werkzeug,代码行数:8,代码来源:test_urls.py
示例6: redirect
def redirect(location, code=302):
"""Return a response object (a WSGI application) that, if called,
redirects the client to the target location. Supported codes are 301,
302, 303, 305, and 307. 300 is not supported because it's not a real
redirect and 304 because it's the answer for a request with a request
with defined If-Modified-Since headers.
.. versionadded:: 0.6
The location can now be a unicode string that is encoded using
the :func:`iri_to_uri` function.
:param location: the location the response should redirect to.
:param code: the redirect status code. defaults to 302.
"""
from werkzeug.wrappers import Response
display_location = escape(location)
if isinstance(location, text_type):
# Safe conversion is necessary here as we might redirect
# to a broken URI scheme (for instance itms-services).
from werkzeug.urls import iri_to_uri
location = iri_to_uri(location, safe_conversion=True)
response = Response(
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n'
'<title>Redirecting...</title>\n'
'<h1>Redirecting...</h1>\n'
'<p>You should be redirected automatically to target URL: '
'<a href="%s">%s</a>. If not click the link.' %
(escape(location), display_location), code, mimetype='text/html')
response.headers['Location'] = location
return response
开发者ID:DaTrollMon,项目名称:werkzeug,代码行数:30,代码来源:utils.py
示例7: redirect
def redirect(location, code=302):
"""Return a response object (a WSGI application) that, if called,
redirects the client to the target location. Supported codes are 301,
302, 303, 305, and 307. 300 is not supported because it's not a real
redirect and 304 because it's the answer for a request with a request
with defined If-Modified-Since headers.
.. versionadded:: 0.6
The location can now be a unicode string that is encoded using
the :func:`iri_to_uri` function.
:param location: the location the response should redirect to.
:param code: the redirect status code. defaults to 302.
"""
display_location = escape(location)
if isinstance(location, str):
location = iri_to_uri(location)
response = Response(
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n'
'<title>Redirecting...</title>\n'
'<h1>Redirecting...</h1>\n'
'<p>You should be redirected automatically to target URL: '
'<a href="%s">%s</a>. If not click the link.' %
(escape(location), display_location), code, mimetype="text/html")
response.headers["Location"] = location
return response
开发者ID:robhudson,项目名称:warehouse,代码行数:26,代码来源:utils.py
示例8: redirect
def redirect(location, code=302):
"""Return a response object (a WSGI application) that, if called,
redirects the client to the target location. Supported codes are 301,
302, 303, 305, and 307. 300 is not supported because it's not a real
redirect and 304 because it's the answer for a request with a request
with defined If-Modified-Since headers.
.. versionadded:: 0.6
The location can now be unicode strings that are encoded using
the :func:`iri_to_uri` function.
:param location: the location the response should redirect to.
:param code: the redirect status code.
"""
assert code in (301, 302, 303, 305, 307), 'invalid code'
from werkzeug.wrappers import BaseResponse
display_location = location
if isinstance(location, unicode):
from werkzeug.urls import iri_to_uri
location = iri_to_uri(location)
response = BaseResponse(
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n'
'<title>Redirecting...</title>\n'
'<h1>Redirecting...</h1>\n'
'<p>You should be redirected automatically to target URL: '
'<a href="%s">%s</a>. If not click the link.' %
(location, display_location), code, mimetype='text/html')
response.headers['Location'] = location
return response
开发者ID:bguided,项目名称:synctester,代码行数:29,代码来源:utils.py
示例9: test_iri_support
def test_iri_support(self):
self.assert_raises(UnicodeError, urls.uri_to_iri, u'http://föö.com/')
self.assert_raises(UnicodeError, urls.iri_to_uri, 'http://föö.com/')
assert urls.uri_to_iri('http://xn--n3h.net/') == u'http://\u2603.net/'
assert urls.uri_to_iri('http://%C3%BCser:p%C3%[email protected]/p%C3%A5th') == \
u'http://\xfcser:p\[email protected]\u2603.net/p\xe5th'
assert urls.iri_to_uri(u'http://☃.net/') == 'http://xn--n3h.net/'
assert urls.iri_to_uri(u'http://üser:pä[email protected]☃.net/påth') == \
'http://%C3%BCser:p%C3%[email protected]/p%C3%A5th'
assert urls.uri_to_iri('http://test.com/%3Fmeh?foo=%26%2F') == \
u'http://test.com/%3Fmeh?foo=%26%2F'
# this should work as well, might break on 2.4 because of a broken
# idna codec
assert urls.uri_to_iri('/foo') == u'/foo'
assert urls.iri_to_uri(u'/foo') == '/foo'
开发者ID:sean-,项目名称:werkzeug,代码行数:17,代码来源:urls.py
示例10: process_bind_param
def process_bind_param(self, value, dialect):
if not value:
return value
if isinstance(value, str):
value = value.decode('utf-8')
# TODO: Ensure NFC order.
value = iri_to_uri(value)
return value
开发者ID:assembl,项目名称:assembl,代码行数:8,代码来源:sqla_types.py
示例11: redirect
def redirect(location, code = 302):
from werkzeug.wrappers import BaseResponse
display_location = location
if isinstance(location, unicode):
from werkzeug.urls import iri_to_uri
location = iri_to_uri(location)
response = BaseResponse('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>Redirecting...</title>\n<h1>Redirecting...</h1>\n<p>You should be redirected automatically to target URL: <a href="%s">%s</a>. If not click the link.' % (location, display_location), code, mimetype='text/html')
response.headers['Location'] = location
return response
开发者ID:Pluckyduck,项目名称:eve,代码行数:9,代码来源:utils.py
示例12: _redirect_to_nginx
def _redirect_to_nginx(location):
"""This creates an internal redirection to a specified location.
This feature is only supported by nginx. See http://wiki.nginx.org/X-accel
for more information about it.
"""
response = Response(status=200)
location = iri_to_uri(location, safe_conversion=True)
response.headers['X-Accel-Redirect'] = location
return response
开发者ID:caroline-gschwend,项目名称:metabrainz.org,代码行数:10,代码来源:views.py
示例13: test_iri_support
def test_iri_support(self):
self.assert_raises(UnicodeError, urls.uri_to_iri, u"http://föö.com/")
self.assert_raises(UnicodeError, urls.iri_to_uri, "http://föö.com/")
assert urls.uri_to_iri("http://xn--n3h.net/") == u"http://\u2603.net/"
assert (
urls.uri_to_iri("http://%C3%BCser:p%C3%[email protected]/p%C3%A5th")
== u"http://\xfcser:p\[email protected]\u2603.net/p\xe5th"
)
assert urls.iri_to_uri(u"http://☃.net/") == "http://xn--n3h.net/"
assert (
urls.iri_to_uri(u"http://üser:pä[email protected]☃.net/påth")
== "http://%C3%BCser:p%C3%[email protected]/p%C3%A5th"
)
assert urls.uri_to_iri("http://test.com/%3Fmeh?foo=%26%2F") == u"http://test.com/%3Fmeh?foo=%26%2F"
# this should work as well, might break on 2.4 because of a broken
# idna codec
assert urls.uri_to_iri("/foo") == u"/foo"
assert urls.iri_to_uri(u"/foo") == "/foo"
开发者ID:FakeSherlock,项目名称:Report,代码行数:20,代码来源:urls.py
示例14: test_uri_iri_normalization
def test_uri_iri_normalization(self):
uri = 'http://xn--f-rgao.com/%E2%98%90/fred?utf8=%E2%9C%93'
iri = u'http://föñ.com/\N{BALLOT BOX}/fred?utf8=\u2713'
tests = [
u'http://föñ.com/\N{BALLOT BOX}/fred?utf8=\u2713',
u'http://xn--f-rgao.com/\u2610/fred?utf8=\N{CHECK MARK}',
b'http://xn--f-rgao.com/%E2%98%90/fred?utf8=%E2%9C%93',
u'http://xn--f-rgao.com/%E2%98%90/fred?utf8=%E2%9C%93',
u'http://föñ.com/\u2610/fred?utf8=%E2%9C%93',
b'http://xn--f-rgao.com/\xe2\x98\x90/fred?utf8=\xe2\x9c\x93',
]
for test in tests:
self.assert_equal(urls.uri_to_iri(test), iri)
self.assert_equal(urls.iri_to_uri(test), uri)
self.assert_equal(urls.uri_to_iri(urls.iri_to_uri(test)), iri)
self.assert_equal(urls.iri_to_uri(urls.uri_to_iri(test)), uri)
self.assert_equal(urls.uri_to_iri(urls.uri_to_iri(test)), iri)
self.assert_equal(urls.iri_to_uri(urls.iri_to_uri(test)), uri)
开发者ID:ArslanRafique,项目名称:werkzeug,代码行数:20,代码来源:urls.py
示例15: test_uri_iri_normalization
def test_uri_iri_normalization():
uri = "http://xn--f-rgao.com/%E2%98%90/fred?utf8=%E2%9C%93"
iri = u"http://föñ.com/\N{BALLOT BOX}/fred?utf8=\u2713"
tests = [
u"http://föñ.com/\N{BALLOT BOX}/fred?utf8=\u2713",
u"http://xn--f-rgao.com/\u2610/fred?utf8=\N{CHECK MARK}",
b"http://xn--f-rgao.com/%E2%98%90/fred?utf8=%E2%9C%93",
u"http://xn--f-rgao.com/%E2%98%90/fred?utf8=%E2%9C%93",
u"http://föñ.com/\u2610/fred?utf8=%E2%9C%93",
b"http://xn--f-rgao.com/\xe2\x98\x90/fred?utf8=\xe2\x9c\x93",
]
for test in tests:
assert urls.uri_to_iri(test) == iri
assert urls.iri_to_uri(test) == uri
assert urls.uri_to_iri(urls.iri_to_uri(test)) == iri
assert urls.iri_to_uri(urls.uri_to_iri(test)) == uri
assert urls.uri_to_iri(urls.uri_to_iri(test)) == iri
assert urls.iri_to_uri(urls.iri_to_uri(test)) == uri
开发者ID:pallets,项目名称:werkzeug,代码行数:20,代码来源:test_urls.py
示例16: test_iri_support
def test_iri_support(self):
self.assert_strict_equal(urls.uri_to_iri('http://xn--n3h.net/'),
u'http://\u2603.net/')
self.assert_strict_equal(
urls.uri_to_iri(b'http://%C3%BCser:p%C3%[email protected]/p%C3%A5th'),
u'http://\xfcser:p\[email protected]\u2603.net/p\xe5th')
self.assert_strict_equal(urls.iri_to_uri(u'http://☃.net/'), 'http://xn--n3h.net/')
self.assert_strict_equal(
urls.iri_to_uri(u'http://üser:pä[email protected]☃.net/påth'),
'http://%C3%BCser:p%C3%[email protected]/p%C3%A5th')
self.assert_strict_equal(urls.uri_to_iri('http://test.com/%3Fmeh?foo=%26%2F'),
u'http://test.com/%3Fmeh?foo=%26%2F')
# this should work as well, might break on 2.4 because of a broken
# idna codec
self.assert_strict_equal(urls.uri_to_iri(b'/foo'), u'/foo')
self.assert_strict_equal(urls.iri_to_uri(u'/foo'), '/foo')
self.assert_strict_equal(urls.iri_to_uri(u'http://föö.com:8080/bam/baz'),
'http://xn--f-1gaa.com:8080/bam/baz')
开发者ID:ArslanRafique,项目名称:werkzeug,代码行数:21,代码来源:urls.py
示例17: _error_common
def _error_common(template, template_modal, code, e):
# g.is_ajax здесь не всегда присутствует, так что так
is_ajax = request.headers.get('X-AJAX') == '1' or request.args.get('isajax') == '1'
if is_ajax:
html = render_template(template_modal, error=e, error_code=code)
response = jsonify({'page_content': {'modal': html}})
response.status_code = code
# for github-fetch polyfill:
response.headers['X-Request-URL'] = iri_to_uri(request.url)
return response
html = render_template(template, error=e, error_code=code)
return html, code
开发者ID:andreymal,项目名称:mini_fiction,代码行数:13,代码来源:application.py
示例18: redirect
def redirect(location, status=302):
"""
which is seldom used in api server
"""
from werkzeug.wrappers import Response
from werkzeug.urls import iri_to_uri
location = iri_to_uri(location, safe_conversion=True)
return Response(
"<!DOCTYPE html>\
<html>\
<h1>Redirecting...</h1>\
<a href='{0}'>touch this to make manually redirection</a>\
</html>"
.format(location), status=status, headers={'Location': location})
开发者ID:ifkite,项目名称:spichi,代码行数:14,代码来源:utils.py
示例19: get_wsgi_headers
def get_wsgi_headers(self, environ):
headers = Headers(self.headers)
location = headers.get('location')
if location is not None:
if isinstance(location, unicode):
location = iri_to_uri(location)
headers['Location'] = urlparse.urljoin(get_current_url(environ, root_only=True), location)
content_location = headers.get('content-location')
if content_location is not None and isinstance(content_location, unicode):
headers['Content-Location'] = iri_to_uri(content_location)
if 100 <= self.status_code < 200 or self.status_code == 204:
headers['Content-Length'] = '0'
elif self.status_code == 304:
remove_entity_headers(headers)
if self.is_sequence and 'content-length' not in self.headers:
try:
content_length = sum((len(str(x)) for x in self.response))
except UnicodeError:
pass
else:
headers['Content-Length'] = str(content_length)
return headers
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:23,代码来源:wrappers.py
示例20: handle_get
def handle_get(path):
"""
Handle the GET
"""
path = '/api' + iri_to_uri(request.url).partition('/api')[-1]
if path == '/api':
abort(400)
logging.debug('Received %s', path)
dump = session.get(path)
logging.debug('From Fake APIC: %s', dump.json())
response = json.dumps(dump.json(), indent=4, separators=(',', ':'))
failure_hdlr.enforce_delay()
if failure_hdlr.enforce_connection_failure():
abort(400)
return response
开发者ID:JMSrulez,项目名称:acitoolkit,代码行数:15,代码来源:apic_test_harness.py
注:本文中的werkzeug.urls.iri_to_uri函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论