当前位置: 首页>>代码示例>>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;未经允许,请勿转载。