diff options
author | Kali Kaneko <kali@leap.se> | 2014-01-23 02:33:32 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2014-01-28 19:38:44 -0400 |
commit | d7a167e1ba5ea9bb8167e6255a81d4c96fdffef9 (patch) | |
tree | a4da7bc61b85cea5f2365d276c2e40523d32da5d /src/leap/mail | |
parent | eaa4bcb241d5d55c4fd2458cb05c74fcdc79368c (diff) |
move utilities
Diffstat (limited to 'src/leap/mail')
-rw-r--r-- | src/leap/mail/utils.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/leap/mail/utils.py b/src/leap/mail/utils.py index 6c79227..64af04f 100644 --- a/src/leap/mail/utils.py +++ b/src/leap/mail/utils.py @@ -36,6 +36,14 @@ def first(things): return None +def maybe_call(thing): + """ + Return the same thing, or the result of its invocation if it is a + callable. + """ + return thing() if callable(thing) else thing + + def find_charset(thing, default=None): """ Looks into the object 'thing' for a charset specification. @@ -46,16 +54,28 @@ def find_charset(thing, default=None): :param default: the dafault charset to return if no charset is found. :type default: str - :returns: the charset or 'default' + :return: the charset or 'default' :rtype: str or None """ charset = first(CHARSET_RE.findall(repr(thing))) if charset is None: charset = default - return charset +def lowerdict(_dict): + """ + Return a dict with the keys in lowercase. + + :param _dict: the dict to convert + :rtype: dict + """ + # TODO should properly implement a CaseInsensitive dict. + # Look into requests code. + return dict((key.lower(), value) + for key, value in _dict.items()) + + class CustomJsonScanner(object): """ This class is a context manager definition used to monkey patch the default |