本文整理匯總了Python中future.backports.urllib.parse.unquote_to_bytes方法的典型用法代碼示例。如果您正苦於以下問題:Python parse.unquote_to_bytes方法的具體用法?Python parse.unquote_to_bytes怎麽用?Python parse.unquote_to_bytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類future.backports.urllib.parse
的用法示例。
在下文中一共展示了parse.unquote_to_bytes方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_host_info
# 需要導入模塊: from future.backports.urllib import parse [as 別名]
# 或者: from future.backports.urllib.parse import unquote_to_bytes [as 別名]
def get_host_info(self, host):
x509 = {}
if isinstance(host, tuple):
host, x509 = host
auth, host = urllib_parse.splituser(host)
if auth:
auth = urllib_parse.unquote_to_bytes(auth)
auth = base64.encodebytes(auth).decode("utf-8")
auth = "".join(auth.split()) # get rid of whitespace
extra_headers = [
("Authorization", "Basic " + auth)
]
else:
extra_headers = []
return host, extra_headers, x509
##
# Connect to server.
#
# @param host Target host.
# @return An HTTPConnection object
示例2: test_unquoting_badpercent
# 需要導入模塊: from future.backports.urllib import parse [as 別名]
# 或者: from future.backports.urllib.parse import unquote_to_bytes [as 別名]
def test_unquoting_badpercent(self):
# Test unquoting on bad percent-escapes
given = '%xab'
expect = given
result = urllib_parse.unquote(given)
self.assertEqual(expect, result, "using unquote(): %r != %r"
% (expect, result))
given = '%x'
expect = given
result = urllib_parse.unquote(given)
self.assertEqual(expect, result, "using unquote(): %r != %r"
% (expect, result))
given = '%'
expect = given
result = urllib_parse.unquote(given)
self.assertEqual(expect, result, "using unquote(): %r != %r"
% (expect, result))
# unquote_to_bytes
given = '%xab'
expect = bytes(given, 'ascii')
result = urllib_parse.unquote_to_bytes(given)
self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r"
% (expect, result))
given = '%x'
expect = bytes(given, 'ascii')
result = urllib_parse.unquote_to_bytes(given)
self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r"
% (expect, result))
given = '%'
expect = bytes(given, 'ascii')
result = urllib_parse.unquote_to_bytes(given)
self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r"
% (expect, result))
self.assertRaises((TypeError, AttributeError), urllib_parse.unquote_to_bytes, None)
self.assertRaises((TypeError, AttributeError), urllib_parse.unquote_to_bytes, ())
示例3: test_unquoting_mixed_case
# 需要導入模塊: from future.backports.urllib import parse [as 別名]
# 或者: from future.backports.urllib.parse import unquote_to_bytes [as 別名]
def test_unquoting_mixed_case(self):
# Test unquoting on mixed-case hex digits in the percent-escapes
given = '%Ab%eA'
expect = b'\xab\xea'
result = urllib_parse.unquote_to_bytes(given)
self.assertEqual(expect, result,
"using unquote_to_bytes(): %r != %r"
% (expect, result))
示例4: test_unquote_to_bytes
# 需要導入模塊: from future.backports.urllib import parse [as 別名]
# 或者: from future.backports.urllib.parse import unquote_to_bytes [as 別名]
def test_unquote_to_bytes(self):
given = 'br%C3%BCckner_sapporo_20050930.doc'
expect = b'br\xc3\xbcckner_sapporo_20050930.doc'
result = urllib_parse.unquote_to_bytes(given)
self.assertEqual(expect, result,
"using unquote_to_bytes(): %r != %r"
% (expect, result))
# Test on a string with unescaped non-ASCII characters
# (Technically an invalid URI; expect those characters to be UTF-8
# encoded).
result = urllib_parse.unquote_to_bytes("\u6f22%C3%BC")
expect = b'\xe6\xbc\xa2\xc3\xbc' # UTF-8 for "\u6f22\u00fc"
self.assertEqual(expect, result,
"using unquote_to_bytes(): %r != %r"
% (expect, result))
# Test with a bytes as input
given = b'%A2%D8ab%FF'
expect = b'\xa2\xd8ab\xff'
result = urllib_parse.unquote_to_bytes(given)
self.assertEqual(expect, result,
"using unquote_to_bytes(): %r != %r"
% (expect, result))
# Test with a bytes as input, with unescaped non-ASCII bytes
# (Technically an invalid URI; expect those bytes to be preserved)
given = b'%A2\xd8ab%FF'
expect = b'\xa2\xd8ab\xff'
result = urllib_parse.unquote_to_bytes(given)
self.assertEqual(expect, result,
"using unquote_to_bytes(): %r != %r"
% (expect, result))
示例5: test_unquote_to_bytes
# 需要導入模塊: from future.backports.urllib import parse [as 別名]
# 或者: from future.backports.urllib.parse import unquote_to_bytes [as 別名]
def test_unquote_to_bytes(self):
result = urllib_parse.unquote_to_bytes('abc%20def')
self.assertEqual(result, b'abc def')
result = urllib_parse.unquote_to_bytes('')
self.assertEqual(result, b'')