Add sphinx with converting part of pages

This commit is contained in:
Alex Root Junior 2020-06-15 02:22:24 +03:00
parent 3aa68a93d1
commit f68960ca87
192 changed files with 6123 additions and 350 deletions

File diff suppressed because it is too large Load diff

View file

@ -32,35 +32,63 @@ _JsonDumps = Callable[..., str]
class BaseSession(abc.ABC):
default_timeout: ClassVar[float] = 60.0
api: Default[TelegramAPIServer] = Default(PRODUCTION)
"""Telegra Bot API URL patterns"""
json_loads: Default[_JsonLoads] = Default(json.loads)
"""JSON loader"""
json_dumps: Default[_JsonDumps] = Default(json.dumps)
"""JSON dumper"""
default_timeout: ClassVar[float] = 60.0
"""Default timeout"""
timeout: Default[float] = Default(fget=lambda self: float(self.__class__.default_timeout))
"""Session scope request timeout"""
@classmethod
def raise_for_status(cls, response: Response[T]) -> None:
"""
Check response status
:param response: Response instance
"""
if response.ok:
return
raise TelegramAPIError(response.description)
@abc.abstractmethod
async def close(self) -> None: # pragma: no cover
"""
Close client session
"""
pass
@abc.abstractmethod
async def make_request(
self, bot: Bot, method: TelegramMethod[T], timeout: Optional[int] = UNSET
) -> T: # pragma: no cover
"""
Make request to Telegram Bot API
:param bot: Bot instance
:param method: Method instance
:param timeout: Request timeout
:return:
:raise TelegramApiError:
"""
pass
@abc.abstractmethod
async def stream_content(
self, url: str, timeout: int, chunk_size: int
) -> AsyncGenerator[bytes, None]: # pragma: no cover
"""
Stream reader
"""
yield b""
def prepare_value(self, value: Any) -> Union[str, int, bool]:
"""
Prepare value before send
"""
if isinstance(value, str):
return value
if isinstance(value, (list, dict)):
@ -74,6 +102,9 @@ class BaseSession(abc.ABC):
return str(value)
def clean_json(self, value: Any) -> Any:
"""
Clean data before send
"""
if isinstance(value, list):
return [self.clean_json(v) for v in value if v is not None]
elif isinstance(value, dict):

View file

@ -38,6 +38,13 @@ class InputFile(ABC):
class BufferedInputFile(InputFile):
def __init__(self, file: bytes, filename: str, chunk_size: int = DEFAULT_CHUNK_SIZE):
"""
Represents object for uploading files from filesystem
:param file: Bytes
:param filename: Filename to be propagated to telegram.
:param chunk_size: Uploading chunk size
"""
super().__init__(filename=filename, chunk_size=chunk_size)
self.data = file
@ -49,6 +56,15 @@ class BufferedInputFile(InputFile):
filename: Optional[str] = None,
chunk_size: int = DEFAULT_CHUNK_SIZE,
) -> BufferedInputFile:
"""
Create buffer from file
:param path: Path to file
:param filename: Filename to be propagated to telegram.
By default will be parsed from path
:param chunk_size: Uploading chunk size
:return: instance of :obj:`BufferedInputFile`
"""
if filename is None:
filename = os.path.basename(path)
with open(path, "rb") as f:
@ -70,6 +86,14 @@ class FSInputFile(InputFile):
filename: Optional[str] = None,
chunk_size: int = DEFAULT_CHUNK_SIZE,
):
"""
Represents object for uploading files from filesystem
:param path: Path to file
:param filename: Filename to be propagated to telegram.
By default will be parsed from path
:param chunk_size: Uploading chunk size
"""
if filename is None:
filename = os.path.basename(path)
super().__init__(filename=filename, chunk_size=chunk_size)
@ -92,6 +116,13 @@ class URLInputFile(InputFile):
chunk_size: int = DEFAULT_CHUNK_SIZE,
timeout: int = 30,
):
"""
Represents object for streaming files from internet
:param url: URL in internet
:param filename: Filename to be propagated to telegram.
:param chunk_size: Uploading chunk size
"""
super().__init__(filename=filename, chunk_size=chunk_size)
self.url = url