|
|
- def rremove(origin, match):
- if origin.endswith(match):
- return origin[:-len(match)]
- return origin
-
- def ldap_path(entry, *arg):
- if arg:
- return "%s,%s"%(ldap_path(entry), ldap_path(arg))
- else:
- if type(entry) == tuple:
- return ldap_path(*entry)
- if entry.find(',') != -1:
- print(entry)
- raise Exception('Warning: ldap query injection detected')
- return entry
-
- def clean_user_name(user_name):
- return clean_value(rremove(user_name, '@lilik.it'))
-
- def clean_value(value):
- '''
- TODO:
- search_filter: the filter of the search request. It must conform to the LDAP
- filter syntax specified in RFC4515. If the search filter contains the
- following characters you must use the relevant escape ASCII sequence, as per
- RFC4515 (section 3):
- ‘*’ -> ‘\\2A’, ‘(‘ -> ‘\\28’, ‘)’ -> ‘\\29’, ‘\’ -> ‘\\5C’, chr(0) -> ‘\\00’.
- '''
- return value
-
- class DictDiffer(object):
- """
- Calculate the difference between two dictionaries as:
- (1) items added
- (2) items removed
- (3) keys same in both but changed values
- (4) keys same in both and unchanged values
- """
- def __init__(self, current_dict, past_dict):
- self.current_dict, self.past_dict = current_dict, past_dict
- self.set_current, self.set_past = set(current_dict.keys()), set(past_dict.keys())
- self.intersect = self.set_current.intersection(self.set_past)
- def added(self):
- return self.set_current - self.intersect
- def removed(self):
- return self.set_past - self.intersect
- def changed(self):
- return set(o for o in self.intersect if self.past_dict[o] != self.current_dict[o])
- def unchanged(self):
- return set(o for o in self.intersect if self.past_dict[o] == self.current_dict[o])
|