From ea84943f291decc631d960d46dc392bf25b8e4af Mon Sep 17 00:00:00 2001 From: "Stuart D. Gathman" Date: Tue, 26 Jul 2016 10:06:56 -0400 Subject: [PATCH] Fix StringIO --- Milter/test.py | 9 ++++++--- milter-template.py | 7 +++++-- mime.py | 11 +++++++---- sample.py | 7 +++++-- testmime.py | 7 +++++-- testsample.py | 1 - 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Milter/test.py b/Milter/test.py index 1573052..8c9167d 100644 --- a/Milter/test.py +++ b/Milter/test.py @@ -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) diff --git a/milter-template.py b/milter-template.py index b41c50c..b2239d2 100644 --- a/milter-template.py +++ b/milter-template.py @@ -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 diff --git a/mime.py b/mime.py index 6e075ec..c23da72 100644 --- a/mime.py +++ b/mime.py @@ -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)) diff --git a/sample.py b/sample.py index eb1c4ec..c4fc033 100644 --- a/sample.py +++ b/sample.py @@ -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 diff --git a/testmime.py b/testmime.py index 94e0b25..28c7c16 100644 --- a/testmime.py +++ b/testmime.py @@ -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 = """ Optional SGML diff --git a/testsample.py b/testsample.py index be10b06..285dee3 100644 --- a/testsample.py +++ b/testsample.py @@ -3,7 +3,6 @@ import Milter import sample import mime import rfc822 -import StringIO from Milter.test import TestBase class TestMilter(TestBase,sample.sampleMilter):