本文整理汇总了Python中twisted.python.util.InsensitiveDict.items方法的典型用法代码示例。如果您正苦于以下问题:Python InsensitiveDict.items方法的具体用法?Python InsensitiveDict.items怎么用?Python InsensitiveDict.items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.util.InsensitiveDict
的用法示例。
在下文中一共展示了InsensitiveDict.items方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Element
# 需要导入模块: from twisted.python.util import InsensitiveDict [as 别名]
# 或者: from twisted.python.util.InsensitiveDict import items [as 别名]
class Element(Node):
preserveCase = 0
caseInsensitive = 1
nsprefixes = None
namespace = ''
def __init__(self, tagName, attributes=None, parentNode=None,
filename=None, markpos=None,
caseInsensitive=1, preserveCase=0,
namespace=''):
Node.__init__(self, parentNode)
self.preserveCase = preserveCase or not caseInsensitive
self.caseInsensitive = caseInsensitive
if not preserveCase:
tagName = tagName.lower()
if attributes is None:
self.attributes = {}
else:
self.attributes = attributes
for k, v in self.attributes.items():
self.attributes[k] = unescape(v)
if caseInsensitive:
self.attributes = InsensitiveDict(self.attributes,
preserve=preserveCase)
self.endTagName = self.nodeName = self.tagName = tagName
self._filename = filename
self._markpos = markpos
self.namespace = namespace
def addPrefixes(self, pfxs):
if self.nsprefixes is None:
self.nsprefixes = pfxs
else:
self.nsprefixes.update(pfxs)
def endTag(self, endTagName):
if not self.preserveCase:
endTagName = endTagName.lower()
self.endTagName = endTagName
def isEqualToElement(self, n):
if self.caseInsensitive:
return (self.attributes == n.attributes) and (self.nodeName.lower() == n.nodeName.lower())
return (self.attributes == n.attributes) and (self.nodeName == n.nodeName)
def cloneNode(self, deep=0, parent=None):
clone = Element(
self.tagName, parentNode=parent, namespace=self.namespace,
preserveCase=self.preserveCase, caseInsensitive=self.caseInsensitive)
clone.attributes.update(self.attributes)
if deep:
clone.childNodes = [child.cloneNode(1, clone) for child in self.childNodes]
else:
clone.childNodes = []
return clone
def getElementsByTagName(self, name):
if self.caseInsensitive:
return getElementsByTagNameNoCase(self, name)
return getElementsByTagName(self, name)
def hasAttributes(self):
return 1
def getAttribute(self, name, default=None):
return self.attributes.get(name, default)
def getAttributeNS(self, ns, name, default=None):
nsk = (ns, name)
if self.attributes.has_key(nsk):
return self.attributes[nsk]
if ns == self.namespace:
return self.attributes.get(name, default)
return default
def getAttributeNode(self, name):
return _Attr(self.getAttribute(name), self)
def setAttribute(self, name, attr):
self.attributes[name] = attr
def removeAttribute(self, name):
if name in self.attributes:
del self.attributes[name]
def removeAttribute_has_key(self, name):
if self.attributes.has_key(name):
del self.attributes[name]
def hasAttribute(self, name):
return name in self.attributes
def hasAttribute_has_key(self, name):
return self.attributes.has_key(name)
if dictsAreNotSequences:
hasAttribute = hasAttribute_has_key
#.........这里部分代码省略.........
示例2: Element
# 需要导入模块: from twisted.python.util import InsensitiveDict [as 别名]
# 或者: from twisted.python.util.InsensitiveDict import items [as 别名]
class Element(Node):
preserveCase = 0
caseInsensitive = 1
nsprefixes = None
def __init__(self, tagName, attributes=None, parentNode=None,
filename=None, markpos=None,
caseInsensitive=1, preserveCase=0,
namespace=None):
Node.__init__(self, parentNode)
self.preserveCase = preserveCase or not caseInsensitive
self.caseInsensitive = caseInsensitive
if not preserveCase:
tagName = tagName.lower()
if attributes is None:
self.attributes = {}
else:
self.attributes = attributes
for k, v in self.attributes.items():
self.attributes[k] = unescape(v)
if caseInsensitive:
self.attributes = InsensitiveDict(self.attributes,
preserve=preserveCase)
self.endTagName = self.nodeName = self.tagName = tagName
self._filename = filename
self._markpos = markpos
self.namespace = namespace
def addPrefixes(self, pfxs):
if self.nsprefixes is None:
self.nsprefixes = pfxs
else:
self.nsprefixes.update(pfxs)
def endTag(self, endTagName):
if not self.preserveCase:
endTagName = endTagName.lower()
self.endTagName = endTagName
def isEqualToElement(self, n):
if self.caseInsensitive:
return ((self.attributes == n.attributes)
and (self.nodeName.lower() == n.nodeName.lower()))
return (self.attributes == n.attributes) and (self.nodeName == n.nodeName)
def isEqualToNode(self, other):
"""
Compare this element to C{other}. If the C{nodeName}, C{namespace},
C{attributes}, and C{childNodes} are all the same, return C{True},
otherwise return C{False}.
"""
return (
self.nodeName.lower() == other.nodeName.lower() and
self.namespace == other.namespace and
self.attributes == other.attributes and
Node.isEqualToNode(self, other))
def cloneNode(self, deep=0, parent=None):
clone = Element(
self.tagName, parentNode=parent, namespace=self.namespace,
preserveCase=self.preserveCase, caseInsensitive=self.caseInsensitive)
clone.attributes.update(self.attributes)
if deep:
clone.childNodes = [child.cloneNode(1, clone) for child in self.childNodes]
else:
clone.childNodes = []
return clone
def getElementsByTagName(self, name):
if self.caseInsensitive:
return getElementsByTagNameNoCase(self, name)
return getElementsByTagName(self, name)
def hasAttributes(self):
return 1
def getAttribute(self, name, default=None):
return self.attributes.get(name, default)
def getAttributeNS(self, ns, name, default=None):
nsk = (ns, name)
if self.attributes.has_key(nsk):
return self.attributes[nsk]
if ns == self.namespace:
return self.attributes.get(name, default)
return default
def getAttributeNode(self, name):
return _Attr(self.getAttribute(name), self)
def setAttribute(self, name, attr):
self.attributes[name] = attr
def removeAttribute(self, name):
if name in self.attributes:
#.........这里部分代码省略.........
示例3: Element
# 需要导入模块: from twisted.python.util import InsensitiveDict [as 别名]
# 或者: from twisted.python.util.InsensitiveDict import items [as 别名]
#.........这里部分代码省略.........
return getElementsByTagName(self.childNodes, name, icase)
def hasAttributes(self):
return 1
def getAttribute(self, name, default=None):
return self.attributes.get(name, default)
def getAttributeNS(self, ns, name, default=None):
nsk = (ns, name)
if nsk in self.attributes:
return self.attributes[nsk]
if ns == self.namespace:
return self.attributes.get(name, default)
return default
def getAttributeNode(self, name):
return _Attr(self.getAttribute(name), self)
def setAttribute(self, name, attr):
self.attributes[name] = attr
def removeAttribute(self, name):
if name in self.attributes:
del self.attributes[name]
def hasAttribute(self, name):
return name in self.attributes
def gen_prefixes(self, nsprefixes):
for k, v in self.nsprefixes.items():
if k not in nsprefixes:
yield (k, v)
def _writexml(self, namespace, nsprefixes, newl, indent):
newprefixes = dict(self.gen_prefixes(nsprefixes))
begin = [newl, indent, '<'] if self.tag_is_blockelement else ['<']
is_same_namespace = self.namespace and namespace == self.namespace
# Make a local for tracking what end tag will be used. If namespace
# prefixes are involved, this will be changed to account for that
# before it's actually used.
endTagName = self.endTagName
if not is_same_namespace and self.namespace in nsprefixes:
# This tag's namespace already has a prefix bound to it. Use
# that prefix.
prefix = nsprefixes[self.namespace]
begin.extend(prefix + ':' + self.tagName)
# Also make sure we use it for the end tag.
endTagName = prefix + ':' + self.endTagName
elif not is_same_namespace:
# This tag's namespace has no prefix bound to it. Change the
# default namespace to this tag's namespace so we don't need
# prefixes. Alternatively, we could add a new prefix binding.
# I'm not sure why the code was written one way rather than the
# other. -exarkun
begin.extend(self.tagName)
begin.extend(self.create_attr("xmlns", self.namespace))
# The default namespace just changed. Make sure any children
# know about this.
示例4: BaseLDAPEntry
# 需要导入模块: from twisted.python.util import InsensitiveDict [as 别名]
# 或者: from twisted.python.util.InsensitiveDict import items [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]
#.........这里部分代码省略.........
示例5: IRCBot
# 需要导入模块: from twisted.python.util import InsensitiveDict [as 别名]
# 或者: from twisted.python.util.InsensitiveDict import items [as 别名]
#.........这里部分代码省略.........
cert = self.transport.getPeerCertificate()
fp = cert.digest("sha1")
verified = "verified" if self.factory.parent.server_fingerprint else "unverified"
print("irc: connected securely. server fingerprint: {0} ({1})".format(fp, verified))
else:
print("irc: connected")
if self.ns_username and self.ns_password and not self.sasl_login:
self.msg('NickServ', 'IDENTIFY {0} {1}'.format(self.ns_username, self.ns_password))
for channel in self.join_channels:
self.join(channel)
def irc_JOIN(self, prefix, params):
nick = prefix.split('!')[0]
channel = params[-1]
if nick == self.nickname:
self.joined(channel)
else:
self.userJoined(prefix, channel)
def joined(self, channel):
print('irc: joined channel')
self.factory.client = self
def who():
self.sendLine("WHO " + channel)
task.LoopingCall(who).start(30)
def isupport(self, args):
self.compute_prefix_names()
def compute_prefix_names(self):
KNOWN_NAMES = {"o": "op", "h": "halfop", "v": "voice"}
prefixdata = self.supported.getFeature("PREFIX", {"o": ("@", 0), "v": ("+", 1)}).items()
op_priority = ([priority for mode, (prefix, priority) in prefixdata if mode == "o"] + [None])[0]
self.prefixes, self.statuses, self.priority = {}, {}, {}
for mode, (prefix, priority) in prefixdata:
name = "?"
if mode in KNOWN_NAMES:
name = KNOWN_NAMES[mode]
elif priority == 0:
if op_priority == 2:
name = "owner"
else:
name = "admin"
else:
name = "+" + mode
self.prefixes[mode] = prefix
self.statuses[prefix] = name
self.priority[name] = priority
self.priority[mode] = priority
self.priority[prefix] = priority
def parse_prefixes(self, user, nick, prefixes=''):
status = []
prefixdata = self.supported.getFeature("PREFIX", {"o": ("@", 0), "v": ("+", 1)}).items()
for mode, (prefix, priority) in prefixdata:
if prefix in prefixes + nick:
nick = nick.replace(prefix, '')
status.append((prefix, priority))
if nick == self.nickname:
return
user.status = ''.join(t[0] for t in sorted(status, key=lambda t: t[1]))
def irc_RPL_WHOREPLY(self, prefix, params):
示例6: BaseLDAPEntry
# 需要导入模块: from twisted.python.util import InsensitiveDict [as 别名]
# 或者: from twisted.python.util.InsensitiveDict import items [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)
#.........这里部分代码省略.........