Skip to content

Commit d3deaff

Browse files
committed
flake8 fixes - use None as sentinel
Changed two methods: nosymessage send_message that used def X( ... cc=[] ...) mutable args. Changed them to use None as sentinel and added code to set the values appropriately when sentinel seen. Plus other flake8 fixes.
1 parent d50166e commit d3deaff

File tree

1 file changed

+56
-41
lines changed

1 file changed

+56
-41
lines changed

roundup/roundupdb.py

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,29 @@
2020
"""
2121
__docformat__ = 'restructuredtext'
2222

23-
import time
24-
import base64, mimetypes
23+
import base64
2524
import logging
25+
import mimetypes
26+
import time
27+
2628
from email import encoders
27-
from email.parser import FeedParser
28-
from email.utils import formataddr
2929
from email.header import Header
30-
from email.mime.text import MIMEText
3130
from email.mime.base import MIMEBase
3231
from email.mime.multipart import MIMEMultipart
32+
from email.mime.text import MIMEText
33+
from email.parser import FeedParser
34+
from email.utils import formataddr
3335

34-
from roundup import password, date, hyperdb
35-
from roundup.i18n import _
36-
from roundup.hyperdb import iter_roles
37-
38-
from roundup.mailer import Mailer, MessageSendError, nice_sender_header
39-
from roundup.i18n import RoundupNullTranslations
36+
import roundup.anypy.random_ as random_
4037

38+
from roundup import date, hyperdb, password
4139
from roundup.anypy.strings import b2s, s2u
42-
import roundup.anypy.random_ as random_
40+
from roundup.hyperdb import iter_roles
41+
from roundup.i18n import _, RoundupNullTranslations
42+
from roundup.mailer import Mailer, MessageSendError, nice_sender_header
4343

4444
try:
45-
import gpg, gpg.core
45+
import gpg, gpg.core # noqa: E401
4646
except ImportError:
4747
gpg = None
4848

@@ -242,9 +242,10 @@ def addmessage(self, issueid, summary, text):
242242
"""
243243

244244
def nosymessage(self, issueid, msgid, oldvalues, whichnosy='nosy',
245-
from_address=None, cc=[], bcc=[], cc_emails=[],
246-
bcc_emails=[], subject=None,
247-
note_filter=None, add_headers={}):
245+
from_address=None, cc=None, bcc=None,
246+
cc_emails=None,
247+
bcc_emails=None, subject=None,
248+
note_filter=None, add_headers=None):
248249
"""Send a message to the members of an issue's nosy list.
249250
250251
The message is sent only to users on the nosy list who are not
@@ -294,6 +295,13 @@ def nosymessage(self, issueid, msgid, oldvalues, whichnosy='nosy',
294295
The add_headers parameter allows to set additional headers for
295296
the outgoing email.
296297
"""
298+
299+
if cc is None: cc = [] # noqa: E701
300+
if bcc is None: bcc = [] # noqa: E701
301+
if cc_emails is None: cc_emails = [] # noqa: E701
302+
if bcc_emails is None: bcc_emails = [] # noqa: E701
303+
if add_headers is None: add_headers = {} # noqa: E701
304+
297305
encrypt = self.db.config.PGP_ENABLE and self.db.config.PGP_ENCRYPT
298306
pgproles = self.db.config.PGP_ROLES
299307
if msgid:
@@ -315,7 +323,8 @@ def add_recipient(userid, to):
315323
address = self.db.user.get(userid, 'address')
316324
if address:
317325
ciphered = encrypt and (not pgproles or
318-
self.db.user.has_role(userid, *iter_roles(pgproles)))
326+
self.db.user.has_role(
327+
userid, *iter_roles(pgproles)))
319328
type = ['plain', 'crypt'][ciphered]
320329
to[type].append(address)
321330
recipients.append(userid)
@@ -429,12 +438,15 @@ def encrypt_to(self, message, sendto):
429438
return msg
430439

431440
def send_message(self, issueid, msgid, note, sendto, from_address=None,
432-
bcc_sendto=[], subject=None, crypt=False,
433-
add_headers={}, authid=None):
441+
bcc_sendto=None, subject=None, crypt=False,
442+
add_headers=None, authid=None):
434443
'''Actually send the nominated message from this issue to the sendto
435444
recipients, with the note appended. It's possible to add
436445
headers to the message with the add_headers variable.
437446
'''
447+
448+
if bcc_sendto is None: bcc_sendto = [] # noqa: E701
449+
if add_headers is None: add_headers = {} # noqa: E701
438450
users = self.db.user
439451
messages = self.db.msg
440452
files = self.db.file
@@ -450,7 +462,8 @@ def send_message(self, issueid, msgid, note, sendto, from_address=None,
450462
if not messageid:
451463
# this is an old message that didn't get a messageid, so
452464
# create one
453-
messageid = "<%s.%s.%s%s@%s>" % (time.time(),
465+
messageid = "<%s.%s.%s%s@%s>" % (
466+
time.time(),
454467
b2s(base64.b32encode(random_.token_bytes(10))),
455468
self.classname, issueid, self.db.config['MAIL_DOMAIN'])
456469
if msgid is not None:
@@ -577,8 +590,10 @@ def send_message(self, issueid, msgid, note, sendto, from_address=None,
577590
# note that authaddr at this point is already
578591
# surrounded by < >, so get the original address
579592
# from the db as nice_send_header adds < >
580-
replyto_addr = nice_sender_header(authname,
581-
users.get(authid, 'address', ''), charset)
593+
replyto_addr = nice_sender_header(
594+
authname,
595+
users.get(authid, 'address', ''),
596+
charset)
582597
else:
583598
replyto_addr = replyto_config
584599
else:
@@ -739,7 +754,8 @@ def email_signature(self, issueid, msgid):
739754
# then append a trailing slash if it is missing
740755
base = self.db.config.TRACKER_WEB
741756
if (not isinstance(base, type('')) or
742-
not (base.startswith('http://') or base.startswith('https://'))):
757+
not (base.startswith('http://') or
758+
base.startswith('https://'))):
743759
web = "Configuration Error: TRACKER_WEB isn't a " \
744760
"fully-qualified URL"
745761
else:
@@ -781,8 +797,7 @@ def generateCreateNote(self, issueid):
781797
else:
782798
value = ''
783799
elif isinstance(prop, hyperdb.Multilink):
784-
if value is None: value = []
785-
l = []
800+
if value is None: value = [] # noqa: E701
786801
link = self.db.classes[prop.classname]
787802
key = link.labelprop(default_to_id=1)
788803
if key:
@@ -858,32 +873,32 @@ def generateChangeNote(self, issueid, oldvalues):
858873
change = '%s -> %s' % (oldvalue, value)
859874
elif isinstance(prop, hyperdb.Multilink):
860875
change = ''
861-
if value is None: value = []
862-
if oldvalue is None: oldvalue = []
863-
l = []
876+
if value is None: value = [] # noqa: E701
877+
if oldvalue is None: oldvalue = [] # noqa: E701
878+
changed_links = []
864879
link = self.db.classes[prop.classname]
865880
key = link.labelprop(default_to_id=1)
866881
# check for additions
867882
for entry in value:
868-
if entry in oldvalue: continue
883+
if entry in oldvalue: continue # noqa: E701
869884
if key:
870-
l.append(link.get(entry, key))
885+
changed_links.append(link.get(entry, key))
871886
else:
872-
l.append(entry)
873-
if l:
874-
l.sort()
875-
change = '+%s' % (', '.join(l))
876-
l = []
887+
changed_links.append(entry)
888+
if changed_links:
889+
changed_links.sort()
890+
change = '+%s' % (', '.join(changed_links))
891+
changed_links = []
877892
# check for removals
878893
for entry in oldvalue:
879-
if entry in value: continue
894+
if entry in value: continue # noqa: E701
880895
if key:
881-
l.append(link.get(entry, key))
896+
changed_links.append(link.get(entry, key))
882897
else:
883-
l.append(entry)
884-
if l:
885-
l.sort()
886-
change += ' -%s' % (', '.join(l))
898+
changed_links.append(entry)
899+
if changed_links:
900+
changed_links.sort()
901+
change += ' -%s' % (', '.join(changed_links))
887902
else:
888903
change = '%s -> %s' % (oldvalue, value)
889904
if '\n' in change:

0 commit comments

Comments
 (0)