Projet

Général

Profil

0003-utils-add-a-helper-function-to-convert-a-dictionnary.patch

Benjamin Dauvergne, 23 mars 2015 16:28

Télécharger (1,05 ko)

Voir les différences:

Subject: [PATCH 3/4] utils: add a helper function to convert a dictionnary of
 list into a dictionnary of sets

It helps for comparing dictionnaries of values, for example with LDAP.
 src/authentic2/utils.py | 4 ++++
 1 file changed, 4 insertions(+)
src/authentic2/utils.py
448 448
    sourceiter = iter(iterable)
449 449
    while True:
450 450
        batchiter = islice(sourceiter, size)
451 451
        yield chain([batchiter.next()], batchiter)
452 452

  
453 453
def lower_keys(d):
454 454
    '''Convert all keys in dictionary d to lowercase'''
455 455
    return dict((key.lower(), value) for key, value in d.iteritems())
456

  
457
def to_dict_of_set(d):
458
    '''Convert a dictionary of sequence into a dictionary of sets'''
459
    return dict((k, set(v)) for k, v in d.iteritems())
456
-