python类quotedata()的实例源码

test_smtplib.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def testQuoteData(self):
        teststr  = "abc\n.jkl\rfoo\r\n..blue"
        expected = "abc\r\n..jkl\r\nfoo\r\n...blue"
        self.assertEqual(expected, smtplib.quotedata(teststr))
test_smtplib.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def testQuoteData(self):
        teststr  = "abc\n.jkl\rfoo\r\n..blue"
        expected = "abc\r\n..jkl\r\nfoo\r\n...blue"
        self.assertEqual(expected, smtplib.quotedata(teststr))
test_smtplib.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def testQuoteData(self):
        teststr  = "abc\n.jkl\rfoo\r\n..blue"
        expected = "abc\r\n..jkl\r\nfoo\r\n...blue"
        self.assertEqual(expected, smtplib.quotedata(teststr))
test_smtplib.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def testQuoteData(self):
        teststr  = "abc\n.jkl\rfoo\r\n..blue"
        expected = "abc\r\n..jkl\r\nfoo\r\n...blue"
        self.assertEqual(expected, smtplib.quotedata(teststr))
ngamsSmtpLib.py 文件源码 项目:ngas 作者: ICRAR 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def data(self,
             msg):
        """
        SMTP 'DATA' command -- sends message data to server.

        Automatically quotes lines beginning with a period per rfc821.
        Raises SMTPDataError if there is an unexpected reply to the
        DATA command; the return value from this method is the final
        response code received when the all data is sent.

        msg:      Message in a string buffer or a filename referring to
                  a file containin the data to be send (string).

        Returns:  Tuple with the status code + a message from the SMTP
                  host (tuple/integer, string).
        """
        self.putcmd("data")
        (code, repl) = self.getreply()
        if self.debuglevel >0 : print "data:", (code, repl)
        if code != 354:
            raise smtplib.SMTPDataError(code, repl)
        else:
            if (not self.__msgInFile):
                # Data contained in the message in memory.
                q = smtplib.quotedata(msg)
                if q[-2:] != smtplib.CRLF: q = q + smtplib.CRLF
                q = q + "." + smtplib.CRLF
                self.send(q)
            else:
                # Data to send is contained in a file.
                fo = open(msg)
                while (1):
                    buf = fo.read(16384)
                    if (buf == ""): break
                    qBuf = smtplib.quotedata(buf)
                    self.send(buf)
                fo.close()
                self.send(smtplib.CRLF + "." + smtplib.CRLF)

            (code, msg) = self.getreply()
            if (self.debuglevel > 0): print "data:", (code, msg)
            return (code, msg)


问题


面经


文章

微信
公众号

扫码关注公众号