当前位置: 首页>>代码示例>>Python>>正文


Python parse.unquote_to_bytes方法代码示例

本文整理汇总了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 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:27,代码来源:client.py

示例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, ()) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:37,代码来源:test_urllib.py

示例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)) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:10,代码来源:test_urllib.py

示例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)) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:32,代码来源:test_urllib.py

示例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'') 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:7,代码来源:test_urlparse.py


注:本文中的future.backports.urllib.parse.unquote_to_bytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。