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