本文整理匯總了Python中werkzeug.urls.url_quote方法的典型用法代碼示例。如果您正苦於以下問題:Python urls.url_quote方法的具體用法?Python urls.url_quote怎麽用?Python urls.url_quote使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類werkzeug.urls
的用法示例。
在下文中一共展示了urls.url_quote方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post
# 需要導入模塊: from werkzeug import urls [as 別名]
# 或者: from werkzeug.urls import url_quote [as 別名]
def post(self):
if not may(CREATE):
raise Forbidden()
lang = request.form.get('language')
content_type = self.TRANS.get(lang)
content_type_hint = 'text/plain'
filename = None
t = request.form['code']
# t is already unicode, but we want utf-8 for storage
t = t.encode('utf-8')
size = len(t)
f = BytesIO(t)
maxlife_timestamp = FOREVER
name = create_item(f, filename, size, content_type, content_type_hint,
maxlife_stamp=maxlife_timestamp)
return redirect_next('bepasty.display', name=name, _anchor=url_quote(filename))
示例2: make_redirect_url
# 需要導入模塊: from werkzeug import urls [as 別名]
# 或者: from werkzeug.urls import url_quote [as 別名]
def make_redirect_url(self, path_info, query_args=None, domain_part=None):
"""Creates a redirect URL.
:internal:
"""
suffix = ''
if query_args:
suffix = '?' + self.encode_query_args(query_args)
return str('%s://%s/%s%s' % (
self.url_scheme,
self.get_host(domain_part),
posixpath.join(self.script_name[:-1].lstrip('/'),
url_quote(path_info.lstrip('/'), self.map.charset,
safe='/:|+')),
suffix
))
示例3: get_query_string
# 需要導入模塊: from werkzeug import urls [as 別名]
# 或者: from werkzeug.urls import url_quote [as 別名]
def get_query_string(environ):
"""Returns the `QUERY_STRING` from the WSGI environment. This also takes
care about the WSGI decoding dance on Python 3 environments as a
native string. The string returned will be restricted to ASCII
characters.
.. versionadded:: 0.9
:param environ: the WSGI environment object to get the query string from.
"""
qs = wsgi_get_bytes(environ.get('QUERY_STRING', ''))
# QUERY_STRING really should be ascii safe but some browsers
# will send us some unicode stuff (I am looking at you IE).
# In that case we want to urllib quote it badly.
return try_coerce_native(url_quote(qs, safe=':&%=+$!*\'(),'))
示例4: build
# 需要導入模塊: from werkzeug import urls [as 別名]
# 或者: from werkzeug.urls import url_quote [as 別名]
def build(self, values, append_unknown=True):
"""Assembles the relative url for that rule and the subdomain.
If building doesn't work for some reasons `None` is returned.
:internal:
"""
tmp = []
add = tmp.append
processed = set(self.arguments)
for is_dynamic, data in self._trace:
if is_dynamic:
try:
add(self._converters[data].to_url(values[data]))
except ValidationError:
return
processed.add(data)
else:
add(url_quote(to_bytes(data, self.map.charset), safe='/:|+'))
domain_part, url = (u''.join(tmp)).split(u'|', 1)
if append_unknown:
query_vars = MultiDict(values)
for key in processed:
if key in query_vars:
del query_vars[key]
if query_vars:
url += u'?' + url_encode(query_vars, charset=self.map.charset,
sort=self.map.sort_parameters,
key=self.map.sort_key)
return domain_part, url
示例5: to_url
# 需要導入模塊: from werkzeug import urls [as 別名]
# 或者: from werkzeug.urls import url_quote [as 別名]
def to_url(self, value):
return url_quote(value, charset=self.map.charset)
示例6: quote
# 需要導入模塊: from werkzeug import urls [as 別名]
# 或者: from werkzeug.urls import url_quote [as 別名]
def quote(self, value):
if self.has_slug:
return self.model.slug.slugify(value)
else:
return url_quote(value)
示例7: build
# 需要導入模塊: from werkzeug import urls [as 別名]
# 或者: from werkzeug.urls import url_quote [as 別名]
def build(self, values, append_unknown=True):
"""Assembles the relative url for that rule and the subdomain.
If building doesn't work for some reasons `None` is returned.
:internal:
"""
tmp = []
add = tmp.append
processed = set(self.arguments)
for is_dynamic, data in self._trace:
if is_dynamic:
try:
add(self._converters[data].to_url(values[data]))
except ValidationError:
return
processed.add(data)
else:
add(url_quote(to_bytes(data, self.map.charset), safe='/:|+'))
domain_part, url = (u''.join(tmp)).split(u'|', 1)
if append_unknown:
query_vars = MultiDict(values)
for key in processed:
if key in query_vars:
del query_vars[key]
if query_vars:
url += u'?' + url_encode(query_vars, charset=self.map.charset,
sort=self.map.sort_parameters,
key=self.map.sort_key)
return domain_part, url
示例8: send_file_inline
# 需要導入模塊: from werkzeug import urls [as 別名]
# 或者: from werkzeug.urls import url_quote [as 別名]
def send_file_inline(filename):
"""Send a file inline, including the original filename.
Ref: http://test.greenbytes.de/tech/tc2231/.
"""
try:
response = send_file(filename)
except FileNotFoundError:
return abort(404)
basename = os.path.basename(filename)
cont_disp = f"inline; filename*=UTF-8''{url_quote(basename)}"
response.headers["Content-Disposition"] = cont_disp
return response