本文整理汇总了Python中Yowsup.ConnectionIO.protocoltreenode.ProtocolTreeNode类的典型用法代码示例。如果您正苦于以下问题:Python ProtocolTreeNode类的具体用法?Python ProtocolTreeNode怎么用?Python ProtocolTreeNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProtocolTreeNode类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parseGroupCreated
def parseGroupCreated(self,node):
jid = node.getAttributeValue("from");
groupNode = node.getChild(0)
if ProtocolTreeNode.tagEquals(groupNode,"error"):
errorCode = groupNode.getAttributeValue("code")
self.signalInterface.send("group_createFail", (errorCode,))
return
ProtocolTreeNode.require(groupNode,"group")
group_id = groupNode.getAttributeValue("id")
self.signalInterface.send("group_createSuccess", (group_id + "@g.us",))
示例2: readSuccess
def readSuccess(self):
node = self.conn.reader.nextTree();
self._d("Login Status: %s"%(node.tag));
if ProtocolTreeNode.tagEquals(node,"failure"):
self.authObject.authenticationFailed()
return 0
#raise Exception("Login Failure");
ProtocolTreeNode.require(node,"success");
expiration = node.getAttributeValue("expiration");
if expiration is not None:
self._d("Expires: "+str(expiration));
self.authObject.expireDate = expiration;
kind = node.getAttributeValue("kind");
self._d("Account type: %s"%(kind))
if kind == "paid":
self.authObject.accountKind = 1;
elif kind == "free":
self.authObject.accountKind = 0;
else:
self.authObject.accountKind = -1;
status = node.getAttributeValue("status");
self._d("Account status: %s"%(status));
if status == "expired":
self.loginFailed.emit()
raise Exception("Account expired on "+str(self.authObject.expireDate));
if status == "active":
if expiration is None:
#raise Exception ("active account with no expiration");
'''@@TODO expiration changed to creation'''
else:
self.authObject.accountKind = 1;
self.conn.reader.inn.buf = [];
nextChallenge = node.data;
f = open("/home/user/.wazapp/challenge", "wb")
f.write(nextChallenge)
f.close()
self.conn.writer.outputKey = self.outputKey
self.authObject.authenticationComplete()
return 1
示例3: parseGroupInfo
def parseGroupInfo(self,node):
jid = node.getAttributeValue("from");
groupNode = node.getChild(0)
if "error code" in groupNode.toString():
self.signalInterface.send("group_infoError",(0,)) #@@TODO replace with real error code
else:
ProtocolTreeNode.require(groupNode,"group")
#gid = groupNode.getAttributeValue("id")
owner = groupNode.getAttributeValue("owner")
subject = groupNode.getAttributeValue("subject") if sys.version_info < (3, 0) else groupNode.getAttributeValue("subject").encode('latin-1').decode();
subjectT = groupNode.getAttributeValue("s_t")
subjectOwner = groupNode.getAttributeValue("s_o")
creation = groupNode.getAttributeValue("creation")
self.signalInterface.send("group_gotInfo",(jid, owner, subject, subjectOwner, int(subjectT),int(creation)))
示例4: readFeaturesAndChallenge
def readFeaturesAndChallenge(self):
root = self.conn.reader.nextTree();
while root is not None:
if ProtocolTreeNode.tagEquals(root,"stream:features"):
self._d("GOT FEATURES !!!!");
self.authObject.supportsReceiptAcks = root.getChild("receipt_acks") is not None;
root = self.conn.reader.nextTree();
continue;
if ProtocolTreeNode.tagEquals(root,"challenge"):
self._d("GOT CHALLENGE !!!!");
#data = base64.b64decode(root.data);
return root.data;
raise Exception("fell out of loop in readFeaturesAndChallenge");
示例5: parseLastOnline
def parseLastOnline(self,node):
jid = node.getAttributeValue("from");
firstChild = node.getChild(0);
if "error" in firstChild.toString():
return
ProtocolTreeNode.require(firstChild,"query");
seconds = firstChild.getAttributeValue("seconds");
status = None
status = firstChild.data #@@TODO discarded?
try:
if seconds is not None and jid is not None:
self.signalInterface.send("presence_updated", (jid, int(seconds)))
except:
self._d("Ignored exception in handleLastOnline "+ sys.exc_info()[1])
示例6: run
def run(self):
self._d("Read thread startedX");
while True:
countdown = self.timeout - ((int(time.time()) - self.lastPongTime))
remainder = countdown % self.selectTimeout
countdown = countdown - remainder
if countdown <= 0:
self._d("No hope, dying!")
self.sendDisconnected("closed")
return
else:
if countdown % (self.selectTimeout*10) == 0 or countdown < 11:
self._d("Waiting, time to die: T-%i seconds" % countdown )
if self.timeout-countdown == 150 and self.ping and self.autoPong:
self.ping()
self.selectTimeout = 1 if countdown < 11 else 3
try:
ready = select.select([self.socket.reader.rawIn], [], [], self.selectTimeout)
except:
self._d("Error in ready")
raise
return
if self.terminateRequested:
return
if ready[0]:
try:
node = self.socket.reader.nextTree()
except ConnectionClosedException:
#print traceback.format_exc()
self._d("Socket closed, got 0 bytes!")
#self.signalInterface.send("disconnected", ("closed",))
self.sendDisconnected("closed")
return
self.lastPongTime = int(time.time());
if node is not None:
if ProtocolTreeNode.tagEquals(node,"iq"):
iqType = node.getAttributeValue("type")
idx = node.getAttributeValue("id")
if iqType is None:
raise Exception("iq doesn't have type")
if iqType == "result":
if idx in self.requests:
self.requests[idx](node)
del self.requests[idx]
elif idx.startswith(self.connection.user):
accountNode = node.getChild(0)
ProtocolTreeNode.require(accountNode,"account")
kind = accountNode.getAttributeValue("kind")
if kind == "paid":
self.connection.account_kind = 1
elif kind == "free":
self.connection.account_kind = 0
else:
self.connection.account_kind = -1
expiration = accountNode.getAttributeValue("expiration")
if expiration is None:
raise Exception("no expiration")
try:
self.connection.expire_date = long(expiration)
except ValueError:
raise IOError("invalid expire date %s"%(expiration))
self.eventHandler.onAccountChanged(self.connection.account_kind,self.connection.expire_date)
elif iqType == "error":
if idx in self.requests:
self.requests[idx](node)
del self.requests[idx]
elif iqType == "get":
childNode = node.getChild(0)
if ProtocolTreeNode.tagEquals(childNode,"ping"):
if self.autoPong:
self.onPing(idx)
self.signalInterface.send("ping", (idx,))
elif ProtocolTreeNode.tagEquals(childNode,"query") and node.getAttributeValue("from") is not None and "http://jabber.org/protocol/disco#info" == childNode.getAttributeValue("xmlns"):
pin = childNode.getAttributeValue("pin");
timeoutString = childNode.getAttributeValue("timeout");
try:
timeoutSeconds = int(timeoutString) if timeoutString is not None else None
except ValueError:
raise Exception("relay-iq exception parsing timeout %s "%(timeoutString))
#.........这里部分代码省略.........
示例7: parseMessage
#.........这里部分代码省略.........
author = bodyNode.getAttributeValue("author") or addSubject
bodyNode = messageNode.getChild("notification").getChild("remove");
if bodyNode is not None:
removeSubject = bodyNode.getAttributeValue("jid");
author = bodyNode.getAttributeValue("author") or removeSubject
if addSubject is not None:
self.signalInterface.send("notification_groupParticipantAdded", (fromAttribute, addSubject, author, timestamp, msgId, receiptRequested))
if removeSubject is not None:
self.signalInterface.send("notification_groupParticipantRemoved", (fromAttribute, removeSubject, author, timestamp, msgId, receiptRequested))
elif typeAttribute == "subject":
receiptRequested = False;
requestNodes = messageNode.getAllChildren("request");
for requestNode in requestNodes:
if requestNode.getAttributeValue("xmlns") == "urn:xmpp:receipts":
receiptRequested = True;
bodyNode = messageNode.getChild("body");
newSubject = None if bodyNode is None else (bodyNode.data if sys.version_info < (3, 0) else bodyNode.data.encode('latin-1').decode());
if newSubject is not None:
self.signalInterface.send("group_subjectReceived",(msgId, fromAttribute, author, newSubject, int(attribute_t), receiptRequested))
elif typeAttribute == "chat":
wantsReceipt = False;
messageChildren = [] if messageNode.children is None else messageNode.children
for childNode in messageChildren:
if ProtocolTreeNode.tagEquals(childNode,"request"):
wantsReceipt = True;
if ProtocolTreeNode.tagEquals(childNode,"broadcast"):
isBroadcast = True
elif ProtocolTreeNode.tagEquals(childNode,"composing"):
self.signalInterface.send("contact_typing", (fromAttribute,))
elif ProtocolTreeNode.tagEquals(childNode,"paused"):
self.signalInterface.send("contact_paused",(fromAttribute,))
elif ProtocolTreeNode.tagEquals(childNode,"media") and msgId is not None:
self._d("MULTIMEDIA MESSAGE!");
mediaUrl = messageNode.getChild("media").getAttributeValue("url");
mediaType = messageNode.getChild("media").getAttributeValue("type")
mediaSize = messageNode.getChild("media").getAttributeValue("size")
encoding = messageNode.getChild("media").getAttributeValue("encoding")
mediaPreview = None
if mediaType == "image":
mediaPreview = messageNode.getChild("media").data
if encoding == "raw" and mediaPreview:
mediaPreview = base64.b64encode(mediaPreview) if sys.version_info < (3, 0) else base64.b64encode(mediaPreview.encode('latin-1')).decode()
if isGroup:
self.signalInterface.send("group_imageReceived", (msgId, fromAttribute, author, mediaPreview, mediaUrl, mediaSize, wantsReceipt))
else:
self.signalInterface.send("image_received", (msgId, fromAttribute, mediaPreview, mediaUrl, mediaSize, wantsReceipt, isBroadcast))
elif mediaType == "video":