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


Python codecs.decode方法代碼示例

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


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

示例1: __call__

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def __call__(self, topic=None):
        if topic is None:
            sys.stdout._write("<span class=help>%s</span>" % repr(self))
            return
        import pydoc

        pydoc.help(topic)
        rv = sys.stdout.reset()
        if isinstance(rv, bytes):
            rv = rv.decode("utf-8", "ignore")
        paragraphs = _paragraph_re.split(rv)
        if len(paragraphs) > 1:
            title = paragraphs[0]
            text = "\n\n".join(paragraphs[1:])
        else:  # pragma: no cover
            title = "Help"
            text = paragraphs[0]
        sys.stdout._write(HELP_HTML % {"title": title, "text": text}) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:20,代碼來源:repr.py

示例2: __init__

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def __init__(
        self,
        stream_factory=None,
        charset="utf-8",
        errors="replace",
        max_form_memory_size=None,
        cls=None,
        buffer_size=64 * 1024,
    ):
        self.charset = charset
        self.errors = errors
        self.max_form_memory_size = max_form_memory_size
        self.stream_factory = (
            default_stream_factory if stream_factory is None else stream_factory
        )
        self.cls = MultiDict if cls is None else cls

        # make sure the buffer size is divisible by four so that we can base64
        # decode chunk by chunk
        assert buffer_size % 4 == 0, "buffer size has to be divisible by 4"
        # also the buffer size has to be at least 1024 bytes long or long headers
        # will freak out the system
        assert buffer_size >= 1024, "buffer size has to be at least 1KB"

        self.buffer_size = buffer_size 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:27,代碼來源:formparser.py

示例3: __call__

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def __call__(self, topic=None):
        if topic is None:
            sys.stdout._write('<span class=help>%s</span>' % repr(self))
            return
        import pydoc
        pydoc.help(topic)
        rv = sys.stdout.reset()
        if isinstance(rv, bytes):
            rv = rv.decode('utf-8', 'ignore')
        paragraphs = _paragraph_re.split(rv)
        if len(paragraphs) > 1:
            title = paragraphs[0]
            text = '\n\n'.join(paragraphs[1:])
        else:  # pragma: no cover
            title = 'Help'
            text = paragraphs[0]
        sys.stdout._write(HELP_HTML % {'title': title, 'text': text}) 
開發者ID:jpush,項目名稱:jbox,代碼行數:19,代碼來源:repr.py

示例4: __init__

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def __init__(self, stream_factory=None, charset='utf-8', errors='replace',
                 max_form_memory_size=None, cls=None, buffer_size=64 * 1024):
        self.stream_factory = stream_factory
        self.charset = charset
        self.errors = errors
        self.max_form_memory_size = max_form_memory_size
        if stream_factory is None:
            stream_factory = default_stream_factory
        if cls is None:
            cls = MultiDict
        self.cls = cls

        # make sure the buffer size is divisible by four so that we can base64
        # decode chunk by chunk
        assert buffer_size % 4 == 0, 'buffer size has to be divisible by 4'
        # also the buffer size has to be at least 1024 bytes long or long headers
        # will freak out the system
        assert buffer_size >= 1024, 'buffer size has to be at least 1KB'

        self.buffer_size = buffer_size 
開發者ID:jpush,項目名稱:jbox,代碼行數:22,代碼來源:formparser.py

示例5: testDecrypt

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def testDecrypt(self):

        g = rdflib.Graph()
        g.parse(data=keybagturtle, format="turtle")
        kb = keybag.PasswordWrappedKeyBag.load(g)

        key = "password"
        kek = digest.pbkdf2_hmac("sha256", key, kb.salt, kb.iterations, kb.keySizeBytes);
        vek = aes_unwrap_key(kek, kb.wrappedKey)

        key1 = vek[0:16]
        key2 = vek[16:]
        tweak = codecs.decode('00', 'hex')

        cipher = python_AES.new((key1, key2), python_AES.MODE_XTS)
        text = cipher.decrypt(target_ciphertext, tweak)

        self.assertEqual(src[0:len(src)], text[0:len(src)]) 
開發者ID:aff4,項目名稱:pyaff4,代碼行數:20,代碼來源:test_crypto.py

示例6: seal_aes_ctr_legacy

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def seal_aes_ctr_legacy(key_service, secret, digest_method=DEFAULT_DIGEST):
    """
    Encrypts `secret` using the key service.
    You can decrypt with the companion method `open_aes_ctr_legacy`.
    """
    # generate a a 64 byte key.
    # Half will be for data encryption, the other half for HMAC
    key, encoded_key = key_service.generate_key_data(64)
    ciphertext, hmac = _seal_aes_ctr(
        secret, key, LEGACY_NONCE, digest_method,
    )
    return {
        'key': b64encode(encoded_key).decode('utf-8'),
        'contents': b64encode(ciphertext).decode('utf-8'),
        'hmac': codecs.encode(hmac, "hex_codec"),
        'digest': digest_method,
    } 
開發者ID:fugue,項目名稱:credstash,代碼行數:19,代碼來源:credstash.py

示例7: SendCommandtoSerial

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def SendCommandtoSerial(self, TXs):
			crc = 0
			#start = codecs.decode('1002', 'hex_codec')
			start = (0x10, 0x02)
			ende = codecs.decode('1003', 'hex_codec')
			ende = (0x10, 0x03)
			i = 0
			while i < TXs[1] + 2:
				crc += TXs[i]
				i += 1
			crc = (256 - crc) & 255
			TXs[TXs[1] + 2] = crc
			i = 0
			self.ser.write(chr(start[0]))
			self.ser.write(chr(start[1]))
			while i < TXs[1] + 3:
				self.ser.write(chr(TXs[i]))
				#print format(TXs[i], '02x')
				if TXs[i] == 0x10:
					self.ser.write(chr(TXs[i]))
				i += 1
			self.ser.write(chr(ende[0]))
			self.ser.write(chr(ende[1])) 
開發者ID:sailoog,項目名稱:openplotter,代碼行數:25,代碼來源:CAN-USB-stick.py

示例8: __init__

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def __init__(self, stream_factory=None, charset='utf-8', errors='replace',
                 max_form_memory_size=None, cls=None, buffer_size=64 * 1024):
        self.charset = charset
        self.errors = errors
        self.max_form_memory_size = max_form_memory_size
        self.stream_factory = default_stream_factory if stream_factory is None else stream_factory
        self.cls = MultiDict if cls is None else cls

        # make sure the buffer size is divisible by four so that we can base64
        # decode chunk by chunk
        assert buffer_size % 4 == 0, 'buffer size has to be divisible by 4'
        # also the buffer size has to be at least 1024 bytes long or long headers
        # will freak out the system
        assert buffer_size >= 1024, 'buffer size has to be at least 1KB'

        self.buffer_size = buffer_size 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:18,代碼來源:formparser.py

示例9: test_errors

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def test_errors(self):
        tests = [
            (b'\xff', u'\ufffd'),
            (b'A\x00Z', u'A\ufffd'),
            (b'A\x00B\x00C\x00D\x00Z', u'ABCD\ufffd'),
            (b'\x00\xd8', u'\ufffd'),
            (b'\x00\xd8A', u'\ufffd'),
            (b'\x00\xd8A\x00', u'\ufffdA'),
            (b'\x00\xdcA\x00', u'\ufffdA'),
        ]
        for raw, expected in tests:
            try:
                with self.assertRaises(UnicodeDecodeError):
                    codecs.utf_16_le_decode(raw, 'strict', True)
                self.assertEqual(raw.decode('utf-16le', 'replace'), expected)
            except:
                print 'raw=%r' % raw
                raise 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_codecs.py

示例10: test_ascii

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def test_ascii(self):
        # Set D (directly encoded characters)
        set_d = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
                 'abcdefghijklmnopqrstuvwxyz'
                 '0123456789'
                 '\'(),-./:?')
        self.assertEqual(set_d.encode(self.encoding), set_d)
        self.assertEqual(set_d.decode(self.encoding), set_d)
        # Set O (optional direct characters)
        set_o = ' !"#$%&*;<=>@[]^_`{|}'
        self.assertEqual(set_o.encode(self.encoding), set_o)
        self.assertEqual(set_o.decode(self.encoding), set_o)
        # +
        self.assertEqual(u'a+b'.encode(self.encoding), 'a+-b')
        self.assertEqual('a+-b'.decode(self.encoding), u'a+b')
        # White spaces
        ws = ' \t\n\r'
        self.assertEqual(ws.encode(self.encoding), ws)
        self.assertEqual(ws.decode(self.encoding), ws)
        # Other ASCII characters
        other_ascii = ''.join(sorted(set(chr(i) for i in range(0x80)) -
                                     set(set_d + set_o + '+' + ws)))
        self.assertEqual(other_ascii.encode(self.encoding),
                         '+AAAAAQACAAMABAAFAAYABwAIAAsADAAOAA8AEAARABIAEwAU'
                         'ABUAFgAXABgAGQAaABsAHAAdAB4AHwBcAH4Afw-') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:test_codecs.py

示例11: test_lone_surrogates

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def test_lone_surrogates(self):
        tests = [
            ('a+2AE-b', u'a\ud801b'),
            ('a+2AE\xe1b', u'a\ufffdb'),
            ('a+2AE', u'a\ufffd'),
            ('a+2AEA-b', u'a\ufffdb'),
            ('a+2AH-b', u'a\ufffdb'),
            ('a+IKzYAQ-b', u'a\u20ac\ud801b'),
            ('a+IKzYAQ\xe1b', u'a\u20ac\ufffdb'),
            ('a+IKzYAQA-b', u'a\u20ac\ufffdb'),
            ('a+IKzYAd-b', u'a\u20ac\ufffdb'),
            ('a+IKwgrNgB-b', u'a\u20ac\u20ac\ud801b'),
            ('a+IKwgrNgB\xe1b', u'a\u20ac\u20ac\ufffdb'),
            ('a+IKwgrNgB', u'a\u20ac\u20ac\ufffd'),
            ('a+IKwgrNgBA-b', u'a\u20ac\u20ac\ufffdb'),
        ]
        for raw, expected in tests:
            try:
                self.assertEqual(raw.decode('utf-7', 'replace'), expected)
            except:
                print 'raw=%r' % raw
                raise 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:24,代碼來源:test_codecs.py

示例12: test_bug1251300

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def test_bug1251300(self):
        # Decoding with unicode_internal used to not correctly handle "code
        # points" above 0x10ffff on UCS-4 builds.
        if sys.maxunicode > 0xffff:
            ok = [
                ("\x00\x10\xff\xff", u"\U0010ffff"),
                ("\x00\x00\x01\x01", u"\U00000101"),
                ("", u""),
            ]
            not_ok = [
                "\x7f\xff\xff\xff",
                "\x80\x00\x00\x00",
                "\x81\x00\x00\x00",
                "\x00",
                "\x00\x00\x00\x00\x00",
            ]
            for internal, uni in ok:
                if sys.byteorder == "little":
                    internal = "".join(reversed(internal))
                self.assertEqual(uni, internal.decode("unicode_internal"))
            for internal in not_ok:
                if sys.byteorder == "little":
                    internal = "".join(reversed(internal))
                self.assertRaises(UnicodeDecodeError, internal.decode,
                    "unicode_internal") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:test_codecs.py

示例13: test_all

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def test_all(self):
        api = (
            "encode", "decode",
            "register", "CodecInfo", "Codec", "IncrementalEncoder",
            "IncrementalDecoder", "StreamReader", "StreamWriter", "lookup",
            "getencoder", "getdecoder", "getincrementalencoder",
            "getincrementaldecoder", "getreader", "getwriter",
            "register_error", "lookup_error",
            "strict_errors", "replace_errors", "ignore_errors",
            "xmlcharrefreplace_errors", "backslashreplace_errors",
            "open", "EncodedFile",
            "iterencode", "iterdecode",
            "BOM", "BOM_BE", "BOM_LE",
            "BOM_UTF8", "BOM_UTF16", "BOM_UTF16_BE", "BOM_UTF16_LE",
            "BOM_UTF32", "BOM_UTF32_BE", "BOM_UTF32_LE",
            "BOM32_BE", "BOM32_LE", "BOM64_BE", "BOM64_LE",  # Undocumented
            "StreamReaderWriter", "StreamRecoder",
        )
        self.assertEqual(sorted(api), sorted(codecs.__all__))
        for api in codecs.__all__:
            getattr(codecs, api) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:23,代碼來源:test_codecs.py

示例14: as_bytes

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def as_bytes(self, errors='strict', codec=AsciiTrytesCodec.name):
    # type: (Text, Text) -> binary_type
    """
    Converts the TryteString into a byte string.

    :param errors:
      How to handle trytes that can't be converted:
        - 'strict':   raise an exception (recommended).
        - 'replace':  replace with '?'.
        - 'ignore':   omit the tryte from the result.

    :param codec:
      Which codec to use:

      - 'binary': Converts each sequence of 5 trits into a byte with
        the same value (this is usually what you want).
      - 'ascii': Uses the legacy ASCII codec.

    :raise:
      - :py:class:`iota.codecs.TrytesDecodeError` if the trytes cannot
        be decoded into bytes.
    """
    # In Python 2, :py:func:`decode` does not accept keyword arguments.
    return decode(self._trytes, codec, errors) 
開發者ID:llSourcell,項目名稱:IOTA_demo,代碼行數:26,代碼來源:types.py

示例15: _git_command

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import decode [as 別名]
def _git_command(params, cwd):
    """
    Executes a git command, returning the output

    :param params:
        A list of the parameters to pass to git

    :param cwd:
        The working directory to execute git in

    :return:
        A 2-element tuple of (stdout, stderr)
    """

    proc = subprocess.Popen(
        ['git'] + params,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        cwd=cwd
    )
    stdout, stderr = proc.communicate()
    code = proc.wait()
    if code != 0:
        e = OSError('git exit code was non-zero')
        e.stdout = stdout
        raise e
    return stdout.decode('utf-8').strip() 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:29,代碼來源:coverage.py


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