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


Python codecs.escape_encode方法代碼示例

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


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

示例1: test_escape_encode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import escape_encode [as 別名]
def test_escape_encode(self):
        tests = [
            (b'', (b'', 0)),
            (b'foobar', (b'foobar', 6)),
            (b'spam\0eggs', (b'spam\\x00eggs', 9)),
            (b'a\'b', (b"a\\'b", 3)),
            (b'b\\c', (b'b\\\\c', 3)),
            (b'c\nd', (b'c\\nd', 3)),
            (b'd\re', (b'd\\re', 3)),
            (b'f\x7fg', (b'f\\x7fg', 3)),
        ]
        for data, output in tests:
            with self.subTest(data=data):
                self.assertEqual(codecs.escape_encode(data), output)
        self.assertRaises(TypeError, codecs.escape_encode, 'spam')
        self.assertRaises(TypeError, codecs.escape_encode, bytearray(b'spam')) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:18,代碼來源:test_codecs.py

示例2: asciiChar

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import escape_encode [as 別名]
def asciiChar(HTTPRequestHolderObjs):
    result = []
    for HTTPRequestHolderObj in HTTPRequestHolderObjs:
        initHTTPReq = HTTPRequestHolderObj.rawHTTPRequest
        initAdditionalInfo = HTTPRequestHolderObj.additionalInfo
        for c in range(0, 256):
            asciiChar = chr(c)
            additionalInfo = 'ASCII [Code: {} - Char: {}]'.format(c, codecs.escape_encode(asciiChar))
            if initAdditionalInfo != '':
                additionalInfo = initAdditionalInfo + ' - ' + additionalInfo
            HTTPRequestHolderObjTemp = HTTPRequestHolder.HTTPRequestHolder(Template(initHTTPReq).safe_substitute(asciiChar=asciiChar),additionalInfo)
            result.append(HTTPRequestHolderObjTemp)
    return result 
開發者ID:irsdl,項目名稱:httpninja,代碼行數:15,代碼來源:testcase_mutation.py

示例3: asciiHex

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import escape_encode [as 別名]
def asciiHex(HTTPRequestHolderObjs):
    result = []
    for HTTPRequestHolderObj in HTTPRequestHolderObjs:
        initHTTPReq = HTTPRequestHolderObj.rawHTTPRequest
        initAdditionalInfo = HTTPRequestHolderObj.additionalInfo
        for c in range(0, 256):
            asciiChar = chr(c)
            asciiHex = "{:02x}".format(c)
            additionalInfo = 'ASCII [Code: {} - Char: {} - Hex: {}]'.format(c, codecs.escape_encode(asciiChar), asciiHex)
            if initAdditionalInfo != '':
                additionalInfo = initAdditionalInfo + ' - ' + additionalInfo
            HTTPRequestHolderObjTemp = HTTPRequestHolder.HTTPRequestHolder(Template(initHTTPReq).safe_substitute(asciiHex=asciiHex),additionalInfo)
            result.append(HTTPRequestHolderObjTemp)
    return result 
開發者ID:irsdl,項目名稱:httpninja,代碼行數:16,代碼來源:testcase_mutation.py

示例4: unicodeChar

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import escape_encode [as 別名]
def unicodeChar(HTTPRequestHolderObjs):
    result = []
    for HTTPRequestHolderObj in HTTPRequestHolderObjs:
        initHTTPReq = HTTPRequestHolderObj.rawHTTPRequest
        initAdditionalInfo = HTTPRequestHolderObj.additionalInfo
        for u in range(0, 65535):
            unicodeChar = int2bytes(u)
            additionalInfo = 'UNICODE [Code: {} - Char: {}]'.format(u, codecs.escape_encode(unicodeChar))
            if initAdditionalInfo != '':
                additionalInfo = initAdditionalInfo + ' - ' + additionalInfo
            HTTPRequestHolderObjTemp = HTTPRequestHolder.HTTPRequestHolder(Template(initHTTPReq).safe_substitute(asciiChar=asciiChar),additionalInfo)
            result.append(HTTPRequestHolderObjTemp)
    return result 
開發者ID:irsdl,項目名稱:httpninja,代碼行數:15,代碼來源:testcase_mutation.py

示例5: encode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import escape_encode [as 別名]
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0] 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:4,代碼來源:string_escape.py

示例6: test_escape_encode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import escape_encode [as 別名]
def test_escape_encode(self):
        #sanity checks
        value, length = codecs.escape_encode("abba")
        self.assertEqual(value, "abba")
        self.assertEqual(length, 4)

        value, length = codecs.escape_encode("ab\a\b\t\n\r\f\vba")
        self.assertEqual(value, 'ab\\x07\\x08\\t\\n\\r\\x0c\\x0bba')
        if is_cli: #http://ironpython.codeplex.com/workitem/27899
            self.assertEqual(length, 26)
        else:
            self.assertEqual(length, 11)

        value, length = codecs.escape_encode("\\a")
        self.assertEqual(value, "\\\\a")
        if is_cli: #http://ironpython.codeplex.com/workitem/27899
            self.assertEqual(length, 3)
        else:
            self.assertEqual(length, 2)
        
        l = []
        for i in xrange(256):
            l.append(chr(i))
            
        value, length = codecs.escape_encode(''.join(l))
        self.assertEqual(value, '\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r\\x0e\\x0f\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f !"#$%&\\\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\x7f\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x8b\\x8c\\x8d\\x8e\\x8f\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99\\x9a\\x9b\\x9c\\x9d\\x9e\\x9f\\xa0\\xa1\\xa2\\xa3\\xa4\\xa5\\xa6\\xa7\\xa8\\xa9\\xaa\\xab\\xac\\xad\\xae\\xaf\\xb0\\xb1\\xb2\\xb3\\xb4\\xb5\\xb6\\xb7\\xb8\\xb9\\xba\\xbb\\xbc\\xbd\\xbe\\xbf\\xc0\\xc1\\xc2\\xc3\\xc4\\xc5\\xc6\\xc7\\xc8\\xc9\\xca\\xcb\\xcc\\xcd\\xce\\xcf\\xd0\\xd1\\xd2\\xd3\\xd4\\xd5\\xd6\\xd7\\xd8\\xd9\\xda\\xdb\\xdc\\xdd\\xde\\xdf\\xe0\\xe1\\xe2\\xe3\\xe4\\xe5\\xe6\\xe7\\xe8\\xe9\\xea\\xeb\\xec\\xed\\xee\\xef\\xf0\\xf1\\xf2\\xf3\\xf4\\xf5\\xf6\\xf7\\xf8\\xf9\\xfa\\xfb\\xfc\\xfd\\xfe\\xff')
        
        if is_cli: #http://ironpython.codeplex.com/workitem/27899
            self.assertEqual(length, 735)
        else:
            self.assertEqual(length, 256) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:33,代碼來源:test_codecs.py

示例7: test_encode_length

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import escape_encode [as 別名]
def test_encode_length(self):
        with support.check_warnings(('unicode_internal codec has been '
                                     'deprecated', DeprecationWarning)):
            # Issue 3739
            encoder = codecs.getencoder("unicode_internal")
            self.assertEqual(encoder("a")[1], 1)
            self.assertEqual(encoder("\xe9\u0142")[1], 2)

            self.assertEqual(codecs.escape_encode(br'\x00')[1], 4)

# From http://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:13,代碼來源:test_codecs.py

示例8: test_escape_encode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import escape_encode [as 別名]
def test_escape_encode(self):
        #sanity checks
        value, length = codecs.escape_encode(b"abba")
        self.assertEqual(value, b"abba")
        self.assertEqual(length, 4)

        value, length = codecs.escape_encode(b"ab\a\b\t\n\r\f\vba")
        self.assertEqual(value, b'ab\\x07\\x08\\t\\n\\r\\x0c\\x0bba')
        self.assertEqual(length, 11)

        value, length = codecs.escape_encode(b"\\a")
        self.assertEqual(value, b"\\\\a")
        self.assertEqual(length, 2)

        value, length = codecs.escape_encode(bytes(range(256)))
        self.assertEqual(value, b'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r\\x0e\\x0f\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f !"#$%&\\\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\x7f\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x8b\\x8c\\x8d\\x8e\\x8f\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99\\x9a\\x9b\\x9c\\x9d\\x9e\\x9f\\xa0\\xa1\\xa2\\xa3\\xa4\\xa5\\xa6\\xa7\\xa8\\xa9\\xaa\\xab\\xac\\xad\\xae\\xaf\\xb0\\xb1\\xb2\\xb3\\xb4\\xb5\\xb6\\xb7\\xb8\\xb9\\xba\\xbb\\xbc\\xbd\\xbe\\xbf\\xc0\\xc1\\xc2\\xc3\\xc4\\xc5\\xc6\\xc7\\xc8\\xc9\\xca\\xcb\\xcc\\xcd\\xce\\xcf\\xd0\\xd1\\xd2\\xd3\\xd4\\xd5\\xd6\\xd7\\xd8\\xd9\\xda\\xdb\\xdc\\xdd\\xde\\xdf\\xe0\\xe1\\xe2\\xe3\\xe4\\xe5\\xe6\\xe7\\xe8\\xe9\\xea\\xeb\\xec\\xed\\xee\\xef\\xf0\\xf1\\xf2\\xf3\\xf4\\xf5\\xf6\\xf7\\xf8\\xf9\\xfa\\xfb\\xfc\\xfd\\xfe\\xff')
        self.assertEqual(length, 256)

        self.assertRaises(TypeError, codecs.escape_encode, "abc")
        self.assertRaises(TypeError, codecs.escape_encode, None)
        self.assertRaises(TypeError, codecs.escape_encode, None, None)
        self.assertEquals(codecs.escape_encode(b"\\", None), (b"\\\\", 1))
        self.assertEquals(codecs.escape_encode(b"\\", 'strict'), (b"\\\\", 1))

        self.assertRaises(TypeError, codecs.escape_encode, bytearray(b"abc"))
        self.assertRaises(TypeError, codecs.escape_encode, memoryview(b"abc"))
        self.assertRaises(TypeError, codecs.escape_encode, array.array('I', (1633771873,))) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:29,代碼來源:test_codecs.py

示例9: build

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import escape_encode [as 別名]
def build(self, pre=None, shortest=False):
        """Build the ``Quote`` instance

        :param list pre: The prerequisites list
        :param bool shortest: Whether or not the shortest reference-chain (most minimal) version of the field should be generated.
        """
        res = super(Q, self).build(pre, shortest=shortest)

        if self.escape:
            return self._repr_escape(res)
        elif self.html_js_escape:
            res, _ = codecs.escape_encode(res)
            return (b"'" + res.replace(b"<", b"\\x3c").replace(b">", b"\\x3e") + b"'")
        else:
            return b"".join([self.quote, res, self.quote]) 
開發者ID:d0c-s4vage,項目名稱:gramfuzz,代碼行數:17,代碼來源:fields.py


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