Server IP : 127.0.0.2 / Your IP : 3.145.71.192 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/lib/python2.7/dist-packages/ldap/ |
Upload File : |
""" This is a convenience wrapper for dictionaries returned from LDAP servers containing attribute names of variable case. See http://www.python-ldap.org/ for details. $Id: cidict.py,v 1.13 2009/04/17 14:34:34 stroeder Exp $ """ __version__ = """$Revision: 1.13 $""" from UserDict import UserDict from string import lower class cidict(UserDict): """ Case-insensitive but case-respecting dictionary. """ def __init__(self,default=None): self._keys = {} UserDict.__init__(self,{}) self.update(default or {}) def __getitem__(self,key): return self.data[lower(key)] def __setitem__(self,key,value): lower_key = lower(key) self._keys[lower_key] = key self.data[lower_key] = value def __delitem__(self,key): lower_key = lower(key) del self._keys[lower_key] del self.data[lower_key] def update(self,dict): for key in dict.keys(): self[key] = dict[key] def has_key(self,key): return UserDict.has_key(self,lower(key)) def __contains__(self,key): return self.has_key(key) def get(self,key,failobj=None): try: return self[key] except KeyError: return failobj def keys(self): return self._keys.values() def items(self): result = [] for k in self._keys.values(): result.append((k,self[k])) return result def strlist_minus(a,b): """ Return list of all items in a which are not in b (a - b). a,b are supposed to be lists of case-insensitive strings. """ temp = cidict() for elt in b: temp[elt] = elt result = [ elt for elt in a if not temp.has_key(elt) ] return result def strlist_intersection(a,b): """ Return intersection of two lists of case-insensitive strings a,b. """ temp = cidict() for elt in a: temp[elt] = elt result = [ temp[elt] for elt in b if temp.has_key(elt) ] return result def strlist_union(a,b): """ Return union of two lists of case-insensitive strings a,b. """ temp = cidict() for elt in a: temp[elt] = elt for elt in b: temp[elt] = elt return temp.values() if __debug__ and __name__ == '__main__': x = { 'AbCDeF' : 123 } cix = cidict(x) assert cix["ABCDEF"] == 123 assert cix.get("ABCDEF",None) == 123 assert cix.get("not existent",None) is None cix["xYZ"] = 987 assert cix["XyZ"] == 987 assert cix.get("XyZ",None) == 987 cix_keys = cix.keys() cix_keys.sort() assert cix_keys==['AbCDeF','xYZ'],ValueError(repr(cix_keys)) cix_items = cix.items() cix_items.sort() assert cix_items==[('AbCDeF',123),('xYZ',987)],ValueError(repr(cix_items)) del cix["abcdEF"] assert not cix._keys.has_key("abcdef") assert not cix.has_key("AbCDef")