summaryrefslogtreecommitdiff
path: root/alot
Commit message (Collapse)AuthorAge
* Dirty fix for case-(in)sensitive MIME matching.Pol Van Aubel2016-12-26
| | | | | Simply cast every string to lower() when matching MIME media type and subtype. Matching is always case-insensitive as per RFC2045, 5.1.
* Use abc module to signal abstract base classesDylan Baker2016-12-21
| | | | | | | | | | | | | The Completer class is abastract, and it's complete method is also abstract. Using ABCMeta achieve two thing, first it will cause an error if a developer doesn't overwrite the method in a subclass. And second that it tells the static analysis tools to ignore the unused arguments in the signature, since this is the definition of a signature, not an actual function. By the same logic addressbook.AddressBook, and account.Account have been extended to use ABCMeta as their metaclass and have had their abstract methods decorated with the abstract method attribute.
* Replace unused arguments with _Dylan Baker2016-12-21
| | | | | | | | | | This patch replaces a large number (but not all) unused arguments with the standard ``_`` placeholder. This has the advantage of signaling that these values are unused. There are a number of places that I've chosen not to apply this, largely in methods that have publicly define signatures that they inherit (usually from urwid).
* Don't use dict.keys when not necessaryDylan Baker2016-12-21
| | | | | | | | | | | It's pretty easy to get caught up using dict.keys (or iterkeys) when one doesn't need to. This patch corrects two cases where it's not needed, the first is the case of inclusion. ``x in mydict.keys()`` is equivalent to ``x in mydict``, but without the need to generate a list and walk it. The second case is when calling set() on a dict, ``set(mydict)`` will create a set object of the dict's keys, without the need to create one in memory and is significantly faster than ``set(mydict.keys())`` or even ``set(mydict.iterkeys())``.
* ui: Don't build lists in memory for assertDylan Baker2016-12-21
| | | | | | This patch changes an assertion to avoid building a list in memory by using dict.keys() and then concatenating it (building a second list in memory). This is both faster and uses less memory.
* settings/manager: remove list comprehension for clarityDylan Baker2016-12-21
| | | | | | | The use of a list comprehension here saves one line of code, but doesn't make the code clearer, a simple loop is more obvious. This also replaces ``if not v or v == ''`` with simply ``if not v``, since they're equivalent.
* Use dict's iter methodsDylan Baker2016-12-21
| | | | | | | | This patch replaces a number of uses of dict.items, dict.values, and dict.keys with their iterative siblings. The advantage of using the iterator version is that they don't copy the keys, values, or items, but simply return references. This reduces memory usage and may speed up the these operations a bit.
* widgets/search: make method that doesn't use self a static methodDylan Baker2016-12-21
|
* db/thread: Set some protected variables in the constructor.Dylan Baker2016-12-21
|
* db/thread: Avoid intermediate data structureDylan Baker2016-12-21
| | | | | | This patch removes the need to create an intermediate dictionary while calculating the authors of a thread, it does so by working directly with the _authors list.
* db/thread: don't create multiple lists to sortDylan Baker2016-12-21
| | | | | | | | | | | | | | | Currently this function takes a list, splits into two lists based on whether or not a function returns None, sorts the list that isn't None, and then appends the list of None to the end. This creates 4 new concrete lists on each method call, requires the use of 3 filter + lambda pairs, and calls list.sort(). Pretty complicated and inefficient. This patch replaces that with a single sorted() function call with a kay function that replaces None with a value that is guaranteed to sort less than what Message.get_date() will return, but will not cause a comparison to None (which is an error in Python 3.x). This is all based on iterators and avoids the need for filter or list concatenation. This should result in only one new list being created.
* Define instance attribute in constructor.Dylan Baker2016-12-21
|
* Replace map() and filter() with comprehensionsDylan Baker2016-12-21
| | | | | | | | This had the advantage of being more readable to people without a functional programming background, and it avoids the need to use lambdas which are both slow and have many corners in python. In a few cases it also allows us to use a generator expression instead of a materialized list, which save some memory.
* Fix "superflous paren" warnings from pylintDylan Baker2016-12-21
| | | | | | | | | In alot/helper.py this is a fairly obvious change. In alot/buffers.py I've taken the liberty of replacing a somewhat odd use of multiplication that relies on the bool class (True and False) implementing an __int__ method. These are used to add the 's' to the end of 'message' if there are more than one message (thus messages), this is much clearer (and more correct) when implemented as a ternary instead.
* Use raw strings with backslashesDylan Baker2016-12-21
| | | | This just adds the `r` prefix to a few strings.
* Fix values to methods in __main__Dylan Baker2016-12-21
| | | | | several of these don't take a self argument. In one case self is needed, in the others decorating them as static methods fixes the behavior.
* tests: Add tests for alot.db.thread.Thread.get_authorDylan Baker2016-12-21
|
* db/thread: define Thread._authors in constructorDylan Baker2016-12-21
| | | | This is needed by unittest that mock Thread.refresh.
* Drop little used helperDylan Baker2016-12-19
| | | | | | | | The safely_get helper is just a wrapper around try/except, and is used twice in the whole code base, in the same function. It really doesn't even end up saving code because to get around line wrapping a lambda is assigned (which is not the greatest style wise), it ends up saving one line of code when it's called, and the function itself is 16 lines long.
* Turn methods with no `self` usage into staticmethodsLucas Hoffmann2016-12-18
|
* Merge pull request #929 from lucc/with-block-temp-filesPatrick Totzke2016-12-18
|\ | | | | Use with blocks to write to temp files
| * Use with blocks to write to temp filesLucas Hoffmann2016-12-18
| |
* | Turn method into static methodLucas Hoffmann2016-12-17
| |
* | Remove redundant None argument in dict.get()Lucas Hoffmann2016-12-17
| |
* | Simplify arithmetic comparisonLucas Hoffmann2016-12-17
|/
* fix interpolation in config files #902.Patrick Totzke2016-12-16
| | | | | | | | | Configobj's string interpolation feature does not work as expected in account sections of alot configuration files. The reason is that interpolation is done in ConfigObj.__getitem__ which alot does not use directly for account sections. This patch causes all values to be read via ConfigObj.__getitem__ explicitly.
* Merge pull request #885 from lucc/historyPatrick Totzke2016-12-15
|\ | | | | Save command line history across sessions
| * Fix typo in commentLucas Hoffmann2016-12-15
| |
| * Address comments by @dcbakerLucas Hoffmann2016-12-15
| |
| * Expand history concept for sender and recipient of mailLucas Hoffmann2016-12-14
| |
| * Add history_size optionLucas Hoffmann2016-12-14
| | | | | | | | | | The option allows to limit the size of recent command line entries that are store on disk.
| * Save and load command history across invocationsLucas Hoffmann2016-12-14
| | | | | | | | | | | | Initialize the command history with lines from ${XDG_CACHE_HOME:-~/.cache}/alot at startup. Write the current history to the file again during shutdown.
* | use open as a context manager instead of oneline open().read()Dylan Baker2016-12-14
| | | | | | | | | | | | | | | | While open().read() is nice for its terseness it has the problem that it causes an fd to leak until the gc collects it. For short lived scripts this isn't a big deal, but for a program like alot that run for long periods of time it's better to be correct and ensure that the fd is closed.
* | use open() as context managerDylan Baker2016-12-14
| | | | | | | | | | | | | | | | | | | | This uses open() as a context manager instead of calling close() explicitly. This has the advantage of closing even in the event of an exception, being easier to visually inspect for correctness, and being the more modern idiom. This does leave one case of file.close(), where FILE is opened in an if tree.
* | Merge pull request #920 from lucc/pylintDylan Baker2016-12-14
|\ \ | |/ |/| Small fixes found with pylint
| * Turn alot.errors.GPGCode into a new style classLucas Hoffmann2016-12-14
| |
| * Use native logging string interpolationLucas Hoffmann2016-12-14
| | | | | | | | This will also make the string interpolation lazy evaluated.
| * Fix import to be compatible with python 2.7 and 3Lucas Hoffmann2016-12-14
| | | | | | | | The lower case version is available since 2.5.
| * Remove an unused variableLucas Hoffmann2016-12-14
| |
* | Fix typo in docstringLucas Hoffmann2016-12-14
|/
* Don't pass None as second argument of dict.get()Dylan Baker2016-12-13
| | | | This is the default value.
* Don't materialize with any()Dylan Baker2016-12-13
| | | | | It's more efficient to use a generator here than a list comprehension, since then we can avoid calculating addresses we don't need.
* Use tuple for isinstance instead of multiple calls to isinstanceDylan Baker2016-12-13
|
* Replace list comprehension with set comprehensionDylan Baker2016-12-13
| | | | | | | Instead of using set([l for l in list]) use {l for l in list} (which shouldn't be confused with a dict comprehension which requires the ':' in the first value}. This avoids creating a list before reducing it to a set. This feature is new in 2.7 and 3.3.
* Replace mutable keyword argumentsDylan Baker2016-12-13
| | | | | | | | | | | | | | | | | | | | | | | There are a number of cases of mutable keyword arguments (list and dict in this case). Mutable keyword arguments are rather dangerous, since any mutation of the default value is persistent, which will inevitably lead to bugs. For example, imagine this code: def func(def=[]): def.append('foo') return def >>> func() ['foo'] >>> func() ['foo', 'foo'] This is almost certainly not what was intended. This code generally uses the idiom of setting the default value to None, and then assigning with or `value = value or []` which will replace value with the empty list (or dict) when value is falsey, like None or another empty list.
* settings/manager.py: Compare addresses using == instead of inDylan Baker2016-12-13
| | | | | | | I don't think this was correct from the start, since "foo@bar.com" would match "bfoo@bar.com", even if there was a "bfoo@bar.com" in the accountmap, depending on the order that they happened to be sorted in accountmap.
* Remove trailing whitespace from inline docsLucas Hoffmann2016-12-11
| | | | It would otherwise be picked up by the autogenerated docs.
* Remove trailing white spaceLucas Hoffmann2016-12-11
|
* Further minor style fixesLucas Hoffmann2016-12-09
|
* Fix except syntaxLucas Hoffmann2016-12-09
|