mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 14:54:21 +01:00
Add labeler.py to root package (bfxapi). Remove List aliases in bfxapi/rest/typings.py. Update BfxRestInterface.py to use new standards.
This commit is contained in:
20
bfxapi/labeler.py
Normal file
20
bfxapi/labeler.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from typing import Generic, TypeVar, Iterable, Optional, List, Any
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
class _Serializer(Generic[T]):
|
||||
def __init__(self, name: str, labels: List[str], IGNORE: List[str] = [ "_PLACEHOLDER" ]):
|
||||
self.name, self.__labels, self.__IGNORE = name, labels, IGNORE
|
||||
|
||||
def __serialize(self, *args: Any, skip: Optional[List[str]]) -> Iterable[T]:
|
||||
labels = list(filter(lambda label: label not in (skip or list()), self.__labels))
|
||||
|
||||
if len(labels) > len(args):
|
||||
raise Exception("<labels> and <*args> arguments should contain the same amount of elements.")
|
||||
|
||||
for index, label in enumerate(labels):
|
||||
if label not in self.__IGNORE:
|
||||
yield label, args[index]
|
||||
|
||||
def parse(self, *values: Any, skip: Optional[List[str]] = None) -> T:
|
||||
return dict(self.__serialize(*values, skip=skip))
|
||||
Reference in New Issue
Block a user