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


Python codecs.latin_1_encode方法代码示例

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


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

示例1: _to_bytes

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_encode [as 别名]
def _to_bytes(msg: Union[str, bytes]) -> bytes:
  """
  Provides the ASCII bytes for the given string. This is purely to provide
  python 3 compatability, normalizing the unicode/ASCII change in the version
  bump. For an explanation of this see...

  http://python3porting.com/problems.html#nicer-solutions

  :param msg: string to be converted

  :returns: ASCII bytes for string
  """

  if isinstance(msg, str):
    return codecs.latin_1_encode(msg, 'replace')[0]  # type: ignore
  else:
    return msg 
开发者ID:torproject,项目名称:stem,代码行数:19,代码来源:str_tools.py

示例2: b

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_encode [as 别名]
def b(s):
        return codecs.latin_1_encode(s)[0] 
开发者ID:gkudos,项目名称:qgis-cartodb,代码行数:4,代码来源:compat.py

示例3: b

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_encode [as 别名]
def b(s):
        # BSON and socket operations deal in binary data. In
        # python 3 that means instances of `bytes`. In python
        # 2.6 and 2.7 you can create an alias for `bytes` using
        # the b prefix (e.g. b'foo'). Python 2.4 and 2.5 don't
        # provide this marker so we provide this compat function.
        # In python 3.x b('foo') results in b'foo'.
        # See http://python3porting.com/problems.html#nicer-solutions
        return codecs.latin_1_encode(s)[0] 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:py3compat.py

示例4: _b

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_encode [as 别名]
def _b(x):
        return codecs.latin_1_encode(x)[0] 
开发者ID:bb4242,项目名称:sdnotify,代码行数:4,代码来源:__init__.py

示例5: encode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_encode [as 别名]
def encode(self, input, final=False):
        return codecs.latin_1_encode(input,self.errors)[0] 
开发者ID:glmcdona,项目名称:meddle,代码行数:4,代码来源:latin_1.py

示例6: test_latin_1_encode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_encode [as 别名]
def test_latin_1_encode(self):
        #sanity
        new_str, size = codecs.latin_1_encode("abc")
        self.assertEqual(new_str, 'abc')
        self.assertEqual(size, 3)
    
        # so many ways to express latin 1...
        for x in ['iso-8859-1', 'iso8859-1', '8859', 'cp819', 'latin', 'latin1', 'L1']:
            self.assertEqual('abc'.encode(x), 'abc')
        

    #TODO: @skip("multiple_execute") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_codecs.py

示例7: b

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_encode [as 别名]
def b(s):
        # BSON and socket operations deal in binary data. In
        # python 3 that means instances of `bytes`. In python
        # 2.6 and 2.7 you can create an alias for `bytes` using
        # the b prefix (e.g. b'foo').
        # See http://python3porting.com/problems.html#nicer-solutions
        return codecs.latin_1_encode(s)[0] 
开发者ID:threathunterX,项目名称:sniffer,代码行数:9,代码来源:py3compat.py

示例8: b

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_encode [as 别名]
def b(x, encoder=None):
    """Converts `x` to a bytes string if not already.
    :param x: The string.
    :param encoder: Optional codec encoder to perform the conversion. The default is
                    `codecs.latin_1_encode`.
    :return: The byte string if conversion was needed.
    """
    if isinstance(x, bytes):
        return x
    else:
        import codecs
        encoder = encoder or codecs.latin_1_encode
        return encoder(x)[0] 
开发者ID:nicfit,项目名称:eyeD3,代码行数:15,代码来源:__init__.py

示例9: b

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_encode [as 别名]
def b(x):
        if isinstance(x, six.binary_type):
            return x
        else:
            return codecs.latin_1_encode(x)[0] 
开发者ID:dispel,项目名称:jak,代码行数:7,代码来源:compat.py

示例10: b

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_encode [as 别名]
def b(x):
        if isinstance(x, bytes) is False:
            return codecs.latin_1_encode(x)[0]
        return x 
开发者ID:SystemRage,项目名称:py-kms,代码行数:6,代码来源:pykms_Structure.py

示例11: makebyte

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_encode [as 别名]
def makebyte(x):
        return codecs.latin_1_encode(x)[0] 
开发者ID:odwyersoftware,项目名称:mega.py,代码行数:4,代码来源:crypto.py

示例12: b

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_encode [as 别名]
def b(s):
        # BSON and socket operations deal in binary data. In
        # python 3 that means instances of `bytes`. In python
        # 2.7 you can create an alias for `bytes` using
        # the b prefix (e.g. b'foo').
        # See http://python3porting.com/problems.html#nicer-solutions
        return codecs.latin_1_encode(s)[0] 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:9,代码来源:py3compat.py

示例13: test_latin_1_encode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_encode [as 别名]
def test_latin_1_encode(self):
        #sanity
        new_str, num_processed = codecs.latin_1_encode("abc")
        self.assertEqual(new_str, b'abc')
        self.assertEqual(num_processed, 3)

        # so many ways to express latin 1...
        for x in ['iso-8859-1', 'iso8859-1', '8859', 'cp819', 'latin', 'latin1', 'L1']:
            self.assertEqual('abc'.encode(x), b'abc')

        self.assertRaises(TypeError, codecs.latin_1_encode, b"abc")
        self.assertRaises(TypeError, codecs.latin_1_encode, None)
        self.assertRaises(TypeError, codecs.latin_1_encode, None, None)
        self.assertRaises(UnicodeEncodeError, codecs.latin_1_encode, "\u0100", None) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:16,代码来源:test_codecs.py


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