async def get(self, sid: str = None, pipeline: str = None, keep_raw: bool = False): '''Awaitable. Get this object from the pipeline.\n `sid` id identifying the session on the pipeline to reuse.\n `pipeline` key identifying the pipeline to execute against.\n `keep_raw` flag for storing raw data of the request as a dictionary.\n ''' # pylint: disable=no-member if pipeline: self.set_pipeline(pipeline) token1 = await self.create_token( search="match" if "tournament_code" not in self.__dict__ else "tournament") token2 = await self.create_token(search="timeline") task1 = asyncio.create_task(self._meta.pipeline.get(token1, sid)) task2 = asyncio.create_task(self._meta.pipeline.get(token2, sid)) data1 = await task1 data2 = await task2 if keep_raw: self._meta.raw_data = { 'match': fast_copy(data1), 'timeline': fast_copy(data2) } self._meta.data = self._transform(data1, data2) self._fill() return self
async def get(self, sid: str = None, pipeline: str = None, keep_raw: bool = False, ptr_cache: PtrCache = None): '''Awaitable. Get this object from the pipeline.\n `sid` id identifying the session on the pipeline to reuse.\n `pipeline` key identifying the pipeline to execute against.\n `keep_raw` flag for storing raw data of the request as a dictionary.\n `ptr_cache` intercepts a PtrCache, usage details please refer to documentations.\n ''' self.set_pipeline(pipeline) token = await self.create_token() if ptr_cache: if not isinstance(ptr_cache, PtrCache): raise TypeError(f"'ptr_cache' receives object of type 'PtrCache', got '{ptr_cache.__class__.__name__}'") item = ptr_cache.get(token.stringify + self._meta.filter_key) if item: return item data = await self._meta.pipeline.get(token, sid) data = self._filter(data) if keep_raw: self._meta.raw_data = fast_copy(data) self._meta.data = self._transform(data) self._fill() if ptr_cache: ptr_cache.set(token.stringify + self._meta.filter_key, self) return self
def dict(self, pyotify: bool = False, remove_server: bool = True): ''' Convert this pyot object to a python dictionary.\n Set `pyotify` to True to return a dict with the same schema of the pyot object (This is expensive due to recursion).\n Set `remove_server` to False to not remove the server values (region/platform/locale). ''' if not pyotify: return fast_copy(self._meta.data) # USING PICKLE FOR FASTER COPY def recursive(obj): dic = obj.__dict__ del dic["_meta"] if remove_server: dic.pop(self._meta.server_type, None) for key, val in dic.items(): if type(val) is PyotLazyObject: obj = val() if isinstance(obj, list): dic[key] = [] for i in range(len(obj)): inner = recursive(obj[i]) dic[key].append(inner) else: inner = recursive(obj) dic[key] = inner return dic obj = pickle.loads(pickle.dumps(self)) return recursive(obj)
async def put(self, sid: str = None, pipeline: str = None, deepcopy: bool = False): '''Awaitable. Execute a PUT request against the pipeline.''' self.set_pipeline(pipeline) token = await self.create_token() data = await self._meta.pipeline.put(token, self._meta.body, sid) data = self._filter(data) self._meta.raw_data = fast_copy(data) if deepcopy else data self._meta.data = self._transform(data) self._fill() return self
async def get_limits(self, server: str, method: str): limits = [] limits.append(f"{self._api_key}_application_rates_{server}") limits.append(f"{self._api_key}_application_times_{server}") limits.append(f"{self._api_key}_methods_rates_{method}") limits.append(f"{self._api_key}_methods_times_{method}") responses = enumerate(self._redis.mget(limits)) # responses = enumerate(await thread_run(partial(self._redis.mget, limits))) return [ pytify(item) if item is not None else fast_copy(self.defaults[ind]) for (ind, item) in responses ]
def dict(self, deepcopy=False, lazy_props=False, recursive=False): if lazy_props: for prop in self._meta.lazy_props: self._load_lazy_prop(self, prop) dic = self._recursive_dict() if recursive else self._meta.data return fast_copy(dic) if deepcopy else dic.copy()