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

Python quopri.encode函数代码示例

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

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



在下文中一共展示了encode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_encode

 def test_encode(self):
     for p, e in self.STRINGS:
         infp = cStringIO.StringIO(p)
         outfp = cStringIO.StringIO()
         if not test_support.due_to_ironpython_bug("http://tkbgitvstfat01:8080/WorkItemTracking/WorkItem.aspx?artifactMoniker=305368"):
             quopri.encode(infp, outfp, quotetabs=False)
             self.assertTrue(outfp.getvalue() == e)
开发者ID:BillyboyD,项目名称:main,代码行数:7,代码来源:test_quopri.py


示例2: __init__

 def __init__(self, http_request, request_id):
     HTTPMessage.__init__(self)
     self.set_type('application/http-request')
     self.add_header('Multipart-Request-ID', str(request_id))
     self.add_header('Content-transfer-encoding', 'quoted-printable')
     payload = StringIO()
     quopri.encode(StringIO(http_request), payload, quotetabs=False)
     self.set_payload(payload.getvalue())
     payload.close()
开发者ID:giorgil2,项目名称:batchhttp,代码行数:9,代码来源:multipart.py


示例3: __init__

 def __init__(self, http_response, request_id):
     HTTPMessage.__init__(self)
     self.set_type("application/http-response")
     self.add_header("Multipart-Request-ID", str(request_id))
     self.add_header("Content-transfer-encoding", "quoted-printable")
     payload = StringIO()
     quopri.encode(StringIO(http_response), payload, quotetabs=False)
     self.set_payload(payload.getvalue())
     payload.close()
开发者ID:apparentlymart,项目名称:batchhttp,代码行数:9,代码来源:multipart.py


示例4: send_mail

def send_mail(send_from, send_to, subject, text, files=[], server="localhost", user=None, password=None):
  assert type(send_to)==list
  assert type(files)==list

  msg = MIMEMultipart()
  msg['From'] = send_from
  msg['To'] = COMMASPACE.join(send_to)
  msg['Date'] = formatdate(localtime=True)
  msg['Subject'] = subject

  msg.attach( MIMEText(text, _charset='utf-8') )

  for fileName in files:
    contentType,ignored=mimetypes.guess_type(fileName)
    if contentType==None: # If no guess, use generic opaque type
      contentType="application/octet-stream"
    contentsEncoded=cStringIO.StringIO()
    f=open(fileName,"rb")
    mainType=contentType[:contentType.find("/")]
    if mainType=="text":
      cte="quoted-printable"
      quopri.encode(f,contentsEncoded,1) # 1 for encode tabs
    else:
      cte="base64"
      base64.encode(f,contentsEncoded)
    f.close()
    subMsg=email.Message.Message()
    subMsg.add_header("Content-type",contentType,name=flatten_name(fileName))
    subMsg.add_header("Content-transfer-encoding",cte)
    subMsg.set_payload(contentsEncoded.getvalue())
    contentsEncoded.close()
    msg.attach(subMsg)



#    part = MIMEBase('application', "octet-stream")
#    part.set_payload( open(file,"rb").read() )
#    Encoders.encode_base64(part)
#    part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
#    msg.attach(part)

#  print server
  smtp = smtplib.SMTP(server, 587)
#  smtp.set_debuglevel(1)
  smtp.ehlo()
  settings = HandshakeSettings()
  smtp.starttls()
  if (user != None and password != None):
    smtp.login(user, password)
  print "Sending mail to " + msg['To']
  smtp.sendmail(send_from, send_to, msg.as_string())
  print "mail sent."
  smtp.close()
  print "done"
开发者ID:lacostej,项目名称:eureka,代码行数:54,代码来源:mailer.py


示例5: _qencode

 def _qencode(s):
     if not s:
         return s
     hasnewline = (s[-1] == '\n')
     infp = StringIO(s)
     outfp = StringIO()
     _quopri.encode(infp, outfp, quotetabs=1)
     # Python 2.x's encode() doesn't encode spaces even when quotetabs==1
     value = outfp.getvalue().replace(' ', '=20')
     if not hasnewline and value[-1] == '\n':
         return value[:-1]
     return value
开发者ID:B-Rich,项目名称:breve,代码行数:12,代码来源:Encoders.py


示例6: quopri_encode

def quopri_encode(input, errors='strict'):
    """Encode 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(input)
    g = StringIO()
    quopri.encode(f, g, 1)
    output = g.getvalue()
    return (output, len(input))
开发者ID:B-Rich,项目名称:breve,代码行数:14,代码来源:quopri_codec.py


示例7: quopri_encode

def quopri_encode(input, errors='strict'):
    """Encode 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'
    # using str() because of cStringIO's Unicode undesired Unicode behavior.
    f = StringIO(str(input))
    g = StringIO()
    quopri.encode(f, g, quotetabs=True)
    output = g.getvalue()
    return (output, len(input))
开发者ID:03013405yujiangfeng,项目名称:XX-Net,代码行数:15,代码来源:quopri_codec.py


示例8: standard_message

    def standard_message(self, to, subject, content, author=None):
        """Send a standard message.

        Arguments:
        - to: a list of addresses usable by rfc822.parseaddr().
        - subject: the subject as a string.
        - content: the body of the message as a string.
        - author: the sender as a (name, address) tuple
        """
        message, writer = self.get_standard_message(to, subject, author)

        writer.addheader("Content-Transfer-Encoding", "quoted-printable")
        body = writer.startbody("text/plain; charset=utf-8")
        content = StringIO(content)
        quopri.encode(content, body, 0)

        self.smtp_send(to, message)
开发者ID:hemmecke,项目名称:roundup4071,代码行数:17,代码来源:mailer.py


示例9: main

def main():
  mainMsg=email.Message.Message()
  mainMsg["To"]=toAddr
  mainMsg["From"]=fromAddr
  mainMsg["Subject"]="Directory contents"
  mainMsg["Date"]=email.Utils.formatdate(localtime=1)
  mainMsg["Message-ID"]=email.Utils.make_msgid()
  mainMsg["Mime-version"]="1.0"
  mainMsg["Content-type"]="Multipart/mixed"
  mainMsg.preamble="Mime message\n"
  mainMsg.epilogue="" # To ensure that message ends with newline
  
  firstSubMsg=email.Message.Message()
  firstSubMsg["Content-type"]="text/plain"
  firstSubMsg["Content-transfer-encoding"]="7bit"
  firstSubMsg.set_payload("Files from directory\n")
  mainMsg.attach(firstSubMsg)
  
  # Get names of plain files
  fileNames=[f for f in os.listdir(os.curdir) if os.path.isfile(f)]
  for fileName in fileNames:
    contentType,ignored=mimetypes.guess_type(fileName)
    if contentType==None: # If no guess, use generic opaque type
      contentType="application/octet-stream"
    contentsEncoded=cStringIO.StringIO()
    f=open(fileName,"rb")
    mainType=contentType[:contentType.find("/")]
    if mainType=="text":
      cte="quoted-printable"
      quopri.encode(f,contentsEncoded,1) # 1 for encode tabs
    else:
      cte="base64"
      base64.encode(f,contentsEncoded)
    f.close()
    subMsg=email.Message.Message()
    subMsg.add_header("Content-type",contentType,name=fileName)
    subMsg.add_header("Content-transfer-encoding",cte)
    subMsg.set_payload(contentsEncoded.getvalue())
    contentsEncoded.close()
    mainMsg.attach(subMsg)

  f=open(outputFile,"wb")
  f.write(mainMsg.as_string())
  f.close()
  return None
开发者ID:jacob-carrier,项目名称:code,代码行数:45,代码来源:recipe-86674.py


示例10: send

 def send(self, report_file, from_addr, to_addrs):
     if self.init == False:
         print("Instance not properly instanitiated")
         return -1
     
     self.msgs = [email.Message.Message() for to in to_addrs]        
     for msg , to in zip(self.msgs, to_addrs):
         msg["From"] = from_addr
         msg["To"] = to
         msg["Subject"] = "Auto-Test Result Reporting"
         msg["MIME-Version"] = "1.0"
         msg["Content-Type"] = "Multipart/mixed"
         msg.preamble = "MIME Message"
         msg.epilogue = ""
     
     content_type, ignored = mimetypes.guess_type(report_file)
     if content_type == None:
         content_type = "Application/octet-stream"
     content_encoded = cStringIO.StringIO()
     with open(report_file, "rb") as f:
         main_type = content_type[:content_type.find("/")]
         if main_type == "text":
             cte = "quoted-printable"
             quopri.encode(f, content_encoded, 1)
         else:
             cte = "base64"
             base64.encode(f, content_encoded)
         f.close()
     
     sub_msg = email.Message.Message()
     sub_msg.add_header("Content-Type", content_type, name = report_file)
     sub_msg.add_header("Content-Transfer-Encoding", cte)
     sub_msg.set_payload(content_encoded.getvalue())
     content_encoded.close()
     for msg, to in zip(self.msgs, to_addrs):
         msg.attach(sub_msg)
         f = StringIO.StringIO()
         g = email.Generator.Generator(f)
         g.flatten(msg)
         try:
             self.smtp.sendmail(from_addr, to, f.getvalue())    
         except Exception:
             print("send to %s failed" % to)
         f.close()
开发者ID:harrytan007,项目名称:TestStation,代码行数:44,代码来源:report_utils.py


示例11: emailTurnin

 def emailTurnin(self):
     #Get email information
     try:
         addr = JESAddressFinder.JESAddressFinder()
         taEmail = addr.getTargetAddress(self.gtNumber, self.hwTitle)
         if(taEmail == None):
             raise StandardError, "Could not find an e-mail to send assignment."
             return            
         
         filehandle = open(self.zipFile,"rb")
        #CONSTRUCT EMAIL
        #Build the email from all the parts of information:
         subject = "%s : %s : %s : %s" % \
                   (self.hwTitle, self.studentName, self.gtNumber, self.fileName)  
         msgBody = 'From: %s\n' % self.studentEmail
         msgBody += 'Subject: %s\n' % subject
         file = StringIO.StringIO()
         mime = MimeWriter.MimeWriter(file)
         mime.addheader("Mime-Version","1.0")
         mime.startmultipartbody("mixed")
         part=mime.nextpart()
         part.addheader("Content-Transfer-Encoding","quoted-printable")
         part.startbody("text/plain")
         quopri.encode(StringIO.StringIO("An Assignment Submission from "+self.studentName),file,0)
         quopri.encode(StringIO.StringIO("Notes to TA: "),file,0)
         #quopri.encode(StringIO.StringIO(notes),file,0)
         part = mime.nextpart()
         part.addheader("Content-Transfer-Encoding","base64")
         part.startbody('application/x-zip-compressed; name='+self.zipFile) 
         base64.encode(filehandle, file)
         mime.lastpart()
         msgBody += file.getvalue()
         filehandle.close()
        #END CONSTRUCT EMAIL
         #SEND EMAIL:
         servObj = smtplib.SMTP(self.mailServer)
         servObj.sendmail(self.studentEmail, taEmail, msgBody)
     except:
         print "Student E-mail: " + self.studentEmail + "\n"
         import sys
         a,b,c=sys.exc_info()
         print a,b,c
         raise StandardError, "Error emailing assignment."
开发者ID:Bail-jw,项目名称:mediacomp-jes,代码行数:43,代码来源:JESHomeworkSubmission.py


示例12: main

def main():
    main_msg = email.Message.Message()
    main_msg["To"] = T_ADDR
    main_msg["From"] = F_ADDR
    main_msg["Subject"] = "Directory contents"
    main_msg["Mime-version"] = "1.0"
    main_msg["Content-type"] = "Multipart/mixed"
    main_msg.preamble = "Mime message\n"
    main_msg.epilogue = ""

    file_names = [f for f in os.listdir(os.curdir) if os.path.isfile(f)]
    for file_name in file_names:
        content_type,ignored = mimetypes.guess_type(file_name)
        if content_type is None:
            content_type = "application/octet-stream"
        contents_encoded = cStringIO.StringIO()
        with open(file_name,"rb") as f:
            main_type = content_type[:content_type.find("/")]
            if main_type == "text":
                cte = "quoted-printable"
                quopri.encode(f,contents_encoded,True)
            else:
                cte = "base64"
                base64.encode(f,contents_encoded)
        sub_msg = email.Message.Message()
        sub_msg.add_header("Content-type",content_type,name=file_name)
        sub_msg.add_header("Content-transfer-encoding",cte)
        sub_msg.set_payload(contents_encoded.getvalue())
        contents_encoded.close()
        main_msg.attach(sub_msg)
    body_content = email.Message.Message()
    body_content.set_type("text/plain")
    body_content.set_payload("hello word")
    main_msg.attach(body_content)
    
    f = open(output_file,"wb")
    g = email.Generator.Generator(f)
    g.flatten(main_msg)
    f.close()
    return None
开发者ID:hongyuanlei,项目名称:papersite,代码行数:40,代码来源:mail_multipart.py


示例13: write

    def write(self, data, mimetype="text/plain"):
        "Write data from string or file to message"

        # data is either an opened file or a string
        if type(data) is type(""):
            file = StringIO.StringIO(data)
        else:
            file = data
            data = None

        part = self.mime.nextpart()

        typ, subtyp = string.split(mimetype, "/", 1)

        if typ == "text":

            # text data
            encoding = "quoted-printable"
            encoder = lambda i, o: quopri.encode(i, o, 0)

            if data and not must_quote(data):
                # copy, don't encode
                encoding = "7bit"
                encoder = None

        else:

            # binary data (image, audio, application, ...)
            encoding = "base64"
            encoder = base64.encode

        #
        # write part headers

        if encoding:
            part.addheader("Content-Transfer-Encoding", encoding)

        part.startbody(mimetype)

        #
        # write part body

        if encoder:
            encoder(file, self.file)
        elif data:
            self.file.write(data)
        else:
            while 1:
                data = infile.read(16384)
                if not data:
                    break
                outfile.write(data)
开发者ID:mtslong,项目名称:demo,代码行数:52,代码来源:mimewriter-example-2.py


示例14: attach

 def attach(self, chemin_fichier):
     raise NotImplementedError
     fileName = chemin_fichier.split( '/' )[-1]
     contentType,ignored=mimetypes.guess_type(fileName)
     if contentType==None: # If no guess, use generic opaque type
       contentType="application/octet-stream"
     contentsEncoded=cStringIO.StringIO()
     f=open(chemin_fichier,"rb")
     mainType=contentType[:contentType.find("/")]
     if mainType=="text":
       cte="quoted-printable"
       quopri.encode(f,contentsEncoded,1) # 1 for encode tabs
     else:
       cte="base64"
       base64.encode(f,contentsEncoded)
     f.close()
     subMsg=email.Message.Message()
     subMsg.add_header("Content-type",contentType,name=fileName)
     subMsg.add_header("Content-transfer-encoding",cte)
     subMsg.set_payload(contentsEncoded.getvalue())
     contentsEncoded.close()
     self.__email.attach( subMsg )
开发者ID:joel-m,项目名称:collorg,代码行数:22,代码来源:mail.py


示例15: encode

def encode(input, output, encoding):
	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 encodetab.has_key(encoding):
		pipethrough(input, encodetab[encoding], output)
	else:
		raise ValueError, \
		      'unknown Content-Transfer-Encoding: %s' % encoding
开发者ID:arandilopez,项目名称:z-eves,代码行数:15,代码来源:mimetools.py


示例16: main

def main():
    mainMsg = email.Message.Message()
    mainMsg["To"] = toAddr
    mainMsg["From"] = fromAddr
    mainMsg["Subject"] = "Directory contents"
    mainMsg["Mime-version"] = "1.0"
    mainMsg["Content-type"] = "Multipart/mixed"
    mainMsg.preamble = "Mime message\n"
    mainMsg.epilogue = "" # to ensure that message ends with newline
    # Get names of plain files (not subdirectories or special files)
    fileNames = [f for f in os.listdir(os.curdir) if os.path.isfile(f)]
    for fileName in fileNames:
        contentType, ignored = mimetypes.guess_type(fileName)
        if contentType is None:     # If no guess, use generic opaque type
            contentType = "application/octet-stream"
        contentsEncoded = cStringIO.StringIO()
        f = open(fileName, "rb")
        mainType = contentType[:contentType.find("/")]
        if mainType=="text":
            cte = "quoted-printable"
            quopri.encode(f, contentsEncoded, 1)   # 1 to also encode tabs
        else:
            cte = "base64"
            base64.encode(f, contentsEncoded)
        f.close()
        subMsg = email.Message.Message()
        subMsg.add_header("Content-type", contentType, name=fileName)
        subMsg.add_header("Content-transfer-encoding", cte)
        subMsg.set_payload(contentsEncoded.getvalue())
        contentsEncoded.close()
        mainMsg.attach(subMsg)
    f = open(outputFile, "wb")
    g = email.Generator.Generator(f)
    g.flatten(mainMsg)
    f.close()
    return None
开发者ID:badboywj,项目名称:python_practice,代码行数:36,代码来源:cb2_13_6_sol_1.py


示例17: encode

def encode(input, output, encoding):
    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
开发者ID:bizonix,项目名称:DropBoxLibrarySRC,代码行数:16,代码来源:mimetools.py


示例18: encode

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'):
		output.write(input.read())
	if encodetab.has_key(encoding):
		pipethrough(input, encodetab[encoding], output)
	else:
		raise ValueError, \
		      'unknown Content-Transfer-Encoding: %s' % encoding
开发者ID:asottile,项目名称:ancient-pythons,代码行数:18,代码来源:mimetools.py


示例19: encodestring

def encodestring(instring, tabs = 0):
	outfile = io.StringIO()
	print(io.StringIO(instring),type(io.StringIO(instring)))
	print(outfile,type(outfile))
	quopri.encode(io.StringIO(instring), outfile, tabs)
	return outfile.getvalue()
开发者ID:Jueee,项目名称:03-StandardLibrary,代码行数:6,代码来源:lib04.13-quopri.py


示例20:

#!/usr/bin/env python

import getopt
import quopri
import base64
import sys

#               QP?    Decode?
codingfuncs = {(True,  True): quopri.decode,
               (True,  False): lambda x,y: quopri.encode(x,y,False),
               (False, True): base64.decode,
               (False, False): base64.encode}

qp = False
decode = False
opts, args = getopt.getopt(sys.argv[1:], "qu")
for opt, arg in opts:
    if opt == "-q":
        qp = True
    elif opt == "-u":
        decode = True

codingfuncs[(qp, decode)](sys.stdin, sys.stdout)

    
开发者ID:nickzuck007,项目名称:python-bits,代码行数:23,代码来源:mmencode.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python quopri.encodestring函数代码示例发布时间:2022-05-26
下一篇:
Python quopri.decodestring函数代码示例发布时间: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