本文整理汇总了Python中uu.Error方法的典型用法代码示例。如果您正苦于以下问题:Python uu.Error方法的具体用法?Python uu.Error怎么用?Python uu.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uu
的用法示例。
在下文中一共展示了uu.Error方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_truncatedinput
# 需要导入模块: import uu [as 别名]
# 或者: from uu import Error [as 别名]
def test_truncatedinput(self):
inp = cStringIO.StringIO("begin 644 t1\n" + encodedtext)
out = cStringIO.StringIO()
try:
uu.decode(inp, out)
self.fail("No exception raised")
except uu.Error, e:
self.assertEqual(str(e), "Truncated input file")
示例2: test_missingbegin
# 需要导入模块: import uu [as 别名]
# 或者: from uu import Error [as 别名]
def test_missingbegin(self):
inp = cStringIO.StringIO("")
out = cStringIO.StringIO()
try:
uu.decode(inp, out)
self.fail("No exception raised")
except uu.Error, e:
self.assertEqual(str(e), "No valid begin line found in input file")
示例3: test_decodetwice
# 需要导入模块: import uu [as 别名]
# 或者: from uu import Error [as 别名]
def test_decodetwice(self):
# Verify that decode() will refuse to overwrite an existing file
with open(self.tmpin, 'wb') as f:
f.write(encodedtextwrapped % (0o644, self.tmpout))
with open(self.tmpin, 'r') as f:
uu.decode(f)
with open(self.tmpin, 'r') as f:
self.assertRaises(uu.Error, uu.decode, f)
示例4: test_decodetwice
# 需要导入模块: import uu [as 别名]
# 或者: from uu import Error [as 别名]
def test_decodetwice(self):
# Verify that decode() will refuse to overwrite an existing file
f = None
try:
f = cStringIO.StringIO(encodedtextwrapped % (0644, self.tmpout))
f = open(self.tmpin, 'r')
uu.decode(f)
f.close()
f = open(self.tmpin, 'r')
self.assertRaises(uu.Error, uu.decode, f)
f.close()
finally:
self._kill(f)
示例5: get_decoded_payload
# 需要导入模块: import uu [as 别名]
# 或者: from uu import Error [as 别名]
def get_decoded_payload(self):
"""
Similar to get_payload(decode=True), but:
* decoding failures are logged as warnings (instead of being
completely silent);
* if the message is a multipart one, the payload of its first
part is extracted (with `.get_decoded_payload()`, recursively)
and returned instead of `None`.
"""
# copied from Py2.7's email.message.Message.get_payload() and adjusted
payload = self._payload
if self.is_multipart():
first_part = payload[0]
assert isinstance(first_part, self.__class__)
return first_part.get_decoded_payload()
cte = self.get('content-transfer-encoding', '').lower()
if cte == 'quoted-printable':
payload = quopri.decodestring(payload)
elif cte == 'base64':
if payload:
try:
payload = base64.decodestring(payload)
except binascii.Error:
LOGGER.warning('Could not decode the payload using base64'
' => not decoding')
LOGGER.debug('The payload: %r', payload)
elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
sfp = StringIO()
try:
uu.decode(StringIO(payload + '\n'), sfp, quiet=True)
payload = sfp.getvalue()
except uu.Error:
LOGGER.warning('Could not decode the payload using %s'
' => not decoding', cte)
LOGGER.debug('The payload: %r', payload)
elif cte not in ('', '7bit', '8bit', 'binary'):
LOGGER.warning('Unsupported content-transfer-encoding: %s'
' => not decoding', cte)
LOGGER.debug('The payload: %r', payload)
return payload
示例6: test_truncatedinput
# 需要导入模块: import uu [as 别名]
# 或者: from uu import Error [as 别名]
def test_truncatedinput(self):
inp = io.BytesIO(b"begin 644 t1\n" + encodedtext)
out = io.BytesIO()
try:
uu.decode(inp, out)
self.fail("No exception raised")
except uu.Error as e:
self.assertEqual(str(e), "Truncated input file")
示例7: test_missingbegin
# 需要导入模块: import uu [as 别名]
# 或者: from uu import Error [as 别名]
def test_missingbegin(self):
inp = io.BytesIO(b"")
out = io.BytesIO()
try:
uu.decode(inp, out)
self.fail("No exception raised")
except uu.Error as e:
self.assertEqual(str(e), "No valid begin line found in input file")
示例8: test_decodetwice
# 需要导入模块: import uu [as 别名]
# 或者: from uu import Error [as 别名]
def test_decodetwice(self):
# Verify that decode() will refuse to overwrite an existing file
f = None
try:
f = io.BytesIO(encodedtextwrapped(0o644, self.tmpout))
f = open(self.tmpin, 'rb')
uu.decode(f)
f.close()
f = open(self.tmpin, 'rb')
self.assertRaises(uu.Error, uu.decode, f)
f.close()
finally:
self._kill(f)
示例9: test_truncatedinput
# 需要导入模块: import uu [as 别名]
# 或者: from uu import Error [as 别名]
def test_truncatedinput(self):
inp = cStringIO.StringIO("begin 644 t1\n" + encodedtext)
out = cStringIO.StringIO()
try:
uu.decode(inp, out)
self.fail("No exception thrown")
except uu.Error, e:
self.assertEqual(str(e), "Truncated input file")
示例10: test_missingbegin
# 需要导入模块: import uu [as 别名]
# 或者: from uu import Error [as 别名]
def test_missingbegin(self):
inp = cStringIO.StringIO("")
out = cStringIO.StringIO()
try:
uu.decode(inp, out)
self.fail("No exception thrown")
except uu.Error, e:
self.assertEqual(str(e), "No valid begin line found in input file")
示例11: test_decodetwice
# 需要导入模块: import uu [as 别名]
# 或者: from uu import Error [as 别名]
def test_decodetwice(self):
# Verify that decode() will refuse to overwrite an existing file
try:
f = cStringIO.StringIO(encodedtextwrapped % (0644, self.tmpout))
f = open(self.tmpin, 'rb')
uu.decode(f)
f.close()
f = open(self.tmpin, 'rb')
self.assertRaises(uu.Error, uu.decode, f)
f.close()
finally:
self._kill(f)
示例12: check_uu
# 需要导入模块: import uu [as 别名]
# 或者: from uu import Error [as 别名]
def check_uu(msg, data):
assert msg._payload.encode() != data, "Payload has not been transformed"
outfile = BytesIO()
try:
uu.decode(BytesIO(msg._payload.encode()), outfile)
payload = outfile.getvalue()
except uu.Error:
assert False, "Payload could not be decoded"
assert payload == data, "Decoded payload does not match input data"
assert INBOXEN_ENCODING_ERROR_HEADER_NAME not in msg.keys(), "Unexpected error header"