本文整理汇总了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",
)
示例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
示例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)