From 68e38391ea83c74cbd16f97005984f3599a19e45 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 17 Mar 2015 16:24:28 +0100 Subject: [PATCH 2/4] utils: add helper function to lowercase the keys of a dictionnary --- src/authentic2/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/authentic2/utils.py b/src/authentic2/utils.py index 3739703..e10a045 100644 --- a/src/authentic2/utils.py +++ b/src/authentic2/utils.py @@ -444,8 +444,12 @@ def csrf_token_check(request, form): def batch(iterable, size): '''Batch an iterable as an iterable of iterables of at most size element long. ''' sourceiter = iter(iterable) while True: batchiter = islice(sourceiter, size) yield chain([batchiter.next()], batchiter) + +def lower_keys(d): + '''Convert all keys in dictionary d to lowercase''' + return dict((key.lower(), value) for key, value in d.iteritems()) -- 1.9.1