Python smtplib 模块,quotedata() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用smtplib.quotedata()

项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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))
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
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))
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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))
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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))
项目:ngas    作者:ICRAR    | 项目源码 | 文件源码
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)