本文整理汇总了Python中quopri.decode函数的典型用法代码示例。如果您正苦于以下问题:Python decode函数的具体用法?Python decode怎么用?Python decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了decode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_decode
def test_decode(self):
for p, e in self.STRINGS:
infp = cStringIO.StringIO(e)
outfp = cStringIO.StringIO()
if not test_support.due_to_ironpython_bug("http://tkbgitvstfat01:8080/WorkItemTracking/WorkItem.aspx?artifactMoniker=317834"):
quopri.decode(infp, outfp) #binascii.a2b_qp() not implemented which is needed in function decode()
self.assertTrue(outfp.getvalue() == p)
示例2: decode_part
def decode_part (self, m, as_utf8 = 0):
ct = m.getmaintype("text")
if ct != "text": as_utf8 = 0
body = m.get_payload()
if not isinstance(body, StringType):
body = str(body)
encoding = string.lower(m.get('content-transfer-encoding', '7bit'))
if encoding == "quoted-printable":
from quopri import decode
## how annoying
inb = StringIO(body)
outb = StringIO()
decode(inb, outb)
body = outb.getvalue()
elif encoding == "base64":
from base64 import decodestring
try:
body = decodestring(body)
except:
pass
if ct == "text":
# don't allow embedded nulls in text parts
body = string.replace(body, '\0', '')
if as_utf8: return to_utf8(body, self.charset(m))
return body
示例3: mime_unpack
def mime_unpack(self, input, stack):
entity = mimetools.Message(input)
stack = (entity,) + stack
if entity.getmaintype() == 'multipart':
self.parts.append(MessagePart(None, None, stack))
boundary = entity.getparam('boundary')
if boundary:
input.push(boundary)
while input.next():
self.mime_unpack(input, stack)
input.pop()
elif entity.gettype() == 'message/rfc822':
self.parts.append(MessagePart(None, None, stack))
self.mime_unpack(input, stack)
else:
name = get_filename(entity)
work = tempfile.mktemp()
cte = entity.getencoding()
if cte == 'quoted-printable':
output = cStringIO.StringIO()
quopri.decode(input, output)
elif cte == 'base64':
output = cStringIO.StringIO()
base64_decode(input, output)
else:
output = None
if output:
output.reset()
if entity.gettype() == "application/x-gzip" or \
(name and name.endswith(".gz")):
work2 = tempfile.mktemp()
tmp2 = open(work2+".gz", "w")
tmp2.write(output.read())
tmp2.close()
inst = popen2.Popen4("gunzip %s.gz" % work2)
data = inst.fromchild.read()
if inst.wait() != 0:
self.write_fatal(_("Uncompressing your submission with gzip has failed. gzip said:\n%s\n") % data)
try:
os.unlink(work2+".gz")
except OSError:
pass
return
output=open(work2)
os.unlink(work2)
if name and name.endswith(".gz"):
name=name[:-3]
tmp = open(work,"w")
tmp.write(output.read())
tmp.close()
del output
self.simple_unpack(open(work), name, stack)
os.remove(work)
else:
self.simple_unpack(input, name, stack)
示例4: _qdecode
def _qdecode(s):
import quopri as _quopri
if not s:
return s
infp = StringIO(s)
outfp = StringIO()
_quopri.decode(infp, outfp)
value = outfp.getvalue()
if not s.endswith('\n') and value.endswith('\n'):
return value[:-1]
return value
示例5: decode
def decode(encoding, s):
if encoding == '7bit' or encoding == '8bit' or encoding == 'binary':
return s
elif encoding == 'quoted-printable':
import quopri
ifp = StringIO.StringIO(s)
ofp = StringIO.StringIO()
quopri.decode(ifp, ofp)
return ofp.getvalue()
elif encoding == 'base64':
import base64
return base64.decodestring(s)
else:
raise Error("Unknown encoding %s" % repr(encoding))
示例6: quopri_decode
def quopri_decode(input, errors='strict'):
"""Decode the input, returning a tuple (output object, length consumed).
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for this codec.
"""
assert errors == 'strict'
f = StringIO(str(input))
g = StringIO()
quopri.decode(f, g)
output = g.getvalue()
return (output, len(input))
示例7: __init__
def __init__(self, reader, a):
sqmail.gui.viewer.Viewer.__init__(self, reader, a, "textmessage")
font = gtk.load_font(sqmail.preferences.get_textmessagefont())
# Ensure the text box is 80 columns wide.
width = gtk.gdk_char_width(font, "m")*82
# The text box is guaranteed to be empty.
self.viewer_widget.messagetext.freeze()
self.viewer_widget.messagetext.set_usize(width, 0)
if (self.attachment[1] == "text/quoted-printable"):
infp = cStringIO.StringIO(self.attachment[2])
outfp = cStringIO.StringIO()
quopri.decode(infp, outfp)
body = outfp.getvalue()
else:
body = self.attachment[2]
self.viewer_widget.messagetext.insert(font, None, None, body)
self.viewer_widget.messagetext.thaw()
示例8: __init__
def __init__(self, reader, a):
sqmail.gui.viewer.Viewer.__init__(self, reader, a, "htmlmessage")
# Glade doesn't do the GtkXmHTML widget yet. So we need to add
# it manually.
self.htmlwidget = gnome.xmhtml.GtkXmHTML()
self.viewer_widget.frame.add(self.htmlwidget)
self.htmlwidget.show()
self.htmlwidget.freeze()
if self.attachment[1] == "text/quoted-printable":
infp = cStringIO.StringIO(self.attachment[2])
outfp = cStringIO.StringIO()
quopri.decode(infp, outfp)
body = outfp.getvalue()
else:
body = self.attachment[2]
self.htmlwidget.set_allow_images(1)
self.htmlwidget.source(body)
self.htmlwidget.thaw()
示例9: _decode
def _decode(self, headers, fileobj):
encoding = headers[-1].get_all("content-transfer-encoding", ["7bit"])[0]
encoding = encoding.lower()
if encoding == "base64":
try:
data = base64.b64decode(fileobj.read())
except TypeError as error:
self.log.error("Base64 decoding failed ({0})".format(error))
idiokit.stop(False)
return StringIO(data)
if encoding == "quoted-printable":
output = StringIO()
quopri.decode(fileobj, output)
output.seek(0)
return output
return fileobj
示例10: parseFrame
def parseFrame(self, frame):
# Parse a passed-in frame for name-value pairs.
# Same as from_rfc_822_format in cgi-bin/PubSub/EventFormat.pm .
message = { }
while len(frame):
pos = string.index(frame, "\n")
header = None
value = None
header = frame[ : pos ]
frame = frame[ pos + 1 : ]
if not pos:
# The rest of the frame is the "kn_payload" value.
name = "kn_payload"
value = frame
frame = ""
else:
# Now we've parsed out a header line. Split into name and value.
sep = string.index(header, ":")
nameEscaped = header[ : sep ]
valueEscaped = string.lstrip(header[ sep + 1 : ])
# Decode them.
nameEscapedStream = cStringIO.StringIO(nameEscaped)
valueEscapedStream = cStringIO.StringIO(valueEscaped)
nameStream = cStringIO.StringIO()
valueStream = cStringIO.StringIO()
quopri.decode(nameEscapedStream, nameStream)
quopri.decode(valueEscapedStream, valueStream)
nameStream.seek(0)
valueStream.seek(0)
name = nameStream.read()
value = valueStream.read()
# Decode UTF-8.
nameU = unicode(name, "UTF-8", "replace")
valueU = unicode(value, "UTF-8", "replace")
# Add this name-value pair to the message.
if message.has_key(nameU):
valueU = message[nameU] + ", " + valueU
message[nameU] = valueU
continue
self.onMessage(message)
示例11: decode
def decode(input, output, encoding):
if encoding == 'base64':
import base64
return base64.decode(input, output)
if encoding == 'quoted-printable':
import quopri
return quopri.decode(input, output)
if encoding in ('uuencode', 'x-uuencode', 'uue', 'x-uue'):
import uu
return uu.decode(input, output)
if decodetab.has_key(encoding):
pipethrough(input, decodetab[encoding], output)
else:
raise ValueError, \
'unknown Content-Transfer-Encoding: %s' % encoding
示例12: decode
def decode(input, output, encoding):
if encoding == 'base64':
import base64
return base64.decode(input, output)
if encoding == 'quoted-printable':
import quopri
return quopri.decode(input, output)
if encoding in ('uuencode', 'x-uuencode', 'uue', 'x-uue'):
import uu
return uu.decode(input, output)
if encoding in ('7bit', '8bit'):
return output.write(input.read())
if encoding in decodetab:
pipethrough(input, decodetab[encoding], output)
else:
raise ValueError, 'unknown Content-Transfer-Encoding: %s' % encoding
示例13: decode
def decode(input, output, encoding):
"""Decode common content-transfer-encodings (base64, quopri, uuencode)."""
if encoding == 'base64':
import base64
return base64.decode(input, output)
if encoding == 'quoted-printable':
import quopri
return quopri.decode(input, output)
if encoding in ('uuencode', 'x-uuencode', 'uue', 'x-uue'):
import uu
return uu.decode(input, output)
if encoding in ('7bit', '8bit'):
output.write(input.read())
if decodetab.has_key(encoding):
pipethrough(input, decodetab[encoding], output)
else:
raise ValueError, \
'unknown Content-Transfer-Encoding: %s' % encoding
示例14: test_decode
def test_decode(self):
for p, e in self.STRINGS:
infp = io.BytesIO(e)
outfp = io.BytesIO()
quopri.decode(infp, outfp)
self.assertEqual(outfp.getvalue(), p)
示例15: quopri_decode
def quopri_decode(input, errors='strict'):
assert errors == 'strict'
f = BytesIO(input)
g = BytesIO()
quopri.decode(f, g)
return (g.getvalue(), len(input))