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