Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion SES/ses.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
try: from hashlib import sha1 as sha
except: import sha
import struct
import syslog

DAY = 24*60*60 # size of day

Expand Down Expand Up @@ -130,7 +131,7 @@ def get_timecode(self,s=None):
return int(s / self.frac_day)

def warn(self,*msg):
print('WARNING:',' '.join(msg), file=sys.stderr)
syslog.syslog('WARNING: ' + ' '.join(msg))

def set_secret(self,*args):
"""ses.set_secret(new,old,...)
Expand Down
6 changes: 3 additions & 3 deletions SocketMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ def handle(self):
try:
line = self.read()
self.log(repr(line))
args = line.split(b' ',1)
mapname = args.pop(0).decode().replace('-','_')
args = line.decode().split(' ',1)
mapname = args.pop(0).replace('-','_')
meth = getattr(self, '_handle_' + mapname, None)
if not map:
if not meth:
raise ValueError("Unrecognized map: %s" % mapname)
res = meth(*args)
self.write('OK ' + res)
Expand Down
15 changes: 6 additions & 9 deletions pysrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
import SocketMap
import time
import sys
import syslog

class SRSHandler(SocketMap.Handler):

def log(self,*msg):
# print "%s [%d]" % (time.strftime('%Y%b%d %H:%M:%S'),self.id),
print("%s" % (time.strftime('%Y%b%d %H:%M:%S'),), end=' ')
for i in msg: print(i, end=' ')
print()
sys.stdout.flush()
syslog.syslog(' '.join(msg))

bracketRE = re.compile(r'[<>]')
traildotRE = re.compile(r'\.$')
Expand All @@ -37,7 +34,7 @@ def log(self,*msg):
#
# We need to preprocess it some:
def _handle_make_srs(self,old_address):
a = [s.decode() for s in old_address.split(b'\x9b')]
a = [s for s in old_address.split('\x9b')]
if len(a) == 2:
h,old_address = a
self.log('h =',h)
Expand Down Expand Up @@ -86,7 +83,6 @@ def _handle_reverse_srs(self,old_address):
# Munge ParseLocal recipient in the same manner as required
# in EnvFromSMTP.

old_address = old_address.decode()
use_address = self.bracketRE.sub('',old_address)
use_address = self.traildotRE.sub('',use_address)

Expand Down Expand Up @@ -161,10 +157,11 @@ def main(args):

daemon.server.srs = srs
daemon.server.ses = ses
print("%s pysrs startup" % time.strftime('%Y%b%d %H:%M:%S'))
syslog.openlog('pysrs.py',0,syslog.LOG_MAIL)
syslog.syslog('pysrs: started')
sys.stdout.flush()
daemon.run()
print("%s pysrs shutdown" % time.strftime('%Y%b%d %H:%M:%S'))
syslog.syslog('pysrs: shutdown')

if __name__ == "__main__":
main(sys.argv[1:])