當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。