當前位置: 首頁>>代碼示例>>Python>>正文


Python binascii.a2b_qp方法代碼示例

本文整理匯總了Python中binascii.a2b_qp方法的典型用法代碼示例。如果您正苦於以下問題:Python binascii.a2b_qp方法的具體用法?Python binascii.a2b_qp怎麽用?Python binascii.a2b_qp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在binascii的用法示例。


在下文中一共展示了binascii.a2b_qp方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_qp

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import a2b_qp [as 別名]
def test_qp(self):
        # A test for SF bug 534347 (segfaults without the proper fix)
        try:
            binascii.a2b_qp("", **{1:1})
        except TypeError:
            pass
        else:
            self.fail("binascii.a2b_qp(**{1:1}) didn't raise TypeError")
        self.assertEqual(binascii.a2b_qp("= "), "= ")
        self.assertEqual(binascii.a2b_qp("=="), "=")
        self.assertEqual(binascii.a2b_qp("=AX"), "=AX")
        self.assertRaises(TypeError, binascii.b2a_qp, foo="bar")
        self.assertEqual(binascii.a2b_qp("=00\r\n=00"), "\x00\r\n\x00")
        self.assertEqual(
            binascii.b2a_qp("\xff\r\n\xff\n\xff"),
            "=FF\r\n=FF\r\n=FF"
        )
        self.assertEqual(
            binascii.b2a_qp("0"*75+"\xff\r\n\xff\r\n\xff"),
            "0"*75+"=\r\n=FF\r\n=FF\r\n=FF"
        ) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:23,代碼來源:test_binascii.py

示例2: decodestring

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import a2b_qp [as 別名]
def decodestring(s, header = 0):
    if a2b_qp is not None:
        return a2b_qp(s, header = header)
    from cStringIO import StringIO
    infp = StringIO(s)
    outfp = StringIO()
    decode(infp, outfp, header = header)
    return outfp.getvalue()



# Other helper functions 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:14,代碼來源:quopri.py

示例3: from_fieldstorage

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import a2b_qp [as 別名]
def from_fieldstorage(cls, fs):
        """
        Create a dict from a cgi.FieldStorage instance
        """
        obj = cls()
        # fs.list can be None when there's nothing to parse
        for field in fs.list or ():
            charset = field.type_options.get('charset', 'utf8')
            transfer_encoding = field.headers.get('Content-Transfer-Encoding', None)
            supported_tranfer_encoding = {
                'base64' : binascii.a2b_base64,
                'quoted-printable' : binascii.a2b_qp
                }
            if PY3: # pragma: no cover
                if charset == 'utf8':
                    decode = lambda b: b
                else:
                    decode = lambda b: b.encode('utf8').decode(charset)
            else:
                decode = lambda b: b.decode(charset)
            if field.filename:
                field.filename = decode(field.filename)
                obj.add(field.name, field)
            else:
                value = field.value
                if transfer_encoding in supported_tranfer_encoding:
                    if PY3: # pragma: no cover
                        # binascii accepts bytes
                        value = value.encode('utf8')
                    value = supported_tranfer_encoding[transfer_encoding](value)
                    if PY3: # pragma: no cover
                        # binascii returns bytes
                        value = value.decode('utf8')
                obj.add(field.name, decode(value))
        return obj 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:37,代碼來源:multidict.py

示例4: test_not_implemented

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import a2b_qp [as 別名]
def test_not_implemented(self):
        test_cases = [
                        lambda: binascii.a2b_qp(None),
                        lambda: binascii.a2b_qp(None, None),
                        lambda: binascii.a2b_hqx(None),
                        lambda: binascii.rledecode_hqx(None),
                        lambda: binascii.rlecode_hqx(None),
                        lambda: binascii.b2a_hqx(None),
                        ]
        for temp_func in test_cases:
            self.assertRaises(NotImplementedError, temp_func) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_binascii.py

示例5: test_qp

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import a2b_qp [as 別名]
def test_qp(self):
        # A test for SF bug 534347 (segfaults without the proper fix)
        try:
            binascii.a2b_qp("", **{1:1})
        except TypeError:
            pass
        else:
            self.fail("binascii.a2b_qp(**{1:1}) didn't raise TypeError")
        self.assertEqual(binascii.a2b_qp("= "), "= ")
        self.assertEqual(binascii.a2b_qp("=="), "=")
        self.assertEqual(binascii.a2b_qp("=AX"), "=AX")
        self.assertRaises(TypeError, binascii.b2a_qp, foo="bar")
        self.assertEqual(binascii.a2b_qp("=00\r\n=00"), "\x00\r\n\x00")
        self.assertEqual(
            binascii.b2a_qp("\xff\r\n\xff\n\xff"),
            "=FF\r\n=FF\r\n=FF"
        )
        self.assertEqual(
            binascii.b2a_qp("0"*75+"\xff\r\n\xff\r\n\xff"),
            "0"*75+"=\r\n=FF\r\n=FF\r\n=FF"
        )

        self.assertEqual(binascii.b2a_qp('\0\n'), '=00\n')
        self.assertEqual(binascii.b2a_qp('\0\n', quotetabs=True), '=00\n')
        self.assertEqual(binascii.b2a_qp('foo\tbar\t\n'), 'foo\tbar=09\n')
        self.assertEqual(binascii.b2a_qp('foo\tbar\t\n', quotetabs=True), 'foo=09bar=09\n')

        self.assertEqual(binascii.b2a_qp('.'), '=2E')
        self.assertEqual(binascii.b2a_qp('.\n'), '=2E\n')
        self.assertEqual(binascii.b2a_qp('a.\n'), 'a.\n') 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:32,代碼來源:test_binascii.py

示例6: decodestring

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import a2b_qp [as 別名]
def decodestring(s, header=False):
    if a2b_qp is not None:
        return a2b_qp(s, header=header)
    from io import BytesIO
    infp = BytesIO(s)
    outfp = BytesIO()
    decode(infp, outfp, header=header)
    return outfp.getvalue()



# Other helper functions 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:14,代碼來源:quopri.py

示例7: test_qp

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import a2b_qp [as 別名]
def test_qp(self):
        binascii.a2b_qp(data=b"", header=False)  # Keyword arguments allowed

        # A test for SF bug 534347 (segfaults without the proper fix)
        try:
            binascii.a2b_qp(b"", **{1:1})
        except TypeError:
            pass
        else:
            self.fail("binascii.a2b_qp(**{1:1}) didn't raise TypeError")

        self.assertEqual(binascii.a2b_qp(b"= "), b"= ")
        self.assertEqual(binascii.a2b_qp(b"=="), b"=")
        self.assertEqual(binascii.a2b_qp(b"=AX"), b"=AX")
        self.assertRaises(TypeError, binascii.b2a_qp, foo="bar")
        self.assertEqual(binascii.a2b_qp(b"=00\r\n=00"), b"\x00\r\n\x00")
        self.assertEqual(
            binascii.b2a_qp(b"\xff\r\n\xff\n\xff"),
            b"=FF\r\n=FF\r\n=FF")
        self.assertEqual(
            binascii.b2a_qp(b"0"*75+b"\xff\r\n\xff\r\n\xff"),
            b"0"*75+b"=\r\n=FF\r\n=FF\r\n=FF")

        self.assertEqual(binascii.b2a_qp(b'\0\n'), b'=00\n')
        self.assertEqual(binascii.b2a_qp(b'\0\n', quotetabs=True), b'=00\n')
        self.assertEqual(binascii.b2a_qp(b'foo\tbar\t\n'), b'foo\tbar=09\n')
        self.assertEqual(binascii.b2a_qp(b'foo\tbar\t\n', quotetabs=True),
                         b'foo=09bar=09\n')

        self.assertEqual(binascii.b2a_qp(b'.'), b'=2E')
        self.assertEqual(binascii.b2a_qp(b'.\n'), b'=2E\n')
        self.assertEqual(binascii.b2a_qp(b'a.\n'), b'a.\n') 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:34,代碼來源:test_binascii.py

示例8: _decode_content_transfer

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import a2b_qp [as 別名]
def _decode_content_transfer(self, data: bytes) -> bytes:
        encoding = cast(str, self.headers[CONTENT_TRANSFER_ENCODING]).lower()

        if encoding == 'base64':
            return base64.b64decode(data)
        elif encoding == 'quoted-printable':
            return binascii.a2b_qp(data)
        elif encoding in ('binary', '8bit', '7bit'):
            return data
        else:
            raise RuntimeError('unknown content transfer encoding: {}'
                               ''.format(encoding)) 
開發者ID:TouwaStar,項目名稱:Galaxy_Plugin_Bethesda,代碼行數:14,代碼來源:multipart.py

示例9: test_empty_string

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import a2b_qp [as 別名]
def test_empty_string(self):
        # A test for SF bug #1022953.  Make sure SystemError is not raised.
        for n in ['b2a_qp', 'a2b_hex', 'b2a_base64', 'a2b_uu', 'a2b_qp',
                  'b2a_hex', 'unhexlify', 'hexlify', 'crc32', 'b2a_hqx',
                  'a2b_hqx', 'a2b_base64', 'rlecode_hqx', 'b2a_uu',
                  'rledecode_hqx']:
            f = getattr(binascii, n)
            f('')
        binascii.crc_hqx('', 0) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:11,代碼來源:test_binascii.py

示例10: _decode_content_transfer

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import a2b_qp [as 別名]
def _decode_content_transfer(self, data):
        encoding = self.headers[CONTENT_TRANSFER_ENCODING].lower()

        if encoding == 'base64':
            return base64.b64decode(data)
        elif encoding == 'quoted-printable':
            return binascii.a2b_qp(data)
        elif encoding in ('binary', '8bit', '7bit'):
            return data
        else:
            raise RuntimeError('unknown content transfer encoding: {}'
                               ''.format(encoding)) 
開發者ID:skylander86,項目名稱:lambda-text-extractor,代碼行數:14,代碼來源:multipart.py


注:本文中的binascii.a2b_qp方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。