Пример #1
0
 def complete(response) :
     if response.error:
         return callback(None)
     obj = json.loads(response.buffer.getvalue())
     pc = PubnubCrypto()
     out = []
     if self.cipher_key :
         if requestType == "history" :
             if type(obj) == type(list()):
                 for item in obj:
                     if type(item) == type(list()):
                         for subitem in item:
                             encryptItem = pc.decrypt(self.cipher_key, subitem )
                             out.append(encryptItem)
                     elif type(item) == type(dict()):
                         outdict = {}
                         for k, subitem in item.iteritems():
                             encryptItem = pc.decrypt(self.cipher_key, subitem )
                             outdict[k] = encryptItem
                             out.append(outdict)
                     else :         
                         encryptItem = pc.decrypt(self.cipher_key, item )
                         out.append(encryptItem)
                 callback(out)
             elif type( obj ) == type(dict()):
                 for k, item in obj.iteritems():
                     encryptItem = pc.decrypt(self.cipher_key, item )
                     out.append(encryptItem)
                 callback(out)    
         else :
             callback(obj)
     else :        
         callback(obj)        
Пример #2
0
 def complete(response):
     if response.error:
         return callback(None)
     obj = json.loads(response.buffer.getvalue())
     pc = PubnubCrypto()
     out = []
     if self.cipher_key:
         if requestType == "history":
             if type(obj) == type(list()):
                 for item in obj:
                     if type(item) == type(list()):
                         for subitem in item:
                             encryptItem = pc.decrypt(
                                 self.cipher_key, subitem)
                             out.append(encryptItem)
                     elif type(item) == type(dict()):
                         outdict = {}
                         for k, subitem in item.iteritems():
                             encryptItem = pc.decrypt(
                                 self.cipher_key, subitem)
                             outdict[k] = encryptItem
                             out.append(outdict)
                     else:
                         encryptItem = pc.decrypt(self.cipher_key, item)
                         out.append(encryptItem)
                 callback(out)
             elif type(obj) == type(dict()):
                 for k, item in obj.iteritems():
                     encryptItem = pc.decrypt(self.cipher_key, item)
                     out.append(encryptItem)
                 callback(out)
         else:
             callback(obj)
     else:
         callback(obj)
Пример #3
0
        def complete(data):
            try    : obj = json.loads(data)
            except : obj = None

            pc = PubnubCrypto()
            out = []
            if self.cipher_key :
                if requestType == "history" :
                    if type(obj) == type(list()):
                        for item in obj:
                            if type(item) == type(list()):
                                for subitem in item:
                                    encryptItem = pc.decrypt(self.cipher_key, subitem )
                                    out.append(encryptItem)
                            elif type(item) == type(dict()):
                                outdict = {}
                                for k, subitem in item.iteritems():
                                    encryptItem = pc.decrypt(self.cipher_key, subitem )
                                    outdict[k] = encryptItem
                                    out.append(outdict)
                            else :         
                                encryptItem = pc.decrypt(self.cipher_key, item )
                                out.append(encryptItem)
                        callback(out)
                    elif type( obj ) == type(dict()):
                        for k, item in obj.iteritems():
                            encryptItem = pc.decrypt(self.cipher_key, item )
                            out.append(encryptItem)
                        callback(out)    
                else :
                    callback(obj)
            else :        
                callback(obj)        
Пример #4
0
            def sub_callback(response):
                ## STOP CONNECTION?
                if not self.subscriptions[channel]['connected']:
                    return

                ## CONNECTED CALLBACK
                if not self.subscriptions[channel]['first']:
                    self.subscriptions[channel]['first'] = True
                    connectcb()

                ## PROBLEM?
                if not response:

                    def time_callback(_time):
                        if not _time:
                            reactor.callLater(time.time() + 1, substabizel)
                            return errorback("Lost Network Connection")
                        else:
                            reactor.callLater(time.time() + 1, substabizel)

                    ## ENSURE CONNECTED (Call Time Function)
                    return self.time({'callback': time_callback})

                self.subscriptions[channel]['timetoken'] = response[1]
                substabizel()

                pc = PubnubCrypto()
                out = []
                for message in response[0]:
                    if self.cipher_key:
                        if type(message) == type(list()):
                            for item in message:
                                encryptItem = pc.decrypt(self.cipher_key, item)
                                out.append(encryptItem)
                            message = out
                        elif type(message) == type(dict()):
                            outdict = {}
                            for k, item in message.iteritems():
                                encryptItem = pc.decrypt(self.cipher_key, item)
                                outdict[k] = encryptItem
                                out.append(outdict)
                            message = out[0]
                        else:
                            message = pc.decrypt(self.cipher_key, message)
                    else:
                        message

                    callback(message)
Пример #5
0
            def sub_callback(response):
                ## STOP CONNECTION?
                if not self.subscriptions[channel]['connected']:
                    return

                ## CONNECTED CALLBACK
                if not self.subscriptions[channel]['first'] :
                    self.subscriptions[channel]['first'] = True
                    connectcb()

                ## PROBLEM?
                if not response:
                    def time_callback(_time):
                        if not _time:
                            reactor.callLater( 1, substabizel )
                            return errorback("Lost Network Connection")
                        else:
                            reactor.callLater( 1, substabizel )

                    ## ENSURE CONNECTED (Call Time Function)
                    return self.time({ 'callback' : time_callback })

                self.subscriptions[channel]['timetoken'] = response[1]
                substabizel()

                pc = PubnubCrypto()
                out = []
                for message in response[0]:
                     if self.cipher_key :
                          if type( message ) == type(list()):
                              for item in message:
                                  encryptItem = pc.decrypt(self.cipher_key, item )
                                  out.append(encryptItem)
                              message = out
                          elif type( message ) == type(dict()):
                              outdict = {}
                              for k, item in message.iteritems():
                                  encryptItem = pc.decrypt(self.cipher_key, item )
                                  outdict[k] = encryptItem
                                  out.append(outdict)
                              message = out[0]
                          else:
                              message = pc.decrypt(self.cipher_key, message )
                     else :
                          message
                        
                     callback(message)
Пример #6
0
        def complete(data):
            if (type(data) == type(str())):
                if self.resulting_is:
                    d = zlib.decompressobj(16 + zlib.MAX_WBITS)

            try:
                data = d.decompress(
                    data)  # try/catch here, pass through if except
            except:
                data = data

            try:
                obj = json.loads(data)
            except:
                obj = None

            pc = PubnubCrypto()
            out = []
            if self.cipher_key:
                if requestType == "history":
                    if type(obj) == type(list()):
                        for item in obj:
                            if type(item) == type(list()):
                                for subitem in item:
                                    encryptItem = pc.decrypt(
                                        self.cipher_key, subitem)
                                    out.append(encryptItem)
                            elif type(item) == type(dict()):
                                outdict = {}
                                for k, subitem in item.iteritems():
                                    encryptItem = pc.decrypt(
                                        self.cipher_key, subitem)
                                    outdict[k] = encryptItem
                                    out.append(outdict)
                            else:
                                encryptItem = pc.decrypt(self.cipher_key, item)
                                out.append(encryptItem)
                        callback(out)
                    elif type(obj) == type(dict()):
                        for k, item in obj.iteritems():
                            encryptItem = pc.decrypt(self.cipher_key, item)
                            out.append(encryptItem)
                        callback(out)
                else:
                    callback(obj)
            else:
                callback(obj)
Пример #7
0
    def decrypt(self, message):
        if self.cipher_key:
            pc = PubnubCrypto()
            if type(message) == type(list()):
                for item in message:
                    encryptItem = pc.decrypt(self.cipher_key, item)
                    out.append(encryptItem)
                message = out
            elif type(message) == type(dict()):
                outdict = {}
                for k, item in message.iteritems():
                    encryptItem = pc.decrypt(self.cipher_key, item)
                    outdict[k] = encryptItem
                    out.append(outdict)
                message = out[0]
            else:
                message = pc.decrypt(self.cipher_key, message)

        return message
Пример #8
0
    def decrypt(self, message):
        if self.cipher_key:
            pc = PubnubCrypto()
            if type( message ) == type(list()):
                for item in message:
                    encryptItem = pc.decrypt(self.cipher_key, item )
                    out.append(encryptItem)
                message = out
            elif type( message ) == type(dict()):
                outdict = {}
                for k, item in message.iteritems():
                    encryptItem = pc.decrypt(self.cipher_key, item )
                    outdict[k] = encryptItem
                    out.append(outdict)
                message = out[0]
            else:
                message = pc.decrypt(self.cipher_key, message)

        return message
Пример #9
0
        def complete(data):
            if ( type(data) == type(str()) ):
                if self.resulting_is:
                    d = zlib.decompressobj(16+zlib.MAX_WBITS)

            try     :   data = d.decompress(data) # try/catch here, pass through if except
            except  :   data = data

            try    : obj = json.loads(data)
            except : obj = None

            pc = PubnubCrypto()
            out = []
            if self.cipher_key :
                if requestType == "history" :
                    if type(obj) == type(list()):
                        for item in obj:
                            if type(item) == type(list()):
                                for subitem in item:
                                    encryptItem = pc.decrypt(self.cipher_key, subitem )
                                    out.append(encryptItem)
                            elif type(item) == type(dict()):
                                outdict = {}
                                for k, subitem in item.iteritems():
                                    encryptItem = pc.decrypt(self.cipher_key, subitem )
                                    outdict[k] = encryptItem
                                    out.append(outdict)
                            else :
                                encryptItem = pc.decrypt(self.cipher_key, item )
                                out.append(encryptItem)
                        callback(out)
                    elif type( obj ) == type(dict()):
                        for k, item in obj.iteritems():
                            encryptItem = pc.decrypt(self.cipher_key, item )
                            out.append(encryptItem)
                        callback(out)
                else :
                    callback(obj)
            else :
                callback(obj)