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


Python Element.getAttribute方法代码示例

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


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

示例1: onIq

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import getAttribute [as 别名]
    def onIq(self, element: Element):
        source = JID(element.getAttribute("from"))
        recipient = JID(element.getAttribute("to"))
        identification = element.getAttribute("id")
        iqType = element.getAttribute("type")

        print("IqReceived " + source.full() + " -> " + recipient.full() + ": " + iqType)

        # Process component iq
        if recipient.full() == self.h2x.config.JID:
            self.componentIq(element, source, identification, iqType)
            return

            # Process user iq
        if self.h2x.isHangUser(recipient):
            self.userIq(element, source, recipient, identification, iqType)
            return

            # TODO: Can we send something like wrong request?
        self.__sendIqError(
            recipient=source.full(),
            sender=recipient.full(),
            identification=identification,
            errorType="cancel",
            condition="service-unavailable",
        )
开发者ID:vladamatena,项目名称:h2x,代码行数:28,代码来源:iq.py

示例2: onMessage

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import getAttribute [as 别名]
	def onMessage(self, element: Element):
		msgType = element.getAttribute("type")
		recipient = JID(element.getAttribute("to"))
		sender = JID(element.getAttribute("from"))
		text = element.firstChildElement().__str__()

		if msgType == "chat":
			self.getClient(sender).sendMessage(recipient, text)
		else:
			raise NotImplementedError
开发者ID:vladamatena,项目名称:h2x,代码行数:12,代码来源:h2x.py

示例3: onPresence

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import getAttribute [as 别名]
	def onPresence(self, element: Element):
		sender = JID(element.getAttribute("from"))
		recipient = JID(element.getAttribute("to"))
		presenceType = element.getAttribute("type")
		if not presenceType:
			presenceType = "available"

		print("PresenceReceived: " + sender.full() + " -> " + recipient.full() + " : " + presenceType)

		# Create client instance on available from XMPP client
		if self.getClient(sender) is None:
			if presenceType == "available":
				try:
					self.addClient(ClientWrapper(self, sender))
				except UserNotRegistered as e:
					print(e)
					self.sendPresenceError(recipient=sender, sender=recipient, errorType="auth",
										   condition="registration-required")
					return
			else:
				print("Operation on client which has not yet send available presence !!! (responding as if we are not available)")
				self.sendPresence(sender, "unavailable")
				return

		# Service component presence
		if recipient == JID(self.config.JID):
			self.getClient(sender).processComponentPresence(sender, presenceType, recipient)

		# Subscription request
		elif presenceType == "subscribe":
			self.getClient(sender).processSubscription(recipient)

		# Presence to Hangouts user
		elif self.isHangUser(recipient):
			self.getClient(sender).processPresence(recipient, presenceType)

		# Unimplemented feature
		else:
			raise NotImplemented(element)
开发者ID:vladamatena,项目名称:h2x,代码行数:41,代码来源:h2x.py


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