当前位置: 首页>>代码示例>>Python>>正文


Python Element.elements方法代码示例

本文整理汇总了Python中twisted.words.xish.domish.Element.elements方法的典型用法代码示例。如果您正苦于以下问题:Python Element.elements方法的具体用法?Python Element.elements怎么用?Python Element.elements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.words.xish.domish.Element的用法示例。


在下文中一共展示了Element.elements方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: removeListEntry

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import elements [as 别名]
	def removeListEntry(self, type, jabberID, legacyID):
		""" Removes a legacy ID entry from a list in
		the XDB, based off the type and jabberID you provide. """
		if type != "roster": return
		xdbns = XDBNS_PREFIX+type
		list = self.request(jabberID, xdbns)
		if list == None:
			list = Element((None, "aimtrans"))
			list.attributes["xmlns"] = xdbns

		buddies = None
		for child in list.elements():
			try:
				if child.name == "buddies":
					buddies = child
					break
			except AttributeError:
				continue

		if buddies == None:
			buddies = list.addElement("buddies")

		# Remove the existing element
		for child in buddies.elements():
			try:
				if child.getAttribute("name") == legacyID:
					buddies.children.remove(child)
			except AttributeError:
				continue

		self.set(jabberID, xdbns, list)
开发者ID:Ashaman-,项目名称:pyaimt,代码行数:33,代码来源:legacyaimtransport.py

示例2: sendErrorMessage

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import elements [as 别名]
def sendErrorMessage(pytrans, to, fro, etype, condition, explanation, body=None, el=None):
    if el is None:
        el = Element((None, "message"))
    el.attributes["to"] = to
    el.attributes["from"] = fro
    el.attributes["type"] = "error"
    error = el.addElement("error")
    error.attributes["type"] = etype
    error.attributes["code"] = str(utils.errorCodeMap[condition])
    if condition:
        desc = error.addElement(condition)
        desc.attributes["xmlns"] = globals.XMPP_STANZAS
    text = error.addElement("text")
    text.attributes["xmlns"] = globals.XMPP_STANZAS
    text.addContent(explanation)

    bodywritten = False  # no <body/> in message
    for child in el.elements():  # try find in el
        if child.name == 'body':  # <body/> already in el
            if body and len(body) > 0:  # necessary add other info to it
                body_txt = child.__str__()
                child.addContent(body_txt + '\n' + body)
            bodywritten = True
    if not bodywritten and body and len(body) > 0:  # <body/> in el don't found
        b = el.addElement('body')
        b.addContent(body)
    pytrans.send(el)
开发者ID:2mf,项目名称:pyicqt,代码行数:29,代码来源:jabw.py

示例3: componentIq

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import elements [as 别名]
    def componentIq(self, element: Element, sender: JID, identifier: str, iqType: str):
        for query in element.elements():
            xmlns = query.uri
            node = query.getAttribute("node")

            if xmlns == "http://jabber.org/protocol/disco#info" and iqType == "get":
                self.__getDiscoInfo(sender, identifier, node)
                return

            if xmlns == "http://jabber.org/protocol/disco#items" and iqType == "get":
                self.__getDiscoItems(sender, identifier, node)
                return

            if xmlns == "jabber:iq:register" and iqType == "get":
                self.__getRegister(sender, identifier)
                return

            if xmlns == "jabber:iq:register" and iqType == "set":
                self.__setRegister(element, sender, identifier)
                return

            if xmlns == "http://jabber.org/protocol/commands" and query.name == "command" and iqType == "set":
                self.__command(query, sender, identifier, node)
                return

            self.__sendIqError(
                recipient=sender.full(),
                sender=self.h2x.config.JID,
                identification=identifier,
                errorType="cancel",
                condition="feature-not-implemented",
            )
开发者ID:vladamatena,项目名称:h2x,代码行数:34,代码来源:iq.py

示例4: setSetting

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import elements [as 别名]
	def setSetting(self, jabberID, variable, value):
		""" Sets a user setting in the XDB. """
		prefs = self.request(jabberID, XDBNS_PREFERENCES)
		if prefs == None:
			prefs = Element((None, "query"))
			prefs.attributes["xmlns"] = XDBNS_PREFERENCES

		# Remove the existing element
		for child in prefs.elements():
			if child.name == variable:
				prefs.children.remove(child)

		newpref = prefs.addElement(variable)
		newpref.addContent(value)

		self.set(jabberID, XDBNS_PREFERENCES, prefs)
开发者ID:Ashaman-,项目名称:pyaimt,代码行数:18,代码来源:xmlfiles.py

示例5: removeListEntry

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import elements [as 别名]
	def removeListEntry(self, type, jabberID, legacyID):
		""" Removes a legacy ID entry from a list in
		the XDB, based off the type and jabberID you provide. """
		xdbns = XDBNS_PREFIX+type
		list = self.request(jabberID, xdbns)
		if list == None:
			list = Element((None, "query"))
			list.attributes["xmlns"] = xdbns

		# Remove the element
		for child in list.elements():
			try:
				if child.getAttribute("jid") == legacyID:
					list.children.remove(child)
			except AttributeError:
				continue

		self.set(jabberID, xdbns, list)
开发者ID:Ashaman-,项目名称:pyaimt,代码行数:20,代码来源:xmlfiles.py

示例6: setCSetting

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import elements [as 别名]
	def setCSetting(self, jabberID, variable, value):
		""" Sets a custom user setting in the XDB. """
		# TODO: may be merge with setSetting? It more safe way for storing in XML as I think
		prefs = self.request(jabberID, XDBNS_CSETTINGS)
		if prefs == None:
			prefs = Element((None, "query"))
			prefs.attributes["xmlns"] = XDBNS_CSETTINGS

		# Remove the existing element
		for child in prefs.elements():
			if child.name == 'item' and child.getAttribute('variable') == str(variable):
				prefs.children.remove(child)

		newpref = prefs.addElement('item')
		newpref.attributes['variable'] = str(variable)
		newpref.addContent(value)

		self.set(jabberID, XDBNS_CSETTINGS, prefs)
开发者ID:anton-ryzhov,项目名称:pyicqt_auto_reconnect,代码行数:20,代码来源:xmlfiles.py

示例7: userIq

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import elements [as 别名]
    def userIq(self, element: Element, sender: JID, recipient: JID, identifier: str, iqType: str):
        for query in element.elements():
            xmlns = query.uri
            node = query.getAttribute("node")

            if xmlns == "jabber:iq:version" and iqType == "get":
                self.__getVersion(sender, recipient, identifier)
                return

            if xmlns == "vcard-temp" and iqType == "get" and query.name == "vCard":
                self.__getVCard(sender, recipient, identifier)
                return

            self.__sendIqError(
                recipient=sender.full(),
                sender=self.h2x.config.JID,
                identification=identifier,
                errorType="cancel",
                condition="feature-not-implemented",
            )
开发者ID:vladamatena,项目名称:h2x,代码行数:22,代码来源:iq.py

示例8: set

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import elements [as 别名]
	def set(self, file, xdbns, element):
		""" Sets a specific xdb namespace in the XDB 'file' to element """
		try:
			element.attributes["xdbns"] = xdbns
			document = None
			try:
				document = self.__getFile(file)
			except IOError:
				pass
			if not document:
				document = Element((None, "xdb"))
			
			# Remove the existing node (if any)
			for child in document.elements():
				if child.getAttribute("xdbns") == xdbns:
					document.children.remove(child)
			# Add the new one
			document.addChild(element)
			
			self.__writeFile(file, document.toXml())
		except:
			LogEvent(INFO, msg="XDB error writing entry %s to file %s" % (xdbns, file))
			raise
开发者ID:fritteli,项目名称:pyicqt,代码行数:25,代码来源:legacyjittransport.py

示例9: setListEntry

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import elements [as 别名]
	def setListEntry(self, type, jabberID, legacyID, payload = {}):
		""" Updates or adds a legacy ID entry to a list in
		the XDB, based off the type and jabberID you provide. """
		xdbns = XDBNS_PREFIX+type
		list = self.request(jabberID, xdbns)
		if list == None:
			list = Element((None, "query"))
			list.attributes["xmlns"] = xdbns

		# Remove the existing element
		for child in list.elements():
			try:
				if child.getAttribute("jid") == legacyID:
					list.children.remove(child)
			except AttributeError:
				continue

		newentry = list.addElement("item")
		newentry["jid"] = legacyID
		for p in payload.keys():
			newentry[p] = payload[p]

		self.set(jabberID, xdbns, list)
开发者ID:Ashaman-,项目名称:pyaimt,代码行数:25,代码来源:xmlfiles.py

示例10: setXstatusText

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import elements [as 别名]
    def setXstatusText(self, jabberID, number, title, desc):
        """ Sets a latest title and desc for x-status with specific number """
        xstatuses = self.request(jabberID, XDBNS_XSTATUSES)
        if xstatuses == None:
            xstatuses = Element((None, "query"))
            xstatuses.attributes["xmlns"] = XDBNS_XSTATUSES

        # Remove the existing element
        for child in xstatuses.elements():
            if child.name == 'item' and child.getAttribute('number') == str(number):
                xstatuses.children.remove(child)

        xstatus = xstatuses.addElement('item')
        xstatus.attributes['number'] = str(number)
        if title:
            xstatus.attributes['title'] = str(title)
        else:
            xstatus.attributes['title'] = ''
        if desc:
            xstatus.addContent(str(desc))
        else:
            xstatus.addContent('')

        self.set(jabberID, XDBNS_XSTATUSES, xstatuses)
开发者ID:2mf,项目名称:pyicqt,代码行数:26,代码来源:xmlfiles.py


注:本文中的twisted.words.xish.domish.Element.elements方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。