本文整理汇总了Python中twisted.words.protocols.jabber.jid.JID.full方法的典型用法代码示例。如果您正苦于以下问题:Python JID.full方法的具体用法?Python JID.full怎么用?Python JID.full使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.words.protocols.jabber.jid.JID
的用法示例。
在下文中一共展示了JID.full方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onIq
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [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: sendMessage
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [as 别名]
def sendMessage(self, recipient: JID, sender: JID, text: str, messageType: str = "chat"):
el = Element((None, "message"))
el.attributes["to"] = recipient.full()
el.attributes["from"] = sender.full()
el.attributes["type"] = messageType
body = el.addElement("body")
body.addContent(escape(text))
self.send(el)
示例3: get_forward_jids
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [as 别名]
def get_forward_jids(self, stanza):
entity_from = JID(stanza["from"])
entity_to = JID(stanza["to"])
if entity_from.userhost() == self.jid_proxy_to:
new_jid_to = self.untranslate_jid(entity_to.full())
new_jid_from = self.jid_act_as
else:
new_jid_to = self.jid_proxy_to
new_jid_from = self.translate_jid(entity_from.full())
return new_jid_to, new_jid_from
示例4: __getVersion
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [as 别名]
def __getVersion(self, sender: JID, recipient: JID, identifier: str):
iq = Element((None, "iq"))
iq.attributes["type"] = "result"
iq.attributes["from"] = recipient.full()
iq.attributes["to"] = sender.full()
if identifier:
iq.attributes["id"] = identifier
query = iq.addElement("query")
query.attributes["xmlns"] = "jabber:iq:version"
query.addElement("name", content="h2x transport")
query.addElement("version", content=0)
self.h2x.send(iq)
示例5: componentIq
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [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",
)
示例6: __getDiscoInfo
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [as 别名]
def __getDiscoInfo(self, sender: JID, identifier: str, node: str):
iq = Element((None, "iq"))
iq.attributes["type"] = "result"
iq.attributes["from"] = self.h2x.config.JID
iq.attributes["to"] = sender.full()
if identifier:
iq.attributes["id"] = identifier
query = iq.addElement("query")
query.attributes["xmlns"] = "http://jabber.org/protocol/disco#info"
# Node not set -> send component identity
if node == None:
identity = query.addElement("identity")
identity.attributes["name"] = "Google Hangouts transport"
identity.attributes["category"] = "gateway"
identity.attributes["type"] = "XMPP"
query.addElement("feature").attributes["var"] = "jabber:iq:gateway"
query.addElement("feature").attributes["var"] = "jabber:iq:register"
query.addElement("feature").attributes["var"] = "jabber:iq:version"
# Generic features for both node and component
query.addElement("feature").attributes["var"] = "http://jabber.org/protocol/commands"
query.addElement("feature").attributes["var"] = "http://jabber.org/protocol/disco#items"
query.addElement("feature").attributes["var"] = "http://jabber.org/protocol/disco#info"
self.h2x.send(iq)
示例7: JID2Hang
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [as 别名]
def JID2Hang(self, jid: JID):
if not self.h2x.isHangUser(jid):
raise Exception(jid.full() + " is not valid user JID for the transport")
userIdParts = jid.user.split(".")
userChatId = userIdParts[0]
userGaiaId = userIdParts[1]
return hangups.user.UserID(userChatId, userGaiaId)
示例8: get_user
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [as 别名]
def get_user(self, msg, session):
jid = JID(msg["from"])
try:
rv = models.User.by_jid(jid.userhost(), session)
except:
print "Getting user without the jid in the DB (%s)" % jid.full()
rv = models.User.update_status(jid.userhost(), None, session)
self.subscribe(jid)
return rv
示例9: __call__
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [as 别名]
def __call__(self, user, prot, args):
# For bare jids, we'll send what was requested,
# but also look up the user and send it to any active resources
self.ping(prot, user.jid, args)
j = JID(args)
if j.user and not j.resource:
for rsrc in scheduling.resources(args):
j.resource=rsrc
self.ping(prot, user.jid, j.full())
示例10: get_user
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [as 别名]
def get_user(self, msg, session):
jid = JID(msg['from'])
try:
user = models.User.by_jid(jid.userhost(), session)
except:
log.msg("Getting user without the jid in the DB (%s)" % jid.full())
user = models.User.update_status(jid.userhost(), None, session)
self.subscribe(jid)
return user;
示例11: __setRegister
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [as 别名]
def __setRegister(self, data: Element, sender: JID, identifier: str):
try:
user = sender.userhost()
token = data.firstChildElement().firstChildElement().firstChildElement().firstChildElement().__str__()
except Exception as e:
# Fail registration
print("Register reponse processing failed: " + e.__str__())
# FIXME: Send negative response here !!!
self.__sendIqResult(sender.full(), self.h2x.config.JID, identifier, "jabber:iq:register")
return
self.h2x.registerUser(user, token)
# Send registration done
self.__sendIqResult(sender.full(), self.h2x.config.JID, identifier, "jabber:iq:register")
# Request subscription
self.h2x.sendPresence(sender, "subscribe")
示例12: sendPresence
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [as 别名]
def sendPresence(self, destination: JID, presenceType: str, status: str = None, show: str = None,
priority: int = None, source: JID = None, nick: str = None):
if not source:
source = JID(self.config.JID)
presence = Element((None, 'presence'))
presence.attributes['to'] = destination.userhost()
presence.attributes['from'] = source.userhost()
presence.attributes['type'] = presenceType
if status:
presence.addElement('status').addContent(status)
if show:
presence.addElement('show').addContent(show)
if priority:
presence.addElement('priority').addContent(priority)
if nick:
nickElement = presence.addElement('nick', content=nick)
nickElement.attributes["xmlns"] = "http://jabber.org/protocol/nick"
print("PresenceSend: " + source.full() + " -> " + destination.full() + " : " + presenceType)
self.send(presence)
示例13: __getVCard
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [as 别名]
def __getVCard(self, sender: JID, recipient: JID, identifier):
iq = Element((None, "iq"))
iq.attributes["type"] = "result"
iq.attributes["from"] = recipient.full()
iq.attributes["to"] = sender.full()
if identifier:
iq.attributes["id"] = identifier
vcard = iq.addElement("vCard")
vcard.attributes["xmlns"] = "vcard-temp"
userInfo = self.h2x.getClient(sender).getUser(recipient)
# TODO: Get more user info
vcard.addElement("FN", content=userInfo.full_name)
vcard.addElement("NICKNAME", content=userInfo.full_name)
emails = vcard.addElement("EMAIL")
for email in userInfo.emails:
emails.addElement("USERID", content=email)
self.h2x.send(iq)
示例14: onPresence
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [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)
示例15: forward_presence
# 需要导入模块: from twisted.words.protocols.jabber.jid import JID [as 别名]
# 或者: from twisted.words.protocols.jabber.jid.JID import full [as 别名]
def forward_presence(self, presence):
type = presence.getAttribute("type", "available")
if type == "error":
return
entity_from = JID(presence["from"])
entity_to = JID(presence["to"])
new_jid_to, new_jid_from = self.get_forward_jids(presence)
presence["to"] = new_jid_to
presence["from"] = new_jid_from
self.send(presence)
if type == "subscribed":
log.msg("Subscribed from %s" % entity_from.userhost())
self.probe(entity_from.full(), entity_to.full())
if type == "available" and entity_from.userhost() != self.jid_proxy_to:
log.msg("Available from %s" % entity_from.full())
self.probe(self.jid_proxy_to, new_jid_from)