diff options
author | Tomás Touceda <chiiph@leap.se> | 2014-06-27 12:47:57 -0300 |
---|---|---|
committer | Tomás Touceda <chiiph@leap.se> | 2014-06-27 12:47:57 -0300 |
commit | 7858d83af4a09ab00f6ba33dd8dbcf07ade101ce (patch) | |
tree | 334e519a4d341c402b5fa81d339b9b1d2b5ead35 /src/leap/bitmask/util/__init__.py | |
parent | c621fa7322b4f8151eb37b27f8aeae563cf6bd63 (diff) | |
parent | 7de085576dd6141a5303aa1e1460c2a208d7b5d4 (diff) |
Merge branch 'release-0.5.3'0.5.3
Diffstat (limited to 'src/leap/bitmask/util/__init__.py')
-rw-r--r-- | src/leap/bitmask/util/__init__.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/leap/bitmask/util/__init__.py b/src/leap/bitmask/util/__init__.py index c35be99e..25b86874 100644 --- a/src/leap/bitmask/util/__init__.py +++ b/src/leap/bitmask/util/__init__.py @@ -110,3 +110,22 @@ def make_address(user, provider): :type provider: basestring """ return "%s@%s" % (user, provider) + + +def force_eval(items): + """ + Return a sequence that evaluates any callable in the sequence, + instantiating it beforehand if the item is a class, and + leaves the non-callable items without change. + """ + def do_eval(thing): + if isinstance(thing, type): + return thing()() + if callable(thing): + return thing() + return thing + + if isinstance(items, (list, tuple)): + return map(do_eval, items) + else: + return do_eval(items) |