summaryrefslogtreecommitdiff
path: root/mail/src/leap
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2014-01-23 02:33:32 -0400
committerKali Kaneko <kali@leap.se>2014-01-28 19:38:44 -0400
commit06c9b95a4e92a7f43f1e91ffcb718aebfe9c3c7d (patch)
tree95f83975bec4278e5d36603edfb2f7980d2e9036 /mail/src/leap
parent02a9cd4d80b76e1bb1001de12eb7af7ae56155ed (diff)
move utilities
Diffstat (limited to 'mail/src/leap')
-rw-r--r--mail/src/leap/mail/utils.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/mail/src/leap/mail/utils.py b/mail/src/leap/mail/utils.py
index 6c79227f..64af04f9 100644
--- a/mail/src/leap/mail/utils.py
+++ b/mail/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