diff options
author | pacien <pacien.trangirard@pacien.net> | 2019-08-20 08:45:27 +0200 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2019-11-23 20:05:13 +0000 |
commit | 50c0b5ed7a3c23eb17fcbda3fc6151691311502a (patch) | |
tree | 1001b9792e279f7bd3147263ab4a23af56181899 /alot/utils | |
parent | 45829f7956716638fe77989a50eb87d3ea34cace (diff) |
commands/envelope: keep editable headers order
Use the ordered set of header keys from the settings or from the current
envelope when generating an editable envelope.
Fixes https://github.com/pazz/alot/issues/898:
Message header ordering isn't preserved from the editor
Note: collections.OrderedDict has been used for backward compatibility with
Python <3.7.
Diffstat (limited to 'alot/utils')
-rw-r--r-- | alot/utils/collections.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/alot/utils/collections.py b/alot/utils/collections.py new file mode 100644 index 00000000..acde56ce --- /dev/null +++ b/alot/utils/collections.py @@ -0,0 +1,29 @@ +# This file is released under the GNU GPL, version 3 or a later revision. +# For further details see the COPYING file + +from collections.abc import Set + +# for backward compatibility with Python <3.7 +from collections import OrderedDict + + +class OrderedSet(Set): + """ + Ordered collection of distinct hashable objects. + Taken from https://stackoverflow.com/a/10006674 + """ + + def __init__(self, iterable=()): + self.d = OrderedDict.fromkeys(iterable) + + def __len__(self): + return len(self.d) + + def __contains__(self, element): + return element in self.d + + def __iter__(self): + return iter(self.d) + + def __repr__(self): + return str(list(self)) |