Skip to content

Commit

Permalink
Merge pull request #918 from dcbaker/pr/misc-cleanups
Browse files Browse the repository at this point in the history
misc cleanups
  • Loading branch information
dcbaker committed Dec 14, 2016
2 parents 16b3dd2 + d3aa06f commit 9574b0b
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 38 deletions.
11 changes: 9 additions & 2 deletions alot/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ class Account(object):
def __init__(self, address=None, aliases=None, alias_regexp=None,
realname=None, gpg_key=None, signature=None,
signature_filename=None, signature_as_attachment=False,
sent_box=None, sent_tags=['sent'], draft_box=None,
draft_tags=['draft'], abook=None, sign_by_default=False,
sent_box=None, sent_tags=None, draft_box=None,
draft_tags=None, abook=None, sign_by_default=False,
encrypt_by_default=u"none",
**rest):
sent_tags = sent_tags or []
if 'sent' not in sent_tags:
sent_tags.append('sent')
draft_tags = draft_tags or []
if 'draft' not in draft_tags:
draft_tags.append('draft')

self.address = address
self.aliases = aliases
self.alias_regexp = alias_regexp
Expand Down
4 changes: 2 additions & 2 deletions alot/buffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,10 +618,10 @@ class TagListBuffer(Buffer):

modename = 'taglist'

def __init__(self, ui, alltags=[], filtfun=None):
def __init__(self, ui, alltags=None, filtfun=None):
self.filtfun = filtfun
self.ui = ui
self.tags = alltags
self.tags = alltags or []
self.isinitialized = False
self.rebuild()
Buffer.__init__(self, ui, self.body)
Expand Down
6 changes: 3 additions & 3 deletions alot/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class SaveAttachmentCommand(Command):
"""
def __init__(self, mode, name, help=None, usage=None,
forced={}, arguments=[]):
forced=None, arguments=None):
"""
:param mode: mode identifier
:type mode: str
Expand All @@ -133,8 +133,8 @@ def __init__(self, mode, name, help=None, usage=None,
self.name = name
self.help = help
self.usage = usage
self.forced = forced
self.arguments = arguments
self.forced = forced or {}
self.arguments = arguments or []

def __call__(self, klass):
helpstring = self.help or klass.__doc__
Expand Down
18 changes: 9 additions & 9 deletions alot/commands/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,10 @@ def apply(self, ui):
class ComposeCommand(Command):

"""compose a new email"""
def __init__(self, envelope=None, headers={}, template=None,
sender=u'', subject=u'', to=[], cc=[], bcc=[], attach=None,
omit_signature=False, spawn=None, rest=[],
encrypt=False, **kwargs):
def __init__(self, envelope=None, headers=None, template=None, sender=u'',
subject=u'', to=None, cc=None, bcc=None, attach=None,
omit_signature=False, spawn=None, rest=None, encrypt=False,
**kwargs):
"""
:param envelope: use existing envelope
:type envelope: :class:`~alot.db.envelope.Envelope`
Expand Down Expand Up @@ -688,16 +688,16 @@ def __init__(self, envelope=None, headers={}, template=None,

self.envelope = envelope
self.template = template
self.headers = headers
self.headers = headers or {}
self.sender = sender
self.subject = subject
self.to = to
self.cc = cc
self.bcc = bcc
self.to = to or []
self.cc = cc or []
self.bcc = bcc or []
self.attach = attach
self.omit_signature = omit_signature
self.force_spawn = spawn
self.rest = ' '.join(rest)
self.rest = ' '.join(rest or [])
self.encrypt = encrypt

@inlineCallbacks
Expand Down
6 changes: 3 additions & 3 deletions alot/commands/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def apply(self, ui):
allrecipients = [to] + [cc]
lists = settings.get('mailinglists')
# check if any recipient address matches a known mailing list
if any([addr in lists for n, addr in getaddresses(allrecipients)]):
if any(addr in lists for n, addr in getaddresses(allrecipients)):
followupto = ', '.join(allrecipients)
logging.debug('mail followup to: %s', followupto)
envelope.add('Mail-Followup-To', decode_header(followupto))
Expand Down Expand Up @@ -965,8 +965,8 @@ def afterwards():
handler_cmdlist = split_commandstring(handler_cmd)

# 'needsterminal' makes handler overtake the terminal
nt = entry.get('needsterminal', None)
overtakes = (nt is None)
# XXX: could this be repalced with "'needsterminal' not in entry"?
overtakes = entry.get('needsterminal') is None

ui.apply_command(ExternalCommand(handler_cmdlist,
stdin=handler_stdin,
Expand Down
4 changes: 2 additions & 2 deletions alot/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ def complete(self, original, pos):
for optionstring in act.option_strings:
if optionstring.startswith(pref):
# append '=' for options that await a string value
if isinstance(act, argparse._StoreAction) or\
isinstance(act, BooleanAction):
if isinstance(
act, (argparse._StoreAction, BooleanAction)):
optionstring += '='
res.append(optionstring)

Expand Down
12 changes: 6 additions & 6 deletions alot/db/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class Envelope(object):
"""tags to add after successful sendout"""

def __init__(
self, template=None, bodytext=None, headers=None, attachments=[],
sign=False, sign_key=None, encrypt=False, tags=[]):
self, template=None, bodytext=None, headers=None, attachments=None,
sign=False, sign_key=None, encrypt=False, tags=None):
"""
:param template: if not None, the envelope will be initialised by
:meth:`parsing <parse_template>` this string before
Expand All @@ -71,12 +71,12 @@ def __init__(
logging.debug('BODY: %s', self.body)
self.body = bodytext or u''
self.headers = headers or {}
self.attachments = list(attachments)
self.attachments = list(attachments) if attachments is not None else []
self.sign = sign
self.sign_key = sign_key
self.encrypt = encrypt
self.encrypt_keys = {}
self.tags = tags # tags to add after successful sendout
self.tags = tags or [] # tags to add after successful sendout
self.sent_time = None
self.modified_since_sent = False
self.sending = False # semaphore to avoid accidental double sendout
Expand Down Expand Up @@ -121,12 +121,12 @@ def get(self, key, fallback=None):
value = fallback
return value

def get_all(self, key, fallback=[]):
def get_all(self, key, fallback=None):
"""returns all header values for given key"""
if key in self.headers:
value = self.headers[key]
else:
value = fallback
value = fallback or []
return value

def add(self, key, value):
Expand Down
4 changes: 3 additions & 1 deletion alot/db/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def query(self, querystring):
db = Database(path=self.path, mode=mode)
return db.create_query(querystring)

def add_message(self, path, tags=[], afterwards=None):
def add_message(self, path, tags=None, afterwards=None):
"""
Adds a file to the notmuch index.
Expand All @@ -409,6 +409,8 @@ def add_message(self, path, tags=[], afterwards=None):
:param afterwards: callback to trigger after adding
:type afterwards: callable or None
"""
tags = tags or []

if self.ro:
raise DatabaseROError()
if not is_subdir_of(path, self.path):
Expand Down
2 changes: 1 addition & 1 deletion alot/db/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def refresh(self, thread=None):
except ValueError: # year is out of range
self._newest_date = None

self._tags = set([t for t in thread.get_tags()])
self._tags = {t for t in thread.get_tags()}
self._messages = {} # this maps messages to its children
self._toplevel_messages = []

Expand Down
7 changes: 4 additions & 3 deletions alot/db/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def add_signature_headers(mail, sigs, error_msg):
)


def get_params(mail, failobj=list(), header='content-type', unquote=True):
def get_params(mail, failobj=None, header='content-type', unquote=True):
'''Get Content-Type parameters as dict.
RFC 2045 specifies that parameter names are case-insensitive, so
Expand All @@ -83,6 +83,7 @@ def get_params(mail, failobj=list(), header='content-type', unquote=True):
:param unquote: unquote the values
:returns: a `dict` containing the parameters
'''
failobj = failobj or []
return {k.lower(): v for k, v in mail.get_params(failobj, header, unquote)}


Expand Down Expand Up @@ -110,7 +111,7 @@ def message_from_file(handle):
# handle OpenPGP signed data
if (m.is_multipart() and
m.get_content_subtype() == 'signed' and
p.get('protocol', None) == app_pgp_sig):
p.get('protocol') == app_pgp_sig):
# RFC 3156 is quite strict:
# * exactly two messages
# * the second is of type 'application/pgp-signature'
Expand Down Expand Up @@ -146,7 +147,7 @@ def message_from_file(handle):
# handle OpenPGP encrypted data
elif (m.is_multipart() and
m.get_content_subtype() == 'encrypted' and
p.get('protocol', None) == app_pgp_enc and
p.get('protocol') == app_pgp_enc and
'Version: 1' in m.get_payload(0).get_payload()):
# RFC 3156 is quite strict:
# * exactly two messages
Expand Down
5 changes: 3 additions & 2 deletions alot/settings/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def get_account_by_address(self, address):
"""

for myad in self.get_addresses():
if myad in address:
if myad == address:
return self._accountmap[myad]
return None

Expand All @@ -415,8 +415,9 @@ def get_addresses(self):
"""returns addresses of known accounts including all their aliases"""
return self._accountmap.keys()

def get_addressbooks(self, order=[], append_remaining=True):
def get_addressbooks(self, order=None, append_remaining=True):
"""returns list of all defined :class:`AddressBook` objects"""
order = order or []
abooks = []
for a in order:
if a:
Expand Down
4 changes: 3 additions & 1 deletion alot/settings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .errors import ConfigError

def read_config(configpath=None, specpath=None, checks={}):
def read_config(configpath=None, specpath=None, checks=None):
"""
get a (validated) config object for given config file path.
Expand All @@ -21,6 +21,8 @@ def read_config(configpath=None, specpath=None, checks={}):
:raises: :class:`~alot.settings.errors.ConfigError`
:rtype: `configobj.ConfigObj`
"""
checks = checks or {}

try:
config = ConfigObj(infile=configpath, configspec=specpath,
file_error=True, encoding='UTF8')
Expand Down
9 changes: 6 additions & 3 deletions alot/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def show_as_root_until_keypress(self, w, key, afterwards=None):
self._unlock_callback = afterwards
self._locked = True

def prompt(self, prefix, text=u'', completer=None, tab=0, history=[]):
def prompt(self, prefix, text=u'', completer=None, tab=0, history=None):
"""
prompt for text input.
This returns a :class:`~twisted.defer.Deferred` that calls back with
Expand All @@ -260,6 +260,8 @@ def prompt(self, prefix, text=u'', completer=None, tab=0, history=[]):
:type history: list of str
:rtype: :class:`twisted.defer.Deferred`
"""
history = history or []

d = defer.Deferred() # create return deferred
oldroot = self.mainloop.widget

Expand Down Expand Up @@ -442,8 +444,8 @@ def clear_notify(self, messages):
self._notificationbar = None
self.update()

def choice(self, message, choices={'y': 'yes', 'n': 'no'},
select=None, cancel=None, msg_position='above'):
def choice(self, message, choices=None, select=None, cancel=None,
msg_position='above'):
"""
prompt user to make a choice.
Expand All @@ -462,6 +464,7 @@ def choice(self, message, choices={'y': 'yes', 'n': 'no'},
:type msg_position: str
:rtype: :class:`twisted.defer.Deferred`
"""
choices = choices or {'y': 'yes', 'n': 'no'}
assert select in choices.values() + [None]
assert cancel in choices.values() + [None]
assert msg_position in ['left', 'above']
Expand Down

0 comments on commit 9574b0b

Please sign in to comment.