Milter.utils.parse_header returns string, other py3 fixes

This commit is contained in:
Stuart D. Gathman
2020-06-25 19:47:38 -04:00
parent 7ea839cfb1
commit f37090371b
5 changed files with 15 additions and 8 deletions
+5 -3
View File
@@ -34,7 +34,8 @@ class MilterConfigParser(ConfigParser):
if q.startswith('file:'):
domain = q[5:].lower()
fname = os.path.join(dir,domain)
d[domain] = d.setdefault(domain,[]) + open(fname,'r').read().split()
with open(fname,'r') as fp:
d[domain] = d.setdefault(domain,[]) + fp.read().split()
else:
user,domain = q.split('@')
d.setdefault(domain.lower(),[]).append(user)
@@ -52,8 +53,9 @@ class MilterConfigParser(ConfigParser):
addr = addr.strip()
if addr.startswith('file:'):
fname = os.path.join(dir,addr[5:])
for a in open(fname,'r').read().split():
d[a] = q
with open(fname,'r') as fp:
for a in fp.read().split():
d[a] = q
else:
d[addr] = q
return d
+1 -1
View File
@@ -64,7 +64,7 @@ class TestBase(object):
def getsymval(self,name):
stage = self._stage
if stage >= 0:
if stage is not None and stage >= 0:
syms = self._symlist[stage]
if syms is not None and name not in syms:
return None
+2 -1
View File
@@ -216,7 +216,8 @@ def parse_header(val):
u.append(s.decode())
else:
u.append(s.decode())
u = u''.join(u)
u = ''.join(u)
if type(u) is str: return u
for enc in ('us-ascii','iso-8859-1','utf-8'):
try:
return u.encode(enc)