Skip to content

Commit f3f35f4

Browse files
hannobgordonmessmer
authored andcommitted
Fix various codingstyle issues
1 parent 84d6b4c commit f3f35f4

14 files changed

Lines changed: 42 additions & 35 deletions

courier/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def get_alias(address):
279279
def smtpaccess(ip):
280280
""" Return the courier smtpaccess value associated with the IP address."""
281281
# First break the IP address into parts, either IPv4 or IPv6
282-
if '.' in ip:
282+
if '.' in ip:
283283
ipsep = '.'
284284
elif ':' in ip:
285285
ipsep = ':'
@@ -376,6 +376,8 @@ def get_block_val(ip):
376376

377377
_standard_config_paths = ['/etc/pythonfilter-modules.conf',
378378
'/usr/local/etc/pythonfilter-modules.conf']
379+
380+
379381
def get_module_config(module_name):
380382
"""Return a dictionary of config values.
381383

courier/control.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _get_recipients_from_file(control_path):
129129
130130
"""
131131
recipients = []
132-
rbuf = ['', '', ''] # This list will contain the recipient data.
132+
rbuf = ['', '', ''] # This list will contain the recipient data.
133133
with open(control_path, 'rb') as control_file:
134134
for control_line in control_file:
135135
control_key = control_line[:1]
@@ -256,7 +256,7 @@ def add_recipient_data(control_paths, recipient_data):
256256
def _mark_complete(control_path, recipient_index):
257257
"""Mark a single recipient's delivery as completed."""
258258
with open(control_path, 'a') as control_file:
259-
control_file.seek(0, 2) # Seek to the end of the file
259+
control_file.seek(0, 2) # Seek to the end of the file
260260
control_file.write('I%d R 250 Ok - Removed by courier.control.py\n' %
261261
recipient_index)
262262
control_file.write('S%d %d\n' % (recipient_index, int(time.time())))
@@ -279,8 +279,8 @@ def del_recipient(control_paths, recipient):
279279
for control_path in control_paths:
280280
rcpts = _get_recipients_from_file(control_path)
281281
for rcpt in rcpts:
282-
if(rcpt[1] is False # Delivery is not complete for this recipient
283-
and rcpt[2][0] == recipient):
282+
if (rcpt[1] is False # Delivery is not complete for this recipient
283+
and rcpt[2][0] == recipient):
284284
_mark_complete(control_path, rcpt[0])
285285
return
286286

@@ -305,8 +305,8 @@ def del_recipient_data(control_paths, recipient_data):
305305
for cf in control_paths:
306306
rcpts = _get_recipients_from_file(cf)
307307
for x in rcpts:
308-
if(x[1] is False # Delivery is not complete for this recipient
309-
and x[2] == recipient_data):
308+
if (x[1] is False # Delivery is not complete for this recipient
309+
and x[2] == recipient_data):
310310
_mark_complete(cf, x[0])
311311
return
312312

@@ -327,6 +327,7 @@ def get_auth_user(control_paths, body_file=None):
327327
return auth_lines[0]
328328
return None
329329

330+
330331
# Deprecated names preserved for compatibility with older releases
331332
getLines = get_lines
332333
getSendersMta = get_senders_mta

courier/quarantine.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _get_db():
5151
lock = open(lockpath, 'w')
5252
fcntl.flock(lock, fcntl.LOCK_EX)
5353
dbm_file = dbm.open(dbmpath, 'c')
54-
return(dbm_file, lock)
54+
return (dbm_file, lock)
5555

5656

5757
def _close_db(dbm_file, lock):
@@ -72,8 +72,8 @@ def send_notice(message, address, sender=None):
7272
# Send the recipient a notice if notify_recipient isn't
7373
# available, or if it is present and a true value.
7474
rcpts = []
75-
if('notify_recipient' not in config
76-
or config['notify_recipient']):
75+
if ('notify_recipient' not in config
76+
or config['notify_recipient']):
7777
rcpts.append(address)
7878
if 'also_notify' in config and config['also_notify']:
7979
rcpts.append(config['also_notify'])
@@ -122,10 +122,10 @@ def quarantine(body_path, control_paths, explanation):
122122
# Prepare notice for recipients of quarantined message
123123
# Some sites would prefer that only admins release messages from the
124124
# quarantine.
125-
if('user_release' in config
126-
and config['user_release'] == 0
127-
and 'also_notify' in config
128-
and config['also_notify']):
125+
if ('user_release' in config
126+
and config['user_release'] == 0
127+
and 'also_notify' in config
128+
and config['also_notify']):
129129
release_addr = config['also_notify']
130130
else:
131131
release_addr = 'quarantine-%s-%s@%s' % (config['siteid'],
@@ -139,7 +139,7 @@ def quarantine(body_path, control_paths, explanation):
139139
qmessage = email.message_from_binary_file(body_file)
140140
except Exception as e:
141141
# TODO: Handle this error.
142-
raise #InitError('Internal failure parsing message data file: %s' % str(e))
142+
raise # InitError('Internal failure parsing message data file: %s' % str(e))
143143
qmessage_sender = qmessage['from']
144144
qmessage_subject = qmessage['subject']
145145
message = """You received a message that was quarantined because:
@@ -188,9 +188,9 @@ def release(requested_id, address):
188188
send_failure_notice(requested_id, address)
189189
return
190190
for x in courier.control.get_control_data(quarantine_paths[1])['r']:
191-
if(x[0] == address or
192-
x[1] == address or
193-
x[1] == '%s%s' % ('rfc822;', address)):
191+
if (x[0] == address or
192+
x[1] == address or
193+
x[1] == '%s%s' % ('rfc822;', address)):
194194
courier.sendmail.sendmail('', address, open(quarantine_paths[0], 'rb').readlines())
195195
return
196196
# If no address matched, alert the user that the request was invalid.
@@ -219,6 +219,7 @@ def purge():
219219
# Unlock the DB
220220
_close_db(dbm_file, lock)
221221

222+
222223
# Deprecated names preserved for compatibility with older releases
223224
sendNotice = send_notice
224225
sendFailureNotice = send_failure_notice

courier/sendmail.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import subprocess
2020
import courier.config
2121

22+
2223
def sendmail(from_addr, to_addrs, msg):
2324
"""Send a message using Courier's sendmail application.
2425

filters/pythonfilter/attachments.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def check_archive(filename, part):
6464
os.rmdir(tmp_d)
6565
return found
6666

67+
6768
def do_filter(body_path, control_paths):
6869
try:
6970
with open(body_path, 'rb') as body_file:

filters/pythonfilter/auto_whitelist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def check_whitelist(control_paths):
7474
correspondents = hashlib.md5(recipient.lower().encode())
7575
correspondents.update(sender.encode())
7676
cdigest = correspondents.hexdigest()
77-
if not cdigest in _whitelist:
77+
if cdigest not in _whitelist:
7878
found_all = 0
7979
break
8080
finally:

filters/pythonfilter/comeagain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def do_filter(body_path, control_paths):
8484
correspondents = sender_md5.copy()
8585
correspondents.update(recipient.encode())
8686
cdigest = correspondents.hexdigest()
87-
if not cdigest in _senders:
87+
if cdigest not in _senders:
8888
found_all = 0
8989
_senders[cdigest] = time.time()
9090
finally:

filters/pythonfilter/deliveredto.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def do_filter(body_path, control_paths):
4444
dparts = dheader.split('@')
4545
if len(dparts) != 2:
4646
return ''
47-
if(courier.config.is_local(dparts[1]) or
48-
courier.config.is_hosteddomain(dparts[1])):
47+
if (courier.config.is_local(dparts[1]) or
48+
courier.config.is_hosteddomain(dparts[1])):
4949
return '501 Mail loop - already have my Delivered-To: header.'
5050
return ''
5151

filters/pythonfilter/localsenders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def do_filter(body_path, control_paths):
5252

5353
if sender_info is None:
5454
return '517 Sender does not exist: %s' % sender
55-
if(require_auth and
56-
courier.control.get_auth_user(control_paths, body_path) is None):
55+
if (require_auth and
56+
courier.control.get_auth_user(control_paths, body_path) is None):
5757
return '517 Policy requires local senders to authenticate.'
5858
return ''
5959

filters/pythonfilter/ratelimit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# individual address.
3939
limit_network = False
4040

41+
4142
def init_filter():
4243
courier.config.apply_module_config('ratelimit.py', globals())
4344

0 commit comments

Comments
 (0)