本文整理汇总了Python中uu.encode方法的典型用法代码示例。如果您正苦于以下问题:Python uu.encode方法的具体用法?Python uu.encode怎么用?Python uu.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uu
的用法示例。
在下文中一共展示了uu.encode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: encode
# 需要导入模块: import uu [as 别名]
# 或者: from uu import encode [as 别名]
def encode(input, output, encoding):
"""Encode common content-transfer-encodings (base64, quopri, uuencode)."""
if encoding == 'base64':
import base64
return base64.encode(input, output)
if encoding == 'quoted-printable':
import quopri
return quopri.encode(input, output, 0)
if encoding in ('uuencode', 'x-uuencode', 'uue', 'x-uue'):
import uu
return uu.encode(input, output)
if encoding in ('7bit', '8bit'):
return output.write(input.read())
if encoding in encodetab:
pipethrough(input, encodetab[encoding], output)
else:
raise ValueError, \
'unknown Content-Transfer-Encoding: %s' % encoding
# The following is no longer used for standard encodings
# XXX This requires that uudecode and mmencode are in $PATH
示例2: test_encode
# 需要导入模块: import uu [as 别名]
# 或者: from uu import encode [as 别名]
def test_encode(self):
with open(self.tmpin, 'wb') as fin:
fin.write(plaintext)
with open(self.tmpin, 'rb') as fin:
with open(self.tmpout, 'w') as fout:
uu.encode(fin, fout, self.tmpin, mode=0o644)
with open(self.tmpout, 'r') as fout:
s = fout.read()
self.assertEqual(s, encodedtextwrapped % (0o644, self.tmpin))
# in_file and out_file as filenames
uu.encode(self.tmpin, self.tmpout, self.tmpin, mode=0o644)
with open(self.tmpout, 'r') as fout:
s = fout.read()
self.assertEqual(s, encodedtextwrapped % (0o644, self.tmpin))
示例3: test_newlines_escaped
# 需要导入模块: import uu [as 别名]
# 或者: from uu import encode [as 别名]
def test_newlines_escaped(self):
# Test newlines are escaped with uu.encode
inp = io.BytesIO(plaintext)
out = io.BytesIO()
filename = "test.txt\n\roverflow.txt"
safefilename = b"test.txt\\n\\roverflow.txt"
uu.encode(inp, out, filename)
self.assertIn(safefilename, out.getvalue())
示例4: test_encode
# 需要导入模块: import uu [as 别名]
# 或者: from uu import encode [as 别名]
def test_encode(self):
inp = cStringIO.StringIO(plaintext)
out = cStringIO.StringIO()
uu.encode(inp, out, "t1")
self.assertEqual(out.getvalue(), encodedtextwrapped % (0666, "t1"))
inp = cStringIO.StringIO(plaintext)
out = cStringIO.StringIO()
uu.encode(inp, out, "t1", 0644)
self.assertEqual(out.getvalue(), encodedtextwrapped % (0644, "t1"))
示例5: test_encode
# 需要导入模块: import uu [as 别名]
# 或者: from uu import encode [as 别名]
def test_encode(self):
inp = io.BytesIO(plaintext)
out = io.BytesIO()
uu.encode(inp, out, "t1")
self.assertEqual(out.getvalue(), encodedtextwrapped(0o666, "t1"))
inp = io.BytesIO(plaintext)
out = io.BytesIO()
uu.encode(inp, out, "t1", 0o644)
self.assertEqual(out.getvalue(), encodedtextwrapped(0o644, "t1"))