當前位置: 首頁>>代碼示例>>Python>>正文


Python layers.YowLayerEvent方法代碼示例

本文整理匯總了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() 
開發者ID:Lambda-3,項目名稱:aide,代碼行數:23,代碼來源:whatsapp.py

示例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))) 
開發者ID:svub,項目名稱:whatsapp-rest-webservice,代碼行數:19,代碼來源:test_crypt.py

示例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)) 
開發者ID:svub,項目名稱:whatsapp-rest-webservice,代碼行數:25,代碼來源:layer_control.py

示例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) 
開發者ID:johntheknife,項目名稱:yowsuphttpinterface,代碼行數:18,代碼來源:layer.py

示例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() 
開發者ID:johntheknife,項目名稱:yowsuphttpinterface,代碼行數:18,代碼來源:stack.py

示例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) 
開發者ID:svub,項目名稱:whatsapp-rest-webservice,代碼行數:8,代碼來源:layer_authentication.py

示例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()) 
開發者ID:svub,項目名稱:whatsapp-rest-webservice,代碼行數:7,代碼來源:layer_authentication.py

示例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))) 
開發者ID:svub,項目名稱:whatsapp-rest-webservice,代碼行數:14,代碼來源:layer_authentication.py

示例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) 
開發者ID:svub,項目名稱:whatsapp-rest-webservice,代碼行數:11,代碼來源:layer_authentication.py

示例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) 
開發者ID:svub,項目名稱:whatsapp-rest-webservice,代碼行數:5,代碼來源:interface.py

示例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)) 
開發者ID:svub,項目名稱:whatsapp-rest-webservice,代碼行數:10,代碼來源:layer.py

示例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() 
開發者ID:svub,項目名稱:whatsapp-rest-webservice,代碼行數:9,代碼來源:layer.py

示例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")) 
開發者ID:svub,項目名稱:whatsapp-rest-webservice,代碼行數:10,代碼來源:layer.py

示例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) 
開發者ID:svub,項目名稱:whatsapp-rest-webservice,代碼行數:8,代碼來源:stack.py

示例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)) 
開發者ID:svub,項目名稱:whatsapp-rest-webservice,代碼行數:6,代碼來源:layer.py


注:本文中的yowsup.layers.YowLayerEvent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。