• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python quopri.decode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中quopri.decode函数的典型用法代码示例。如果您正苦于以下问题:Python decode函数的具体用法?Python decode怎么用?Python decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了decode函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:BillyboyD,项目名称:main,代码行数:7,代码来源:test_quopri.py


示例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
开发者ID:jeske,项目名称:csla,代码行数:25,代码来源:email_message.py


示例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)
开发者ID:donnut,项目名称:software,代码行数:55,代码来源:unpack.py


示例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
开发者ID:paulgay,项目名称:crf_dia_ident,代码行数:12,代码来源:Utils.py


示例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))
开发者ID:osuburger,项目名称:Zaarly-Feed,代码行数:14,代码来源:mime.py


示例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))
开发者ID:03013405yujiangfeng,项目名称:XX-Net,代码行数:14,代码来源:quopri_codec.py


示例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()
开发者ID:davidgiven,项目名称:sqmail,代码行数:17,代码来源:textviewer.py


示例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()
开发者ID:davidgiven,项目名称:sqmail,代码行数:18,代码来源:htmlviewer.py


示例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
开发者ID:Exploit-install,项目名称:abusehelper,代码行数:19,代码来源:shadowservermail.py


示例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)
开发者ID:kragen,项目名称:mod_pubsub,代码行数:40,代码来源:pubsublib.py


示例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
开发者ID:arandilopez,项目名称:z-eves,代码行数:15,代码来源:mimetools.py


示例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
开发者ID:bizonix,项目名称:DropBoxLibrarySRC,代码行数:16,代码来源:mimetools.py


示例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
开发者ID:asottile,项目名称:ancient-pythons,代码行数:18,代码来源:mimetools.py


示例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)
开发者ID:5outh,项目名称:Databases-Fall2014,代码行数:6,代码来源:test_quopri.py


示例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))
开发者ID:1958,项目名称:kbengine,代码行数:6,代码来源:quopri_codec.py


示例16: test_decode

 def test_decode(self):
     for p, e in self.STRINGS:
         infp = cStringIO.StringIO(e)
         outfp = cStringIO.StringIO()
         quopri.decode(infp, outfp)
         self.assert_(outfp.getvalue() == p)
开发者ID:AojiaoZero,项目名称:CrossApp,代码行数:6,代码来源:test_quopri.py


示例17: decodestring

def decodestring(instring):
	outfile = io.StringIO()
	quopri.decode(io.StringIO(instring), outfile)
	return outfile.getvalue()
开发者ID:Jueee,项目名称:03-StandardLibrary,代码行数:4,代码来源:lib04.13-quopri.py


示例18:

"""Codec for quoted-printable encoding.
开发者ID:mcyril,项目名称:ravel-ftn,代码行数:1,代码来源:quopri_codec.py


示例19:

"""Various tools used by MIME-reading or MIME-writing programs."""
开发者ID:mcyril,项目名称:ravel-ftn,代码行数:1,代码来源:mimetools.py



注:本文中的quopri.decode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python quopri.decodestring函数代码示例发布时间:2022-05-26
下一篇:
Python text.slugify函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap