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


Python codecs.getencoder方法代码示例

本文整理汇总了Python中codecs.getencoder方法的典型用法代码示例。如果您正苦于以下问题:Python codecs.getencoder方法的具体用法?Python codecs.getencoder怎么用?Python codecs.getencoder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在codecs的用法示例。


在下文中一共展示了codecs.getencoder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: header_check

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [as 别名]
def header_check(self, content):
        """Special HTML encoding check."""

        encode = None

        # Look for meta charset
        m = RE_HTML_ENCODE.search(content)
        if m:
            enc = m.group(1).decode('ascii')

            try:
                codecs.getencoder(enc)
                encode = enc
            except LookupError:
                pass
        else:
            encode = self._has_xml_encode(content)
        return encode 
开发者ID:facelessuser,项目名称:pyspelling,代码行数:20,代码来源:html.py

示例2: str_encode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [as 别名]
def str_encode(arr, encoding, errors="strict"):
    """
    Encode character string in the Series/Index using indicated encoding.
    Equivalent to :meth:`str.encode`.

    Parameters
    ----------
    encoding : str
    errors : str, optional

    Returns
    -------
    encoded : Series/Index of objects
    """
    if encoding in _cpython_optimized_encoders:
        # CPython optimized implementation
        f = lambda x: x.encode(encoding, errors)
    else:
        encoder = codecs.getencoder(encoding)
        f = lambda x: encoder(x, errors)[0]
    return _na_map(f, arr) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:strings.py

示例3: _filter_encode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [as 别名]
def _filter_encode(self, data, encoding):
		if its.py_v3 and isinstance(data, str):
			data = data.encode('utf-8')
		encoding = encoding.lower()
		encoding = re.sub(r'^(base|rot)-(\d\d)$', r'\1\2', encoding)

		if encoding == 'base16' or encoding == 'hex':
			data = base64.b16encode(data)
		elif encoding == 'base32':
			data = base64.b32encode(data)
		elif encoding == 'base64':
			data = base64.b64encode(data)
		elif encoding == 'rot13':
			data = codecs.getencoder('rot-13')(data.decode('utf-8'))[0]
		else:
			raise ValueError('Unknown encoding type: ' + encoding)
		if its.py_v3 and isinstance(data, bytes):
			data = data.decode('utf-8')
		return data 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:21,代码来源:templates.py

示例4: test_all

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [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

示例5: test_all

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [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",
            "namereplace_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.assertCountEqual(api, codecs.__all__)
        for api in codecs.__all__:
            getattr(codecs, api) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:test_codecs.py

示例6: test_all

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [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.assertCountEqual(api, codecs.__all__)
        for api in codecs.__all__:
            getattr(codecs, api) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:23,代码来源:test_codecs.py

示例7: alpha_encode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [as 别名]
def alpha_encode(data: Any, metadata: 'XMetadata', field_metadata: 'XField') -> bytes:
    """Encode alpha or alphanumeric data.
    metadata has encoding.
    field_metadata is not used.

    Mock metadata objects
    >>> import types
    >>> meta = types.SimpleNamespace(encoding='ebcdic')
    >>> meta.encode = codecs.getencoder(meta.encoding)
    >>> field_meta = types.SimpleNamespace(length=6)

    >>> data = '98765-'
    >>> actual = alpha_encode(data, meta, field_meta)
    >>> repr(actual)
    "b'\\\\xf9\\\\xf8\\\\xf7\\\\xf6\\\\xf5`'"
    >>> actual == bytes([0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0x60])
    True

    """
    bytes, _ = metadata.encode("{:<{size}s}".format(data, size=field_metadata.length))
    return bytes


# Encoder for numeric USAGE DISPLAY, trailing sign. 
开发者ID:PacktPublishing,项目名称:Mastering-Object-Oriented-Python-Second-Edition,代码行数:26,代码来源:ch10_ex5.py

示例8: _bytes_to_hex

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [as 别名]
def _bytes_to_hex(bs):
        return codecs.getencoder('hex')(bs)[0] 
开发者ID:Cobliteam,项目名称:cassandra-migrate,代码行数:4,代码来源:migrator.py

示例9: _verify_encoding

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [as 别名]
def _verify_encoding(self, enc):
        """Verify encoding is okay."""

        enc = PYTHON_ENCODING_NAMES.get(enc, enc)
        try:
            codecs.getencoder(enc)
            encoding = enc
        except LookupError:
            encoding = None
        return encoding 
开发者ID:facelessuser,项目名称:pyspelling,代码行数:12,代码来源:__init__.py

示例10: function

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [as 别名]
def function(self):
        name = self.inferior_frame().name()
        return codecs.getencoder('rot13')(name)[0]

# Create and register filter that uses it 
开发者ID:jefftrull,项目名称:gdb_python_api,代码行数:7,代码来源:combined_filter_decorator.py

示例11: bind_processor

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [as 别名]
def bind_processor(self, dialect):
        if self.convert_unicode or dialect.convert_unicode:
            if dialect.supports_unicode_binds and \
                    self.convert_unicode != 'force':
                if self._warn_on_bytestring:
                    def process(value):
                        if isinstance(value, util.binary_type):
                            util.warn_limited(
                                "Unicode type received non-unicode "
                                "bind param value %r.",
                                (util.ellipses_string(value),))
                        return value
                    return process
                else:
                    return None
            else:
                encoder = codecs.getencoder(dialect.encoding)
                warn_on_bytestring = self._warn_on_bytestring

                def process(value):
                    if isinstance(value, util.text_type):
                        return encoder(value, self.unicode_error)[0]
                    elif warn_on_bytestring and value is not None:
                        util.warn_limited(
                            "Unicode type received non-unicode bind "
                            "param value %r.",
                            (util.ellipses_string(value),))
                    return value
            return process
        else:
            return None 
开发者ID:jpush,项目名称:jbox,代码行数:33,代码来源:sqltypes.py

示例12: quote_value

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [as 别名]
def quote_value(self, value):
        # The backend "mostly works" without this function and there are use
        # cases for compiling Python without the sqlite3 libraries (e.g.
        # security hardening).
        import _sqlite3
        try:
            value = _sqlite3.adapt(value)
        except _sqlite3.ProgrammingError:
            pass
        # Manual emulation of SQLite parameter quoting
        if isinstance(value, type(True)):
            return str(int(value))
        elif isinstance(value, (Decimal, float)):
            return str(value)
        elif isinstance(value, six.integer_types):
            return str(value)
        elif isinstance(value, six.string_types):
            return "'%s'" % six.text_type(value).replace("\'", "\'\'")
        elif value is None:
            return "NULL"
        elif isinstance(value, (bytes, bytearray, six.memoryview)):
            # Bytes are only allowed for BLOB fields, encoded as string
            # literals containing hexadecimal data and preceded by a single "X"
            # character:
            # value = b'\x01\x02' => value_hex = b'0102' => return X'0102'
            value = bytes(value)
            hex_encoder = codecs.getencoder('hex_codec')
            value_hex, _length = hex_encoder(value)
            # Use 'ascii' encoding for b'01' => '01', no need to use force_text here.
            return "X'%s'" % value_hex.decode('ascii')
        else:
            raise ValueError("Cannot quote parameter value %r of type %s" % (value, type(value))) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:34,代码来源:schema.py

示例13: test_encode_length

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [as 别名]
def test_encode_length(self):
        # Issue 3739
        encoder = codecs.getencoder("unicode_internal")
        self.assertEqual(encoder(u"a")[1], 1)
        self.assertEqual(encoder(u"\xe9\u0142")[1], 2)

        encoder = codecs.getencoder("string-escape")
        self.assertEqual(encoder(r'\x00')[1], 4)

# From http://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_codecs.py

示例14: test_getencoder

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [as 别名]
def test_getencoder(self):
        self.assertRaises(TypeError, codecs.getencoder)
        self.assertRaises(LookupError, codecs.getencoder, "__spam__") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_codecs.py

示例15: test_bad_encode_args

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getencoder [as 别名]
def test_bad_encode_args(self):
        for encoding in all_unicode_encodings:
            encoder = codecs.getencoder(encoding)
            self.assertRaises(TypeError, encoder) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_codecs.py


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