Use print function everywhere

This commit is contained in:
Stuart D. Gathman
2016-07-26 09:52:40 -04:00
parent 99552b40e9
commit 76eb93223c
12 changed files with 46 additions and 35 deletions
+5 -4
View File
@@ -8,6 +8,7 @@
# Copyright 2001,2009 Business Management Systems, Inc.
# This code is under the GNU General Public License. See COPYING for details.
from __future__ import print_function
__version__ = '0.9.8'
import os
@@ -365,7 +366,7 @@ class Base(object):
for func,(nr,nc) in OPTIONAL_CALLBACKS.items():
func = getattr(klass,func)
ca = getattr(func,'milter_protocol',0)
#print func,hex(nr),hex(nc),hex(ca)
#print(func,hex(nr),hex(nc),hex(ca))
p |= (nr|nc) & ~ca
klass._protocol_mask = p
return p
@@ -579,9 +580,9 @@ class Milter(Base):
## Provide simple logging to sys.stdout
def log(self,*msg):
print 'Milter:',
for i in msg: print i,
print
print('Milter:',end=None)
for i in msg: print(i,end=None)
print()
@noreply
def connect(self,hostname,family,hostaddr):
+5 -2
View File
@@ -46,6 +46,7 @@
# Copyright 2001,2002,2003,2004,2005 Business Management Systems, Inc.
# This code is under the GNU General Public License. See COPYING for details.
from __future__ import print_function
import time
from plock import PLock
@@ -147,7 +148,8 @@ class AddrCache(object):
if not ts: return # already permanent
self.cache[lsender] = (None,res)
if not res:
print >>open(self.fname,'a'),sender
with open(self.fname,'a') as fp:
print(sender,file=fp)
def __setitem__(self,sender,res):
lsender = sender.lower()
@@ -155,7 +157,8 @@ class AddrCache(object):
self.cache[lsender] = (now,res)
if not res and self.fname:
s = time.strftime(AddrCache.time_format,time.localtime(now))
print >>open(self.fname,'a'),sender,s # log refreshed senders
with open(self.fname,'a') as fp:
print(sender,s,file=fp) # log refreshed senders
def __len__(self):
return len(self.cache)
+3 -2
View File
@@ -1,6 +1,7 @@
## @package Milter.dns
# Provide a higher level interface to pydns.
from __future__ import print_function
import DNS
from DNS import DNSError
@@ -120,5 +121,5 @@ if __name__ == '__main__':
import sys
s = Session()
for n,t in zip(*[iter(sys.argv[1:])]*2):
print n,t
print s.dns(n,t)
print(n,t)
print(s.dns(n,t))
+4 -3
View File
@@ -69,6 +69,7 @@
# a DSN or use a null MAIL FROM with an email address obtained from
# anywhere else.
#
from __future__ import print_function
import smtplib
import socket
from email.Message import Message
@@ -230,6 +231,6 @@ Subject: Test
Test DSN template
"""
)
print msg.as_string()
# print send_dsn(f,msg.as_string())
# print send_dsn(q.s,'mail.example.com',msg.as_string())
print(msg.as_string())
# print(send_dsn(f,msg.as_string()))
# print(send_dsn(q.s,'mail.example.com',msg.as_string()))
+3 -2
View File
@@ -9,6 +9,7 @@
# wiley-268-8196.roadrunner.nf.net at ('205.251.174.46', 4810)
# cbl-sd-02-79.aster.com.do at ('200.88.62.79', 4153)
from __future__ import print_function
import re
ip3 = re.compile('[0-9]{1,3}')
@@ -91,6 +92,6 @@ if __name__ == '__main__':
if ip in seen: continue
seen.add(ip)
if is_dynip(host,ip):
print '%s\t%s DYN' % (ip,host)
print('%s\t%s DYN' % (ip,host))
else:
print '%s\t%s' % (ip,host)
print('%s\t%s' % (ip,host))
+2 -1
View File
@@ -1,3 +1,4 @@
from __future__ import print_function
import time
import shelve
import thread
@@ -58,7 +59,7 @@ class Greylist(object):
cnt = 0
dbp = self.dbp
for key, r in dbp.iteritems():
#print key,r,time.ctime(now)
#print(key,r,time.ctime(now))
if now > r.lastseen + self.greylist_retain:
self.lock.acquire()
try:
+2 -1
View File
@@ -6,6 +6,7 @@ This module is free software, and you may redistribute it and/or modify
it under the same terms as Python itself, so long as this copyright message
and disclaimer are retained in their original form.
"""
from __future__ import print_function
import struct
#from spf import RE_IP4
import re
@@ -80,7 +81,7 @@ def inet_pton(p):
(0, 0, 0, 0, 0, 65535, 258, 772)
>>> try: inet_pton('::1.2.3.4.5')
... except ValueError,x: print x
... except ValueError,x: print(x)
::1.2.3.4.5
"""
if p == '::':
+3 -2
View File
@@ -1,6 +1,7 @@
## @package Milter.test
# A test framework for milters
from __future__ import print_function
import rfc822
import StringIO
import Milter
@@ -35,8 +36,8 @@ class TestBase(object):
self._symlist = [ None, None, None, None, None, None, None ]
def log(self,*msg):
for i in msg: print >>self.logfp, i,
print >>self.logfp
for i in msg: print(i,file=self.logfp,end=None)
print(file=self.logfp,flush=True)
## Set a macro value.
# These are retrieved by the %milter with getsymval.
+7 -6
View File
@@ -7,6 +7,7 @@
## Return REJECT,TEMPFAIL,ACCEPT to short circuit processing for a message.
## You can also add/del recipients, replacebody, add/del headers, etc.
from __future__ import print_function
import Milter
import StringIO
import time
@@ -131,10 +132,11 @@ def background():
t = logq.get()
if not t: break
msg,id,ts = t
print "%s [%d]" % (time.strftime('%Y%b%d %H:%M:%S',time.localtime(ts)),id),
print("%s [%d]" % (time.strftime('%Y%b%d %H:%M:%S',time.localtime(ts)),id),
end=None)
# 2005Oct13 02:34:11 [1] msg1 msg2 msg3 ...
for i in msg: print i,
print
for i in msg: print(i,end=None)
print(flush=True)
## ===
@@ -149,12 +151,11 @@ def main():
flags += Milter.ADDRCPT
flags += Milter.DELRCPT
Milter.set_flags(flags) # tell Sendmail which features we use
print "%s milter startup" % time.strftime('%Y%b%d %H:%M:%S')
sys.stdout.flush()
print("%s milter startup" % time.strftime('%Y%b%d %H:%M:%S'),flush=True)
Milter.runmilter("pythonfilter",socketname,timeout)
logq.put(None)
bt.join()
print "%s bms milter shutdown" % time.strftime('%Y%b%d %H:%M:%S')
print("%s bms milter shutdown" % time.strftime('%Y%b%d %H:%M:%S'))
if __name__ == "__main__":
main()
+2 -1
View File
@@ -93,6 +93,7 @@
# Copyright 2001,2002,2003,2004,2005 Business Management Systems, Inc.
# This code is under the GNU General Public License. See COPYING for details.
from __future__ import print_function
import StringIO
import socket
import Milter
@@ -532,7 +533,7 @@ if __name__ == '__main__':
def _list_attach(msg):
t = msg.get_content_type()
p = msg.get_payload(decode=True)
print msg.get_filename(),msg.get_content_type(),type(p)
print(msg.get_filename(),msg.get_content_type(),type(p))
msg = msg.get_submsg()
if isinstance(msg,Message):
return check_attachments(msg,_list_attach)
+7 -8
View File
@@ -1,4 +1,4 @@
from __future__ import print_function
# A simple milter.
# Author: Stuart D. Gathman <stuart@bmsi.com>
@@ -21,9 +21,9 @@ class sampleMilter(Milter.Milter):
"Milter to replace attachments poisonous to Windows with a WARNING message."
def log(self,*msg):
print "%s [%d]" % (strftime('%Y%b%d %H:%M:%S'),self.id),
for i in msg: print i,
print
print("%s [%d]" % (strftime('%Y%b%d %H:%M:%S'),self.id),end=None)
for i in msg: print(i,end=None)
print(flush=True)
def __init__(self):
self.tempname = None
@@ -171,13 +171,12 @@ if __name__ == "__main__":
socketname = os.getenv("HOME") + "/pythonsock"
Milter.factory = sampleMilter
Milter.set_flags(Milter.CHGBODY + Milter.CHGHDRS + Milter.ADDHDRS)
print """To use this with sendmail, add the following to sendmail.cf:
print("""To use this with sendmail, add the following to sendmail.cf:
O InputMailFilters=pythonfilter
Xpythonfilter, S=local:%s
See the sendmail README for libmilter.
sample milter startup""" % socketname
sys.stdout.flush()
sample milter startup""" % socketname,flush=True)
Milter.runmilter("pythonfilter",socketname,240)
print "sample milter shutdown"
print("sample milter shutdown")
+3 -3
View File
@@ -1,3 +1,4 @@
from __future__ import print_function
import unittest
import doctest
import os
@@ -32,9 +33,8 @@ class AddrCacheTestCase(unittest.TestCase):
self.failUnless(not cache['temp@bar.com'])
def testDomain(self):
fp = open(self.fname,'w')
print >>fp,'spammer.com'
fp.close()
with open(self.fname,'w') as fp:
print('spammer.com',file=fp)
cache = AddrCache(fname=self.fname)
cache.load(self.fname,30)
self.failUnless('spammer.com' in cache)