本文整理匯總了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)