本文整理汇总了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)
示例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]
示例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)
示例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.
示例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
示例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
示例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)