本文整理汇总了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'')