本文整理汇总了Python中werkzeug.urls.url_encode方法的典型用法代码示例。如果您正苦于以下问题:Python urls.url_encode方法的具体用法?Python urls.url_encode怎么用?Python urls.url_encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.urls
的用法示例。
在下文中一共展示了urls.url_encode方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dispatch_url
# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_encode [as 别名]
def dispatch_url(self, url_string):
url, url_adapter, query_args = self.parse_url(url_string)
try:
endpoint, kwargs = url_adapter.match()
except NotFound:
raise NotSupported(url_string)
except RequestRedirect as e:
new_url = "{0.new_url}?{1}".format(e, url_encode(query_args))
return self.dispatch_url(new_url)
try:
handler = import_string(endpoint)
request = Request(url=url, args=query_args)
return handler(request, **kwargs)
except RequestRedirect as e:
return self.dispatch_url(e.new_url)
示例2: request_authentication
# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_encode [as 别名]
def request_authentication(
self, redirect_url: str
) -> AuthenticationContinuation:
auth_nonce = ''.join(map('{:02x}'.format, os.urandom(16)))
self.states.append((auth_nonce, redirect_url))
url = 'http://example.com/auth/?' + url_encode({
'auth_nonce': auth_nonce,
'redirect_url': redirect_url
})
return AuthenticationContinuation(url, auth_nonce)
示例3: request_authentication
# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_encode [as 别名]
def request_authentication(
self, redirect_url: str
) -> AuthenticationContinuation:
auth_nonce = ''.join(map('{:02x}'.format, os.urandom(16)))
query = url_encode({
'client_id': self.client_id,
'redirect_uri': redirect_url,
'scope': self.authorize_scope,
'state': auth_nonce,
'response_type': 'code',
})
authorize_url = '{}?{}'.format(self.authorize_url, query)
return AuthenticationContinuation(authorize_url, auth_nonce)
示例4: request_authentication
# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_encode [as 别名]
def request_authentication(
self, redirect_url: str
) -> AuthenticationContinuation:
response = self.request('POST', self.REQUEST_TOKEN_URL.format(self))
request_token = url_decode_stream(response)
response.close()
return AuthenticationContinuation(
self.AUTHORIZE_URL.format(self) + '?' + url_encode({
'oauth_token': request_token['oauth_token'],
'oauth_callback': redirect_url
}),
(request_token['oauth_token'], request_token['oauth_token_secret'])
)
示例5: build
# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_encode [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
示例6: encode_query_args
# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_encode [as 别名]
def encode_query_args(self, query_args):
if not isinstance(query_args, string_types):
query_args = url_encode(query_args, self.map.charset)
return query_args
示例7: login_url
# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_encode [as 别名]
def login_url(login_view, next_url=None, next_field='next'):
'''
Creates a URL for redirecting to a login page. If only `login_view` is
provided, this will just return the URL for it. If `next_url` is provided,
however, this will append a ``next=URL`` parameter to the query string
so that the login view can redirect back to that URL.
:param login_view: The name of the login view. (Alternately, the actual
URL to the login view.)
:type login_view: str
:param next_url: The URL to give the login view for redirection.
:type next_url: str
:param next_field: What field to store the next URL in. (It defaults to
``next``.)
:type next_field: str
'''
if login_view.startswith(('https://', 'http://', '/')):
base = login_view
else:
base = url_for(login_view)
if next_url is None:
return base
parts = list(urlparse(base))
md = url_decode(parts[4])
md[next_field] = make_next_param(base, next_url)
parts[4] = url_encode(md, sort=True)
return urlunparse(parts)
示例8: _build_url
# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_encode [as 别名]
def _build_url(self, url, kwargs):
if 'qs' not in kwargs:
return url
qs = kwargs.pop('qs')
return '?'.join([url, url_encode(qs)])
示例9: delete_query
# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_encode [as 别名]
def delete_query(*new_values):
args = request.args.copy()
for key in new_values:
del args[key]
return '{}?{}'.format(request.path, url_encode(args))
示例10: modify_query
# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_encode [as 别名]
def modify_query(key, value):
args = request.args.copy()
args[key] = value
return '{}?{}'.format(request.path, url_encode(args))
示例11: build
# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_encode [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
示例12: test_run_template_http_url
# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_encode [as 别名]
def test_run_template_http_url(app, dataflow_job_name):
args = {
'project': PROJECT,
'job': dataflow_job_name,
'template': 'gs://dataflow-templates/latest/Word_Count',
'inputFile': 'gs://apache-beam-samples/shakespeare/kinglear.txt',
'output': 'gs://{}/dataflow/wordcount/outputs'.format(BUCKET),
}
with app.test_request_context('/?' + url_encode(args)):
res = main.run_template(flask.request)
data = json.loads(res)
assert 'test_run_template_url' in data['job']['name']
示例13: modify_query
# 需要导入模块: from werkzeug import urls [as 别名]
# 或者: from werkzeug.urls import url_encode [as 别名]
def modify_query(**new_values):
args = flask.request.args.copy()
args.pop('p', None)
for key, value in new_values.items():
args[key] = value
return '{}?{}'.format(flask.request.path, url_encode(args))