本文整理匯總了Python中urlparse.unquote方法的典型用法代碼示例。如果您正苦於以下問題:Python urlparse.unquote方法的具體用法?Python urlparse.unquote怎麽用?Python urlparse.unquote使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類urlparse
的用法示例。
在下文中一共展示了urlparse.unquote方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: filename
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def filename(self):
'''Returns the filename to be used for saving the repo file.
The filename is derived from the repo url by injecting a suffix
after the name and before the file extension. This suffix is a
partial md5 checksum of the full repourl. This avoids multiple
repos from being written to the same file.
'''
urlpath = unquote(urlsplit(self.repourl, allow_fragments=False).path)
basename = os.path.basename(urlpath)
if not basename.endswith(REPO_SUFFIX):
basename += REPO_SUFFIX
if self.add_hash:
suffix = '-' + md5(self.repourl.encode('utf-8')).hexdigest()[:5] # nosec
else:
suffix = ''
final_name = suffix.join(os.path.splitext(basename))
return final_name
示例2: GET
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def GET(self, obj, query_params=None):
# Replace the a10_url with just the base path, stripping out any previous querystring
parse_result = urlparse.urlparse(obj.a10_url)
obj.a10_url = parse_result.path
obj.a10_url = self.url_encoder(obj.a10_url)
if query_params:
obj.a10_url += '?' + urlparse.unquote(urllib.urlencode(query_params))
conn = self.get_connection()
conn.request("GET", obj.a10_url, "", self.headers)
response = conn.getresponse()
conn.close()
obj.__setattr__("DEBUG_CONNECTION", conn.__dict__)
obj.__setattr__("DEBUG_Payload", "")
obj.__setattr__("DEBUG_Response", response)
obj.__setattr__("DEBUG_URL", obj.a10_url)
obj.__setattr__("DEBUG_headers", self.headers)
return self.request_handler("GET", obj, response)
# TODO: Due to Bug 175975, add zero_length kwarg to optionally send zero-length POST. Remove code once bug resolved
示例3: _ParseBaseRequest
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def _ParseBaseRequest(self, method):
"""Return path, headers and post data commonly required by all methods"""
try:
from urllib.parse import unquote, urlparse, parse_qsl
except ImportError:
from urlparse import unquote, urlparse, parse_qsl
path = py2_decode(urlparse(self.path).path[1:]) # Get URI without the trailing slash
path = path.split('/') # license/<asin>/<ATV endpoint>
Log('[PS] Requested {} path {}'.format(method, path), Log.DEBUG)
# Retrieve headers and data
headers = {k: self.headers[k] for k in self.headers if k not in ['host', 'content-length']}
data_length = self.headers.get('content-length')
data = {k: v for k, v in parse_qsl(self.rfile.read(int(data_length)))} if data_length else None
return (path, headers, data)
示例4: do_POST
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def do_POST(self):
"""Respond to POST requests"""
try:
from urllib.parse import unquote
except ImportError:
from urlparse import unquote
path, headers, data = self._ParseBaseRequest('POST')
if None is path: return
if ('gpr' == path[0]) and (2 == len(path)):
self._AlterGPR(unquote(path[1]), headers, data)
else:
Log('[PS] Invalid request received', Log.DEBUG)
self.send_error(501, 'Invalid request')
示例5: do_GET
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def do_GET(self):
"""Respond to GET requests"""
try:
from urllib.parse import unquote
except ImportError:
from urlparse import unquote
path, headers, data = self._ParseBaseRequest('GET')
if None is path: return
if ('mpd' == path[0]) and (2 == len(path)):
self._AlterMPD(unquote(path[1]), headers, data)
elif ('subtitles' == path[0]) and (3 == len(path)):
self._TranscodeSubtitle(unquote(path[1]), headers, data, path[2])
else:
Log('[PS] Invalid request received', Log.DEBUG)
self.send_error(501, 'Invalid request')
示例6: api_index
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def api_index(request):
if check_if_valid_token(request):
try:
token = urlparse.unquote(request.META['HTTP_AUTHORIZATION'])
user_id = extrapolate_user(token)
user = User.objects.get(user_id=user_id)
if user.is_admin:
data = serializers.serialize("json", User.objects.all())
return HttpResponse(data, content_type='application/json')
else:
data = serializers.serialize("json", User.objects.filter(user_id=user_id))
return HttpResponse(data, content_type='application/json')
except User.DoesNotExist:
return HttpResponse("null", content_type='application/json')
else:
return HttpResponse('Unauthorized', status=401)
示例7: check_if_valid_token
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def check_if_valid_token(request):
if 'HTTP_AUTHORIZATION' not in request.META:
return False
else:
token = urlparse.unquote(request.META['HTTP_AUTHORIZATION'])
regex = re.compile("(.*?)-(.*)")
split_token = token.split('=')[1]
regex_groups = regex.search(split_token)
if regex_groups.group(1):
group_id = regex_groups.group(1)
else:
return False
if regex_groups.group(2):
group_hash = regex_groups.group(2)
else:
return False
sha = SHA.new()
sha.update(ACCESS_TOKEN_SALT + ":" + str(group_id))
return group_hash == sha.hexdigest()
示例8: url2name
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def url2name(url):
from os.path import basename
url = url.split('|')[0]
return basename(unquote(urlparse.urlsplit(url)[2]))
示例9: parse_redis_url
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def parse_redis_url(url, password_quote):
"""Parses a redis URL."""
# create config with some sane defaults
redis_config = {
"DB": 0,
"PASSWORD": None,
"HOST": "localhost",
"PORT": 6379,
"SSL": False,
}
if not url:
return redis_config
url = urlparse.urlparse(url)
# Remove query strings.
path = url.path[1:]
path = path.split("?", 2)[0]
if path:
redis_config.update({"DB": int(path)})
if url.password:
password = url.password
if password_quote:
password = urlparse.unquote(password)
redis_config.update({"PASSWORD": password})
if url.hostname:
redis_config.update({"HOST": url.hostname})
if url.port:
redis_config.update({"PORT": int(url.port)})
if url.scheme in ["https", "rediss"]:
redis_config.update({"SSL": True})
return redis_config
示例10: unquote_bytes_to_wsgi
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def unquote_bytes_to_wsgi(bytestring):
return unquote_to_bytes(bytestring).decode('latin-1')
示例11: filename
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def filename(self):
_, netloc, path, _, _ = urlparse.urlsplit(self.url)
name = posixpath.basename(path.rstrip("/")) or netloc
name = urlparse.unquote(name)
assert name, "URL %r produced no filename" % self.url
return name
示例12: path
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def path(self):
return urlparse.unquote(urlparse.urlsplit(self.url)[2])
示例13: normalize
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def normalize(string):
unescaped = unescape(string)
unquoted = unquote(unescaped)
return unicodedata.normalize("NFKD", unquoted).replace('\n', '')
示例14: file_url_to_local_path
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def file_url_to_local_path(file_url):
parts = urlparse.urlparse(file_url)
path = urlparse.unquote(parts.path)
if path.startswith('/') and not path.startswith('//'):
if len(parts.netloc) == 2 and parts.netloc[1] == ':':
return parts.netloc + path
return 'C:' + path
if len(path) > 2 and path[1] == ':':
return path
示例15: path_from_uri
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import unquote [as 別名]
def path_from_uri(uri):
# Convert file uri to path (strip html like head part)
if not uri.startswith("file://"):
return uri
if os.name == "nt":
_, path = uri.split("file:///", 1)
else:
_, path = uri.split("file://", 1)
return os.path.normpath(unquote(path))