本文整理汇总了Python中twisted.python.util.InsensitiveDict.keys方法的典型用法代码示例。如果您正苦于以下问题:Python InsensitiveDict.keys方法的具体用法?Python InsensitiveDict.keys怎么用?Python InsensitiveDict.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.util.InsensitiveDict
的用法示例。
在下文中一共展示了InsensitiveDict.keys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BaseLDAPEntry
# 需要导入模块: from twisted.python.util import InsensitiveDict [as 别名]
# 或者: from twisted.python.util.InsensitiveDict import keys [as 别名]
class BaseLDAPEntry(object):
implements(interfaces.ILDAPEntry)
dn = None
def __init__(self, dn, attributes={}):
"""
Initialize the object.
@param dn: Distinguished Name of the object, as a string.
@param attributes: Attributes of the object. A dictionary of
attribute types to list of attribute values.
"""
self._attributes=InsensitiveDict()
self.dn = distinguishedname.DistinguishedName(dn)
for k,vs in attributes.items():
if k not in self._attributes:
self._attributes[k] = []
self._attributes[k].extend(vs)
for k,vs in self._attributes.items():
self._attributes[k] = self.buildAttributeSet(k, vs)
def buildAttributeSet(self, key, values):
return attributeset.LDAPAttributeSet(key, values)
def __getitem__(self, key):
return self._attributes[key]
def get(self, key, default=None):
return self._attributes.get(key, default)
def has_key(self, key):
return key in self._attributes
def __contains__(self, key):
return self.has_key(key)
def keys(self):
a = []
if self.get('objectClass'):
a.append('objectClass')
l=list(self._attributes.keys())
l.sort()
for key in l:
if key.lower() != 'objectclass':
a.append(key)
return a
def items(self):
a=[]
objectClasses = list(self.get('objectClass', []))
objectClasses.sort()
if objectClasses:
a.append(('objectClass', objectClasses))
l=list(self._attributes.items())
l.sort()
for key, values in l:
if key.lower() != 'objectclass':
vs = list(values)
vs.sort()
a.append((key, vs))
return a
def __str__(self):
a=[]
objectClasses = list(self.get('objectClass', []))
objectClasses.sort()
a.append(('objectClass', objectClasses))
l=list(self.items())
l.sort()
for key, values in l:
if key.lower() != 'objectclass':
vs = list(values)
vs.sort()
a.append((key, vs))
return ldif.asLDIF(self.dn, a)
def __eq__(self, other):
if not isinstance(other, BaseLDAPEntry):
return 0
if self.dn != other.dn:
return 0
my=self.keys()
my.sort()
its=other.keys()
its.sort()
if my!=its:
return 0
for key in my:
myAttr=self[key]
itsAttr=other[key]
#.........这里部分代码省略.........
示例2: BaseLDAPEntry
# 需要导入模块: from twisted.python.util import InsensitiveDict [as 别名]
# 或者: from twisted.python.util.InsensitiveDict import keys [as 别名]
class BaseLDAPEntry(WireStrAlias):
dn = None
_object_class_keys = set(get_strings('objectClass'))
_object_class_lower_keys = set(get_strings('objectclass'))
_user_password_keys = set(get_strings('userPassword'))
def __init__(self, dn, attributes={}):
"""
Initialize the object.
@param dn: Distinguished Name of the object, as a string.
@param attributes: Attributes of the object. A dictionary of
attribute types to list of attribute values.
"""
self._attributes = InsensitiveDict()
self.dn = distinguishedname.DistinguishedName(dn)
for k, vs in attributes.items():
if k not in self._attributes:
self._attributes[k] = []
self._attributes[k].extend(vs)
for k, vs in self._attributes.items():
self._attributes[k] = self.buildAttributeSet(k, vs)
def buildAttributeSet(self, key, values):
return attributeset.LDAPAttributeSet(key, values)
def __getitem__(self, key):
for k in get_strings(key):
if k in self._attributes:
return self._attributes[k]
raise KeyError(key)
def get(self, key, default=None):
for k in get_strings(key):
if k in self._attributes:
return self._attributes[k]
return default
def has_key(self, key):
for k in get_strings(key):
if k in self._attributes:
return True
return False
def __contains__(self, key):
return self.has_key(key)
def __iter__(self):
for key in self._attributes.iterkeys():
yield key
def keys(self):
a = []
for key in self._object_class_keys:
if key in self._attributes:
a.append(key)
l = list(self._attributes.keys())
l.sort(key=to_bytes)
for key in l:
if key.lower() not in self._object_class_lower_keys:
a.append(key)
return a
def items(self):
a = []
for key in self._object_class_keys:
objectClasses = list(self._attributes.get(key, []))
objectClasses.sort(key=to_bytes)
if objectClasses:
a.append((key, objectClasses))
l = list(self._attributes.items())
l.sort(key=lambda x: to_bytes(x[0]))
for key, values in l:
if key.lower() not in self._object_class_lower_keys:
vs = list(values)
vs.sort()
a.append((key, vs))
return a
def toWire(self):
a = []
for key in self._object_class_keys:
objectClasses = list(self._attributes.get(key, []))
objectClasses.sort(key=to_bytes)
a.append((key, objectClasses))
items_gen = ((key, self[key]) for key in self)
items = sorted(items_gen, key=lambda x: to_bytes(x[0]))
for key, values in items:
if key.lower() not in self._object_class_lower_keys:
vs = list(values)
#.........这里部分代码省略.........