def loginCall(self, loginInput): print('Long term memory handler, login %s' % input) ip, port = self.__resolve_config() transport = TSocket.TSocket(ip, port) # Make socket try: lmLoginInput = LongMemoryLoginInputObject() lmLoginInput.username = loginInput.username lmLoginInput.password = loginInput.password lmLoginInput.code = loginInput.code transport = TTransport.TBufferedTransport( transport) # Buffering is critical. Raw sockets are very slow protocol = TBinaryProtocol.TBinaryProtocol( transport) # Wrap in a protocol client = LongMemoryService.Client( protocol) # Create a client to use the protocol encoder transport.open() # Connect! person = client.loginCall(loginobject=lmLoginInput) transport.close() return person except LoginFailedException as fail: print('login failed %s' % fail) raise fail except BadHashException as bad: print('Bad hash %s' % bad) raise bad except Thrift.TException as tx: print('%s' % (tx.message)) raise tx finally: transport.close()
def login(self, input): ip, port = self.__resolve_longmemory_config() transport = TSocket.TSocket(ip, port) try: transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = LongMemoryService.Client(protocol) transport.open() output = client.loginCall(input) transport.close() return output except Thrift.TException as tx: print("%s" % (tx.message)) finally: transport.close()
def storeNewPerson(self, input): ip, port = self.__resolve_longmemory_config() transport = TSocket.TSocket(ip, port) try: transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = LongMemoryService.Client(protocol) transport.open() client.storeNewPerson(input) transport.close() except UniqueFailedException as unique: raise unique except Thrift.TException as tx: print("%s" % (tx.message)) finally: transport.close()
def changeUser(self, field, person): ip, port = self.__resolve_config() transport = TSocket.TSocket(ip, port) # Make socket try: transport = TTransport.TBufferedTransport( transport) # Buffering is critical. Raw sockets are very slow protocol = TBinaryProtocol.TBinaryProtocol( transport) # Wrap in a protocol client = LongMemoryService.Client( protocol) # Create a client to use the protocol encoder transport.open() client.updatePerson(field=field, person=person) transport.close() except Thrift.TException as tx: print('%s' % (tx.message)) except Exception as ex: print('whot??? %s' % ex) finally: transport.close()
def getUserList(self): ip, port = self.__resolve_config() transport = TSocket.TSocket(ip, port) # Make socket try: transport = TTransport.TBufferedTransport( transport) # Buffering is critical. Raw sockets are very slow protocol = TBinaryProtocol.TBinaryProtocol( transport) # Wrap in a protocol client = LongMemoryService.Client( protocol) # Create a client to use the protocol encoder transport.open() personList = client.getAll() transport.close() return personList except Thrift.TException as tx: print('%s' % (tx.message)) except Exception as ex: print('whot??? %s' % ex) finally: transport.close()
def get_Person(self, input): print('Long term memory handler, get Person %s' % input) ip, port = self.__resolve_config() transport = TSocket.TSocket(ip, port) # Make socket try: transport = TTransport.TBufferedTransport( transport) # Buffering is critical. Raw sockets are very slow protocol = TBinaryProtocol.TBinaryProtocol( transport) # Wrap in a protocol client = LongMemoryService.Client( protocol) # Create a client to use the protocol encoder transport.open() # Connect! person = client.getPersonConfig(uniquename=input) transport.close() return person except Thrift.TException as tx: print('%s' % (tx.message)) except Exception as ex: print('whot??? %s' % ex) finally: transport.close()
def createNewPerson(self, person): ip, port = self.__resolve_config() transport = TSocket.TSocket(ip, port) # Make socket try: transport = TTransport.TBufferedTransport( transport) # Buffering is critical. Raw sockets are very slow protocol = TBinaryProtocol.TBinaryProtocol( transport) # Wrap in a protocol client = LongMemoryService.Client( protocol) # Create a client to use the protocol encoder transport.open() # Connect! person = client.storeNewPerson(person=person) transport.close() return person except UniqueFailedException as unique: raise unique except Thrift.TException as tx: print('%s' % (tx.message)) except Exception as ex: print('whot??? %s' % ex) finally: transport.close()
def changePassword(self, username, password): ip, port = self.__resolve_config() transport = TSocket.TSocket(ip, port) # Make socket try: transport = TTransport.TBufferedTransport( transport) # Buffering is critical. Raw sockets are very slow protocol = TBinaryProtocol.TBinaryProtocol( transport) # Wrap in a protocol client = LongMemoryService.Client( protocol) # Create a client to use the protocol encoder transport.open() # TODO review this! client.changePassword(username=username, password=password) transport.close() except BadHashException as bad: raise bad except LoginFailedException as fail: raise fail except Thrift.TException as tx: print('%s' % (tx.message)) except Exception as ex: print('whot??? %s' % ex) finally: transport.close()
def configureModuleSettings(self, uniquename, action, config): ip, port = self.__resolve_config() transport = TSocket.TSocket(ip, port) # Make socket try: person = Person() person.uniquename = uniquename transport = TTransport.TBufferedTransport( transport) # Buffering is critical. Raw sockets are very slow protocol = TBinaryProtocol.TBinaryProtocol( transport) # Wrap in a protocol client = LongMemoryService.Client( protocol) # Create a client to use the protocol encoder transport.open() client.updateActionConfig(uniquename=uniquename, action=action, config=config) transport.close() except Thrift.TException as tx: print('%s' % (tx.message)) except Exception as ex: print('whot??? %s' % ex) finally: transport.close()
def create_server(): handler = LongTermMemoryThriftServer() return TServer.TSimpleServer(LongMemoryService.Processor(handler), TSocket.TServerSocket(port=port), TTransport.TBufferedTransportFactory(), TBinaryProtocol.TBinaryProtocolFactory())