本文整理汇总了Python中urlparse.urlunsplit方法的典型用法代码示例。如果您正苦于以下问题:Python urlparse.urlunsplit方法的具体用法?Python urlparse.urlunsplit怎么用?Python urlparse.urlunsplit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urlparse
的用法示例。
在下文中一共展示了urlparse.urlunsplit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def validate_(self, value, context=None):
url = self.valid_url(value)
if not url:
raise StopValidationError(self.messages['invalid_url'])
if self.verify_exists:
url_string = urlquote(urlunsplit((
url['scheme'],
(url['host6'] or url['host4'] or url['hostn_enc']) + ':' + (url['port'] or ''),
url['path'],
url['query'],
url['frag'])
).encode('utf-8'), safe=VALID_CHAR_STRING)
try:
urlopen(url_string)
except URLError:
raise StopValidationError(self.messages['not_found'])
示例2: goto
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def goto(self, href, method='get', **args):
"""
Go to the (potentially relative) link ``href``, using the
given method (``'get'`` or ``'post'``) and any extra arguments
you want to pass to the ``app.get()`` or ``app.post()``
methods.
All hostnames and schemes will be ignored.
"""
scheme, host, path, query, fragment = urlparse.urlsplit(href)
# We
scheme = host = fragment = ''
href = urlparse.urlunsplit((scheme, host, path, query, fragment))
href = urlparse.urljoin(self.request.full_url, href)
method = method.lower()
assert method in ('get', 'post'), (
'Only "get" or "post" are allowed for method (you gave %r)'
% method)
if method == 'get':
method = self.test_app.get
else:
method = self.test_app.post
return method(href, **args)
示例3: _convert_to_idn
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def _convert_to_idn(url):
"""Convert a URL to IDN notation"""
# this function should only be called with a unicode string
# strategy: if the host cannot be encoded in ascii, then
# it'll be necessary to encode it in idn form
parts = list(urlparse.urlsplit(url))
try:
parts[1].encode('ascii')
except UnicodeEncodeError:
# the url needs to be converted to idn notation
host = parts[1].rsplit(':', 1)
newhost = []
port = u''
if len(host) == 2:
port = host.pop()
for h in host[0].split('.'):
newhost.append(h.encode('idna').decode('utf-8'))
parts[1] = '.'.join(newhost)
if port:
parts[1] += ':' + port
return urlparse.urlunsplit(parts)
else:
return url
示例4: url_fix
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def url_fix(s, charset='utf-8'):
'''
Sometimes you get an URL by a user that just isn't a real
URL because it contains unsafe characters like ' ' and so on. This
function can fix some of the problems in a similar way browsers
handle data entered by the user:
>>> url_fix(u'http://de.wikipedia.org/wiki/Elf (Begriffsklärung)')
'http://de.wikipedia.org/wiki/Elf%20%28Begriffskl%C3%A4rung%29'
:param s: Url address.
:type s: string
:param charset: The target charset for the URL if the url was
given as unicode string. Default is 'utf-8'.
:type charset: string
:rtype: string
(taken from `werkzeug.utils <http://werkzeug.pocoo.org/docs/utils/>`_)
'''
if sys.version_info < (3, 0) and isinstance(s, unicode):
s = s.encode(charset, 'ignore')
scheme, netloc, path, qs, anchor = urlparse.urlsplit(s)
path = urllib.quote(path, '/%')
qs = urllib.quote_plus(qs, ':&=')
return urlparse.urlunsplit((scheme, netloc, path, qs, anchor))
示例5: generate_docservice_url
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def generate_docservice_url(request, doc_id, temporary=True, prefix=None):
docservice_key = getattr(request.registry, 'docservice_key', None)
parsed_url = urlparse(request.registry.docservice_url)
query = {}
if temporary:
expires = int(ttime()) + 300 # EXPIRES
mess = "{}\0{}".format(doc_id, expires)
query['Expires'] = expires
else:
mess = doc_id
if prefix:
mess = '{}/{}'.format(prefix, mess)
query['Prefix'] = prefix
query['Signature'] = quote(b64encode(docservice_key.signature(mess.encode("utf-8"))))
query['KeyID'] = docservice_key.hex_vk()[:8]
return urlunsplit((parsed_url.scheme, parsed_url.netloc, '/get/{}'.format(doc_id), urlencode(query), ''))
示例6: audit
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def audit(arg):
ooO0oooOoO0 = arg
II11i = urlparse.urlparse(ooO0oooOoO0)
i1oOOoo00O0O = urlparse.urlunsplit((II11i.scheme, II11i.netloc, II11i.path, "", ""))
Oo0Ooo = urlparse.parse_qsl(II11i.query)
i1111 = ['__VIEWSTATE', 'IbtnEnter.x', 'IbtnEnter.y']
i11 = ["GET", "POST"]
for I11 in i11:
for O0O0OO0O0O0, iiiii in Oo0Ooo:
if O0O0OO0O0O0 in i1111:
continue
debug('[XSS] <%s> %s %s', I11, O0O0OO0O0O0, i1oOOoo00O0O)
Oo0o0000o0o0 = iI1(I11, i1oOOoo00O0O, Oo0Ooo, O0O0OO0O0O0, iiiii)
if Oo0o0000o0o0:
security_info('<%s> %s' % (I11, Oo0o0000o0o0[1]))
return
示例7: giphy_translate
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def giphy_translate(text):
"""
Giphy translate method, uses the Giphy API to find an appropriate gif url
"""
params = {}
params['s'] = text
params['rating'] = RATING
params['api_key'] = GIPHY_API_KEY
resp = requests.get('https://api.giphy.com/v1/gifs/translate', params=params, verify=True)
if resp.status_code is not requests.codes.ok:
print('Encountered error using Giphy API, text=%s, status=%d, response_body=%s' % (text, resp.status_code, resp.json()))
return ''
resp_data = resp.json()
url = list(urlsplit(resp_data['data']['images']['original']['url']))
url[0] = SCHEME.lower()
return urlunsplit(url)
示例8: smart_urlquote
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def smart_urlquote(url):
"Quotes a URL if it isn't already quoted."
# Handle IDN before quoting.
scheme, netloc, path, query, fragment = urlsplit(url)
try:
netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE
except UnicodeError: # invalid domain part
pass
else:
url = urlunsplit((scheme, netloc, path, query, fragment))
url = unquote(force_str(url))
# See http://bugs.python.org/issue2637
url = quote(url, safe=b'!*\'();:@&=+$,/?#[]~')
return force_text(url)
示例9: __call__
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def __call__(self, value):
try:
super(URLValidator, self).__call__(value)
except ValidationError as e:
# Trivial case failed. Try for possible IDN domain
if value:
value = force_text(value)
scheme, netloc, path, query, fragment = urlsplit(value)
try:
netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE
except UnicodeError: # invalid domain part
raise e
url = urlunsplit((scheme, netloc, path, query, fragment))
super(URLValidator, self).__call__(url)
else:
raise
else:
url = value
示例10: url_fix
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def url_fix(self, charset = 'utf-8'):
"""
From http://stackoverflow.com/a/121017/854988
"""
if self.bypass_url_encoding:
return
if type(self.url) is bytes:
self.url = self._bytes_to_unicode(self.url, encoding = charset)
scheme, netloc, path, qs, anchor = urlparse.urlsplit(self.url)
if self.force_quote or not self.is_quoted(path):
path = urllib.quote(path, '/%')
if self.force_quote or not self.is_quoted_plus(qs):
qs = urllib.quote_plus(qs, '& = ')
self.url = urlparse.urlunsplit((scheme, netloc, path, qs, anchor))
示例11: urldefrag
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def urldefrag(url):
if "#" in url:
s, n, p, q, frag = urlsplit(url)
defrag = urlunsplit((s, n, p, q, ''))
else:
defrag = url
frag = ''
return defrag, frag
示例12: iri2uri
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def iri2uri(uri):
"""Convert an IRI to a URI. Note that IRIs must be
passed in a unicode strings. That is, do not utf-8 encode
the IRI before passing it into the function."""
if isinstance(uri, unicode):
(scheme, authority, path, query, fragment) = urlparse.urlsplit(uri)
authority = authority.encode("idna")
# For each character in 'ucschar' or 'iprivate'
# 1. encode as utf-8
# 2. then %-encode each octet of that utf-8
uri = urlparse.urlunsplit((scheme, authority, path, query, fragment))
uri = "".join([encode(c) for c in uri])
return uri
示例13: iri2uri
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def iri2uri(uri):
"""Convert an IRI to a URI. Note that IRIs must be
passed in a unicode strings. That is, do not utf-8 encode
the IRI before passing it into the function."""
if isinstance(uri ,unicode):
(scheme, authority, path, query, fragment) = urlparse.urlsplit(uri)
authority = authority.encode('idna')
# For each character in 'ucschar' or 'iprivate'
# 1. encode as utf-8
# 2. then %-encode each octet of that utf-8
uri = urlparse.urlunsplit((scheme, authority, path, query, fragment))
uri = "".join([encode(c) for c in uri])
return uri
示例14: _build_api_url
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def _build_api_url(url, query):
scheme, netloc, path, base_query, fragment = urlparse.urlsplit(url)
if base_query:
query = '%s&%s' % (base_query, query)
return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
示例15: url_without_fragment
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunsplit [as 别名]
def url_without_fragment(self):
scheme, netloc, path, query, fragment = urlparse.urlsplit(self.url)
return urlparse.urlunsplit((scheme, netloc, path, query, None))