def fetch(self, user_id, query, page): if self.encryption: query = AES._aes_encrypt_and_encode(self.aes_key, query) encoded = Serialization.serialize_sendquery(user_id, query, page) response = self.__post('query', encoded, aes_encrypt=self.encryption) return Serialization.deserialize_sendqueryresponse(response)
def handle_query(self, message): query_message = Serialization.deserialize_sendquery(message) self.clients_lock.acquire() if query_message.user_id in self.clients: aes_key = self.clients[query_message.user_id].symmetric_key self.clients_lock.release() query = query_message.query if self.encryption: query = AES._aes_decrypt_and_decode(aes_key, query_message.query) response = self.__fetch_query.fetch('keyword', query, page=query_message.page) entries = self.__parse_query.parse(response) if self.encryption: return AES._aes_encrypt_and_encode(aes_key, Serialization.serialize_sendqueryresponse(entries)) return base64.b64encode(Serialization.serialize_sendqueryresponse(entries))