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


Python codecs.ascii_encode方法代碼示例

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


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

示例1: test_escapes_non_ascii

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import ascii_encode [as 別名]
def test_escapes_non_ascii(self):
    """
    Check that our manual parser escapes all non-ascii characters. If this
    fails then that means someone probably added a new type of non-ascii
    character. Easy to fix: please simply add an escape for it in
    stem/manual.py's _get_categories().
    """

    self.requires_downloaded_manual()

    def check(content):
      try:
        codecs.ascii_encode(content, 'strict')
      except UnicodeEncodeError as exc:
        self.fail("Unable to read '%s' as ascii: %s" % (content, exc))

    categories = stem.manual._get_categories(self.man_content)

    for category, lines in categories.items():
      check(category)

      for line in lines:
        check(line) 
開發者ID:torproject,項目名稱:stem,代碼行數:25,代碼來源:manual.py

示例2: encode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import ascii_encode [as 別名]
def encode(self, input, final=False):
        return codecs.ascii_encode(input, self.errors)[0] 
開發者ID:alsmith,項目名稱:multicast-relay,代碼行數:4,代碼來源:ascii.py

示例3: test_ascii_encode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import ascii_encode [as 別名]
def test_ascii_encode(self):
        #sanity
        new_str, size = codecs.ascii_encode("abc")
        self.assertEqual(new_str, 'abc')
        self.assertEqual(size, 3) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_codecs.py

示例4: setTextFrame

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import ascii_encode [as 別名]
def setTextFrame(self, fid: bytes, txt: str):
        fid = b(fid, ascii_encode)
        if not fid.startswith(b"T") or fid.startswith(b"TX"):
            raise ValueError("Invalid frame-id for text frame")

        if not txt and self.frame_set[fid]:
            del self.frame_set[fid]
        elif txt:
            self.frame_set.setTextFrame(fid, txt)

    # FIXME: is returning data not a Frame. 
開發者ID:nicfit,項目名稱:eyeD3,代碼行數:13,代碼來源:tag.py

示例5: getTextFrame

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import ascii_encode [as 別名]
def getTextFrame(self, fid: bytes):
        fid = b(fid, ascii_encode)
        if not fid.startswith(b"T") or fid.startswith(b"TX"):
            raise ValueError("Invalid frame-id for text frame")
        f = self.frame_set[fid]
        return f[0].text if f else None 
開發者ID:nicfit,項目名稱:eyeD3,代碼行數:8,代碼來源:tag.py

示例6: frameiter

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import ascii_encode [as 別名]
def frameiter(self, fids=None):
        """A iterator for tag frames. If ``fids`` is passed it must be a list
        of frame IDs to filter and return."""
        fids = fids or []
        fids = [(b(f, ascii_encode) if isinstance(f, str) else f) for f in fids]
        for f in self.frame_set.getAllFrames():
            if not fids or f.id in fids:
                yield f 
開發者ID:nicfit,項目名稱:eyeD3,代碼行數:10,代碼來源:tag.py

示例7: test_ascii_encode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import ascii_encode [as 別名]
def test_ascii_encode(self):
        #sanity
        self.assertEqual(codecs.ascii_encode("abc"), (b"abc", 3))
        self.assertEqual(codecs.ascii_encode("abc", None), (b"abc", 3))
        self.assertRaises(TypeError, codecs.ascii_encode, b"abc")
        self.assertRaises(TypeError, codecs.ascii_encode, None)
        self.assertRaises(TypeError, codecs.ascii_encode, b"")
        self.assertRaises(UnicodeEncodeError, codecs.ascii_encode, "\u0100", None) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:10,代碼來源:test_codecs.py


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