Fix StringIO
This commit is contained in:
+6
-3
@@ -3,7 +3,10 @@
|
||||
|
||||
from __future__ import print_function
|
||||
import rfc822
|
||||
import StringIO
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
except:
|
||||
from io import StringIO
|
||||
import Milter
|
||||
|
||||
Milter.NOREPLY = Milter.CONTINUE
|
||||
@@ -152,14 +155,14 @@ class TestBase(object):
|
||||
rc = self.body(buf)
|
||||
if rc != Milter.CONTINUE: return rc
|
||||
self._msg = msg
|
||||
self._body = StringIO.StringIO()
|
||||
self._body = StringIO()
|
||||
rc = self.eom()
|
||||
if self._bodyreplaced:
|
||||
body = self._body.getvalue()
|
||||
else:
|
||||
msg.rewindbody()
|
||||
body = msg.fp.read()
|
||||
self._body = StringIO.StringIO()
|
||||
self._body = StringIO()
|
||||
self._body.writelines(msg.headers)
|
||||
self._body.write('\n')
|
||||
self._body.write(body)
|
||||
|
||||
+5
-2
@@ -9,7 +9,10 @@
|
||||
|
||||
from __future__ import print_function
|
||||
import Milter
|
||||
import StringIO
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
except:
|
||||
from io import StringIO
|
||||
import time
|
||||
import email
|
||||
import sys
|
||||
@@ -75,7 +78,7 @@ class myMilter(Milter.Base):
|
||||
# NOTE: self.fp is only an *internal* copy of message data. You
|
||||
# must use addheader, chgheader, replacebody to change the message
|
||||
# on the MTA.
|
||||
self.fp = StringIO.StringIO()
|
||||
self.fp = StringIO()
|
||||
self.canon_from = '@'.join(parse_addr(mailfrom))
|
||||
self.fp.write('From %s %s\n' % (self.canon_from,time.ctime()))
|
||||
return Milter.CONTINUE
|
||||
|
||||
@@ -94,7 +94,10 @@
|
||||
# This code is under the GNU General Public License. See COPYING for details.
|
||||
|
||||
from __future__ import print_function
|
||||
import StringIO
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
except:
|
||||
from io import StringIO
|
||||
import socket
|
||||
import Milter
|
||||
import zipfile
|
||||
@@ -113,7 +116,7 @@ from types import ListType,StringType
|
||||
## Return a list of filenames in a zip file.
|
||||
# Embedded zip files are recursively expanded.
|
||||
def zipnames(txt):
|
||||
fp = StringIO.StringIO(txt)
|
||||
fp = StringIO(txt)
|
||||
zipf = zipfile.ZipFile(fp,'r')
|
||||
names = []
|
||||
for nm in zipf.namelist():
|
||||
@@ -241,7 +244,7 @@ class MimeMessage(Message):
|
||||
|
||||
def as_string(self, unixfrom=False):
|
||||
"Return the entire formatted message as a string."
|
||||
fp = StringIO.StringIO()
|
||||
fp = StringIO()
|
||||
self.dump(fp,unixfrom=unixfrom)
|
||||
return fp.getvalue()
|
||||
|
||||
@@ -503,7 +506,7 @@ def check_html(msg,savname=None):
|
||||
if name and name.lower().endswith(".htm"):
|
||||
msgtype = 'text/html'
|
||||
if msgtype == 'text/html':
|
||||
out = StringIO.StringIO()
|
||||
out = StringIO()
|
||||
htmlfilter = HTMLScriptFilter(out)
|
||||
try:
|
||||
htmlfilter.write(msg.get_payload(decode=True))
|
||||
|
||||
@@ -7,7 +7,10 @@ from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import os
|
||||
import StringIO
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
except:
|
||||
from io import StringIO
|
||||
import rfc822
|
||||
import mime
|
||||
import Milter
|
||||
@@ -39,7 +42,7 @@ class sampleMilter(Milter.Milter):
|
||||
def envfrom(self,f,*str):
|
||||
"start of MAIL transaction"
|
||||
self.log("mail from",f,str)
|
||||
self.fp = StringIO.StringIO()
|
||||
self.fp = StringIO()
|
||||
self.tempname = None
|
||||
self.mailfrom = f
|
||||
self.bodysize = 0
|
||||
|
||||
+5
-2
@@ -30,7 +30,10 @@ from __future__ import print_function
|
||||
import unittest
|
||||
import mime
|
||||
import socket
|
||||
import StringIO
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
except:
|
||||
from io import StringIO
|
||||
import email
|
||||
import sys
|
||||
import Milter
|
||||
@@ -180,7 +183,7 @@ class MimeTestCase(unittest.TestCase):
|
||||
self.assertEquals(rc,Milter.CONTINUE)
|
||||
|
||||
def testHTML(self,fname=""):
|
||||
result = StringIO.StringIO()
|
||||
result = StringIO()
|
||||
filter = mime.HTMLScriptFilter(result)
|
||||
msg = """<! Illegal declaration used as comment>
|
||||
<![if conditional]> Optional SGML <![endif]>
|
||||
|
||||
@@ -3,7 +3,6 @@ import Milter
|
||||
import sample
|
||||
import mime
|
||||
import rfc822
|
||||
import StringIO
|
||||
from Milter.test import TestBase
|
||||
|
||||
class TestMilter(TestBase,sample.sampleMilter):
|
||||
|
||||
Reference in New Issue
Block a user