コード例 #1
0
ファイル: messages.py プロジェクト: jmcrox/python-api
    def parse(serializedData):
        '''
        Parses a serialized JSON message received from the SIB.
        
        Keyword arguments:
        serializedData: a serialized JSON messages
        '''
        dataWithoutEscapedQuotes = serializedData.replace(b"\\\\", b"")
        jsonMessage = json.loads(bytes2String(dataWithoutEscapedQuotes))
        
        jsonMessage["messageType"] = _SSAPMessageParser.__message_types[jsonMessage["messageType"]]
        jsonMessage["direction"] = _SSAPMessageParser.__message_directions[jsonMessage["direction"]]
        
        if (isinstance(jsonMessage["body"], str)):
            # Some ssap messages have a string (and therefore non-json) body. In that case, we'll have to
            # parse it too.
            if(jsonMessage["messageType"] == SSAP_MESSAGE_TYPE.INDICATION) :
                jsonMessage["body"] = six.b(jsonMessage["body"]).replace(b"\"[", b"[").replace(b"]\"", b"]")
                
            jsonMessage["body"] = json.loads(jsonMessage["body"])
        
        if (SSAPEndpoint.hasOkField(jsonMessage) and jsonMessage["body"]["ok"] and 
                jsonMessage["messageType"] in [SSAP_MESSAGE_TYPE.INSERT, SSAP_MESSAGE_TYPE.UPDATE]) :
            # The message body data is a string or an array of strings. We must convert it to a JSON object
            patched_data = six.b(jsonMessage["body"]["data"])             
            patched_data = patched_data.replace(b"ObjectId", b"\"ObjectId")
            patched_data = patched_data.replace(b"(\"", b"('")
            patched_data = patched_data.replace(b"\")", b"')\"")           
            jsonMessage["body"]["data"] = json.loads(bytes2String(patched_data))

        if ("errorCode" in jsonMessage["body"] and not (jsonMessage["body"]["errorCode"] is None)):
            jsonMessage["body"]["errorCode"] = _SSAPMessageParser.__error_codes[jsonMessage["body"]["errorCode"]]
        
        return jsonMessage
コード例 #2
0
ファイル: callbacks.py プロジェクト: C8E/python-api
 def onSSAPMessageReceived(self, message):
     self.__prettyPrintMessage(message)
     self.__isResponseOk = SSAPEndpoint.hasOkField(message) and message["body"]["ok"]
     if (message["messageType"] == SSAP_MESSAGE_TYPE.SUBSCRIBE):
         self.__subscriptionId = message["body"]["data"]
     self.__indicationReceived = message["messageType"] == SSAP_MESSAGE_TYPE.INDICATION
     self.__responseReceived = True
コード例 #3
0
ファイル: callbacks.py プロジェクト: Sofia2/python-api
 def onSSAPMessageReceived(self, message):
     self.__prettyPrintMessage(message)
     self.__isResponseOk = SSAPEndpoint.hasOkField(
         message) and message["body"]["ok"]
     if (message["messageType"] == SSAP_MESSAGE_TYPE.SUBSCRIBE):
         self.__subscriptionId = message["body"]["data"]
     self.__indicationReceived = message[
         "messageType"] == SSAP_MESSAGE_TYPE.INDICATION
     self.__responseReceived = True
コード例 #4
0
ファイル: websockets.py プロジェクト: C8E/python-api
 def __init__(self, callback, connectionData, debugMode=False):
     '''
     Initializes the state of the endpoint.
     
     Keyword arguments:
     callback          -- the object that will process the incoming SSAP messages.
     connectionData    -- the object that stores the configuration of the websocket connection.
     debugMode         -- a flag that enables additional debug messages.
     '''
     SSAPEndpoint.__init__(self, callback)
     if (debugMode) :
         logLevel = logging.DEBUG
     else:
         logLevel = logging.INFO
     self.__logger = LogFactory.configureLogger(self, logLevel, LogFactory.DEFAULT_LOG_FILE)      
     self.__queue = GenericThreadSafeList()
     self.__websocket = None
     self.__connectionData = connectionData
     self.__activeSubscriptions = 0
コード例 #5
0
 def __init__(self, callback, connectionData, debugMode=False):
     '''
     Initializes the state of the endpoint.
     
     Keyword arguments:
     callback          -- the object that will process the incoming SSAP messages.
     connectionData    -- the object that stores the configuration of the websocket connection.
     debugMode         -- a flag that enables additional debug messages.
     '''
     SSAPEndpoint.__init__(self, callback)
     if (debugMode) :
         logLevel = logging.DEBUG
     else:
         logLevel = logging.INFO
     self.__logger = LogFactory.configureLogger(self, logLevel, LogFactory.DEFAULT_LOG_FILE)      
     self.__queue = GenericThreadSafeList()
     self.__websocket = None
     self.__connectionData = connectionData
     self.__activeSubscriptions = 0
コード例 #6
0
    def parse(serializedData):
        '''
        Parses a serialized JSON message received from the SIB.
        
        Keyword arguments:
        serializedData: a serialized JSON messages
        '''
        dataWithoutEscapedQuotes = serializedData.replace(b"\\\\", b"")
        jsonMessage = json.loads(bytes2String(dataWithoutEscapedQuotes))
        
        jsonMessage["messageType"] = _SSAPMessageParser.__message_types[jsonMessage["messageType"]]
        jsonMessage["direction"] = _SSAPMessageParser.__message_directions[jsonMessage["direction"]]
        
        if (isinstance(jsonMessage["body"], six.string_types)):
            # Some ssap messages have a string (and therefore non-json) body. In that case, we'll have to
            # parse it too.
            if(jsonMessage["messageType"] == SSAP_MESSAGE_TYPE.INDICATION) :
                patched_data = jsonMessage["body"] = six.b(jsonMessage["body"]).replace(b"\"[", b"[").replace(b"]\"", b"]")

                patched_data = patched_data.replace(b" ", b"")
                patched_data = patched_data.replace(b'"{', b'{')
                patched_data = patched_data.replace(b'}"', b'}')
                #patched_data = patched_data.replace(b'" :', b'":')
                jsonMessage["body"]=patched_data
                print("Dato\n")
                print(jsonMessage["body"])


            if(jsonMessage["messageType"] == SSAP_MESSAGE_TYPE.SUBSCRIBE) :
                print("Mensage")

                jsonMessage["body"] = six.b(jsonMessage["body"]).replace(b"\"[", b"[").replace(b"]\"", b"]")
                print(jsonMessage["body"])
                
            jsonMessage["body"] = json.loads(bytes2String(jsonMessage["body"]))
        
        if (SSAPEndpoint.hasOkField(jsonMessage) and jsonMessage["body"]["ok"] and 
                jsonMessage["messageType"] in [SSAP_MESSAGE_TYPE.INSERT, SSAP_MESSAGE_TYPE.UPDATE]) :
            # The message body data is a string or an array of strings. We must convert it to a JSON object
            patched_data = six.b(jsonMessage["body"]["data"])             
            patched_data = patched_data.replace(b"ObjectId", b"\"ObjectId")
            patched_data = patched_data.replace(b"(\"", b"('")
            patched_data = patched_data.replace(b"\")", b"')\"")           
            jsonMessage["body"]["data"] = json.loads(bytes2String(patched_data))

        if ("errorCode" in jsonMessage["body"] and not (jsonMessage["body"]["errorCode"] is None)):
            jsonMessage["body"]["errorCode"] = _SSAPMessageParser.__error_codes[jsonMessage["body"]["errorCode"]]
        
        return jsonMessage
コード例 #7
0
ファイル: websockets.py プロジェクト: C8E/python-api
 def _clearStateData(self):
     '''
     Deletes all the state data stored in the endpoint (i.e. session keys, ...).
     '''
     SSAPEndpoint._clearStateData(self)
     self.__connection_established = False
コード例 #8
0
 def _clearStateData(self):
     '''
     Deletes all the state data stored in the endpoint (i.e. session keys, ...).
     '''
     SSAPEndpoint._clearStateData(self)
     self.__connection_established = False