本文整理汇总了Python中yowsup.layers.YowLayerEvent方法的典型用法代码示例。如果您正苦于以下问题:Python layers.YowLayerEvent方法的具体用法?Python layers.YowLayerEvent怎么用?Python layers.YowLayerEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yowsup.layers
的用法示例。
在下文中一共展示了layers.YowLayerEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def main():
rospy.init_node("whatsapp_service")
cred = credentials.WHATSAPP
stackBuilder = YowStackBuilder()
stack = (stackBuilder
.pushDefaultLayers(True)
.push(AideRosLayer)
.build())
loginfo("Stack built...")
stack.setCredentials(cred)
stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT)) # sending the connect signal
loginfo("Connected...")
atexit.register(lambda: stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_DISCONNECT)))
th = threading.Thread(target=stack.loop)
th.daemon = True
th.start()
loginfo("Running in background.")
loginfo("All done. spinning.")
while not rospy.is_shutdown():
rospy.spin()
示例2: setUp
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def setUp(self):
YowCryptLayer.__init__(self)
self.password = bytearray(list(map(ord,"password")))
self.salt = bytearray(list(map(ord,"salt")))
self.username = "username"
self.inputMessage = bytearray([0,0,0,0, ord('t'), ord('a'), ord('r'), ord('e'), ord('k')])
self.inputMessageCrypted = bytearray(b'\x80\x00\r)\x99\xbe_\xee\x98\xecV<\x9d\x0c\xb7r')
keys = [
bytearray(b'>\xd5\x8a\xecB\xdb\xc8\xd4}\x98\x9aBa\x89\x9fC\x08\xdcp\x8d'),
bytearray(b'\xd3;\xda:\x8f\x94CX\xe4;\xbb\xcc"W\x83\xe0m\xba\xe0\xd1'),
bytearray(b'\x92w{\xc2\x04~\x08;\x81w\xb7h3\xb8\xc4t\xbd\xed\xf7q'),
bytearray(b'.\xc7\xe4\x15\x1a\xa0\xfd\x98\xc0\xea\xefs{\r7E\xa6\xec\xd5\xfb')
]
inputKey = KeyStream(keys[2], keys[3])
outputKey = KeyStream(keys[0], keys[1])
self.onEvent(YowLayerEvent(YowCryptLayer.EVENT_KEYS_READY, keys = (inputKey, outputKey)))
示例3: persistKeys
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def persistKeys(self, registrationId, identityKeyPair, preKeys, signedPreKey, fresh):
total = len(preKeys)
curr = 0
prevPercentage = 0
if fresh:
self.store.storeLocalData(registrationId, identityKeyPair)
self.store.storeSignedPreKey(signedPreKey.getId(), signedPreKey)
for preKey in preKeys:
self.store.storePreKey(preKey.getId(), preKey)
curr += 1
currPercentage = int((curr * 100) / total)
if currPercentage == prevPercentage:
continue
prevPercentage = currPercentage
#logger.debug("%s" % currPercentage + "%")
sys.stdout.write("Storing prekeys %d%% \r" % (currPercentage))
sys.stdout.flush()
if fresh:
self.state = self.__class__._STATE_GENKEYS
self.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_DISCONNECT))
示例4: onEvent
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def onEvent(self, layerEvent):
credentials=self.getProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS)
id=str(credentials[0])
logger.info(id +': '+ layerEvent.getName())
if layerEvent.getName() == YowNetworkLayer.EVENT_STATE_DISCONNECTED:
logger.warning("Id: %s, Disconnected: %s" % (id,layerEvent.getArg("reason")))
if layerEvent.getArg("reason") in ('Connection Closed','Ping Timeout'):
time.sleep(20)
logger.info("Id: %s, Issueing EVENT_STATE_CONNECT" % id)
self.getStack().broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
else:
app=self.getProp('flaskApp')
if hasattr(app,'layers') and 'credentials' in app.layers:
del app.layers[credentials]
elif layerEvent.getName() == YowNetworkLayer.EVENT_STATE_CONNECTED:
logger.info("Id: %s Connected"% id)
示例5: start
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def start(self):
self.stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
def startThread():
try:
self.stack.loop(timeout = 0.5, discrete = 0.5)
except AuthError as e:
print("Auth Error, reason %s" % e)
except KeyboardInterrupt:
print("\nYowsdown KeyboardInterrupt")
sys.exit(0)
except Exception as e:
print("\nYowsdown General Exception")
print e
t1=threading.Thread(target=startThread)
t1.daemon=True
t1.start()
示例6: handleSuccess
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def handleSuccess(self, node):
if(node.data != None): StorageTools.writeNonce(self.credentials[0],node.data)
successEvent = YowLayerEvent(self.__class__.EVENT_AUTHED, passive = self.getProp(self.__class__.PROP_PASSIVE))
self.broadcastEvent(successEvent)
nodeEntity = SuccessProtocolEntity.fromProtocolTreeNode(node)
self.toUpper(nodeEntity)
示例7: handleFailure
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def handleFailure(self, node):
nodeEntity = FailureProtocolEntity.fromProtocolTreeNode(node)
self.toUpper(nodeEntity)
self.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_DISCONNECT, reason = "Authentication Failure"))
raise AuthError(nodeEntity.getReason())
示例8: _sendAuth
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def _sendAuth(self):
passive = self.getProp(self.__class__.PROP_PASSIVE, False)
nonce = StorageTools.getNonce(self.credentials[0])
if nonce == None:
self.entityToLower(AuthProtocolEntity(self.credentials[0], passive=passive))
else:
inputKey, outputKey, authBlob = self.generateAuthBlob(nonce)
#to prevent enr whole response
self.broadcastEvent(YowLayerEvent(YowCryptLayer.EVENT_KEYS_READY, keys = (inputKey, None)))
self.entityToLower(AuthProtocolEntity(self.credentials[0], passive=passive, nonce=authBlob))
self.broadcastEvent(YowLayerEvent(YowCryptLayer.EVENT_KEYS_READY, keys = (inputKey, outputKey)))
示例9: _sendResponse
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def _sendResponse(self,nonce):
inputKey, outputKey, authBlob = self.generateAuthBlob(nonce)
responseEntity = ResponseProtocolEntity(authBlob)
#to prevent enr whole response
self.broadcastEvent(YowLayerEvent(YowCryptLayer.EVENT_KEYS_READY, keys = (inputKey, None)))
self.entityToLower(responseEntity)
self.broadcastEvent(YowLayerEvent(YowCryptLayer.EVENT_KEYS_READY, keys = (inputKey, outputKey)))
#YowCryptLayer.setProp("outputKey", outputKey)
示例10: disconnect
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def disconnect(self):
disconnectEvent = YowLayerEvent(YowNetworkLayer.EVENT_STATE_DISCONNECT)
self.broadcastEvent(disconnectEvent)
示例11: handle_connect
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def handle_connect(self):
self.state = self.__class__.STATE_CONNECTED
self.connected = True
if self.proxyHandler != None:
logger.debug("HttpProxy handle connect")
self.proxyHandler.send(self)
else:
self.emitEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECTED))
示例12: handle_close
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def handle_close(self, reason = "Connection Closed"):
if self.state != self.__class__.STATE_DISCONNECTED:
self.state = self.__class__.STATE_DISCONNECTED
self.connected = False
logger.debug("Disconnected, reason: %s" % reason)
self.emitEvent(YowLayerEvent(self.__class__.EVENT_STATE_DISCONNECTED, reason = reason, detached=True))
self.close()
示例13: waitPong
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def waitPong(self, id):
self._pingQueueLock.acquire()
self._pingQueue[id] = None
pingQueueSize = len(self._pingQueue)
self._pingQueueLock.release()
self.__logger.debug("ping queue size: %d" % pingQueueSize)
if pingQueueSize >= 2:
self.getStack().broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_DISCONNECT, reason = "Ping Timeout"))
示例14: start
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def start(self):
self.stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
try:
self.stack.loop()
except AuthError as e:
print("Authentication Error: %s" % e.message)
示例15: disconnect
# 需要导入模块: from yowsup import layers [as 别名]
# 或者: from yowsup.layers import YowLayerEvent [as 别名]
def disconnect(self):
if self.assertConnected():
self.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_DISCONNECT))