def function(**kwargs): if not self._req_method_list: self.log.debug('Create new request...') name = func.upper() if kwargs: self._req_method_list.append( { RequestType.Value(name): kwargs } ) self.log.debug("Adding '%s' to RPC request including arguments", name) self.log.debug("Arguments of '%s': \n\r%s", name, kwargs) else: self._req_method_list.append( RequestType.Value(name) ) self.log.debug("Adding '%s' to RPC request", name) return self
def __getattr__(self, func): def function(**kwargs): if '_call_direct' in kwargs: del kwargs['_call_direct'] self.log.info('Creating a new direct request...') elif not self._req_method_list: self.log.info('Creating a new request...') name = func.upper() if kwargs: self._req_method_list.append({RequestType.Value(name): kwargs}) self.log.info("Adding '%s' to RPC request including arguments", name) self.log.debug("Arguments of '%s': \n\r%s", name, kwargs) else: self._req_method_list.append(RequestType.Value(name)) self.log.info("Adding '%s' to RPC request", name) return self if func.upper() in RequestType.keys(): return function else: raise AttributeError
def __getattr__(self, func): def function(**kwargs): request = self.create_request() getattr(request, func)(_call_direct=True, **kwargs) return request.call() if func.upper() in RequestType.keys(): return function else: raise AttributeError
def _build_sub_requests(self, mainrequest, subrequest_list): self.log.debug('Generating sub RPC requests...') for entry in subrequest_list: if isinstance(entry, dict): entry_id = list(entry.items())[0][0] entry_content = entry[entry_id] entry_name = RequestType.Name(entry_id) proto_name = to_camel_case(entry_name.lower()) + 'Message' proto_classname = 'POGOProtos.Networking.Requests.Messages_pb2.' + proto_name subrequest_extension = self.get_class(proto_classname)() self.log.debug("Subrequest class: %s", proto_classname) for (key, value) in entry_content.items(): if isinstance(value, list): self.log.debug("Found list: %s - trying as repeated", key) for i in value: try: self.log.debug("%s -> %s", key, i) r = getattr(subrequest_extension, key) r.append(i) except Exception as e: self.log.warning( 'Argument %s with value %s unknown inside %s (Exception: %s)', key, i, proto_name, str(e)) else: try: setattr(subrequest_extension, key, value) except Exception: try: self.log.debug("%s -> %s", key, value) r = getattr(subrequest_extension, key) r.append(value) except Exception as e: self.log.warning( 'Argument %s with value %s unknown inside %s (Exception: %s)', key, value, proto_name, str(e)) subrequest = mainrequest.requests.add() subrequest.request_type = entry_id subrequest.request_message = subrequest_extension.SerializeToString( ) elif isinstance(entry, int): subrequest = mainrequest.requests.add() subrequest.request_type = entry else: raise Exception('Unknown value in request list') return mainrequest
def _parse_sub_responses(self, response_proto, subrequests_list, response_proto_dict): self.log.debug('Parsing sub RPC responses...') response_proto_dict['responses'] = {} if 'returns' in response_proto_dict: del response_proto_dict['returns'] list_len = len(subrequests_list) - 1 i = 0 for subresponse in response_proto.returns: if i > list_len: self.log.info("Error - something strange happend...") request_entry = subrequests_list[i] if isinstance(request_entry, int): entry_id = request_entry else: entry_id = list(request_entry.items())[0][0] entry_name = RequestType.Name(entry_id) proto_name = to_camel_case(entry_name.lower()) + 'Response' proto_classname = 'POGOProtos.Networking.Responses_pb2.' + proto_name self.log.debug("Parsing class: %s", proto_classname) subresponse_return = None try: subresponse_extension = self.get_class(proto_classname)() except Exception: subresponse_extension = None error = 'Protobuf definition for {} not found'.format( proto_classname) subresponse_return = error self.log.debug(error) if subresponse_extension: try: subresponse_extension.ParseFromString(subresponse) subresponse_return = protobuf_to_dict( subresponse_extension) except: error = "Protobuf definition for {} seems not to match".format( proto_classname) subresponse_return = error self.log.debug(error) response_proto_dict['responses'][entry_name] = subresponse_return i += 1 return response_proto_dict
def __getattr__(self, func): def function(**kwargs): if not self._req_method_list: self.log.debug('Create new request...') name = func.upper() if kwargs: self._req_method_list.append( { RequestType.Value(name): kwargs } ) self.log.debug("Adding '%s' to RPC request including arguments", name) self.log.debug("Arguments of '%s': \n\r%s", name, kwargs) else: self._req_method_list.append( RequestType.Value(name) ) self.log.debug("Adding '%s' to RPC request", name) return self if func.upper() in RequestType.keys(): return function else: raise AttributeError
def __getattr__(self, func): if func.upper() in RequestType.keys(): self.request_callers.append(func) return PGoApiRequest.__getattr__(self, func)
def __getattr__(self, func): if func.upper() in RequestType.keys(): self.request_callers.append(func) return PGoApiRequest.__getattr__(self, func)
def list_curr_methods(self): for i in self._req_method_list: print("{} ({})".format(RequestType.Name(i), i))