| Total Complexity | 2 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # Copyright Pincer 2021-Present |
||
|
|
|||
| 2 | # Full MIT License can be found in `LICENSE` at the project root. |
||
| 3 | |||
| 4 | from dataclasses import dataclass |
||
| 5 | from typing import Optional |
||
| 6 | |||
| 7 | |||
| 8 | @dataclass(repr=False) |
||
| 9 | class GatewayConfig: |
||
| 10 | """This file is to make maintaining the library and its gateway |
||
| 11 | configuration easier. Leave compression blank for no compression. |
||
| 12 | """ |
||
| 13 | MAX_RETRIES: int = 5 |
||
| 14 | version: int = 9 |
||
| 15 | encoding: str = "json" |
||
| 16 | compression: str = "zlib-stream" |
||
| 17 | |||
| 18 | @classmethod |
||
| 19 | def make_uri(cls, uri) -> str: |
||
| 20 | """ |
||
| 21 | Returns |
||
| 22 | ------- |
||
| 23 | :class:`str`: |
||
| 24 | The GatewayConfig's uri. |
||
| 25 | """ |
||
| 26 | return ( |
||
| 27 | f"{uri}" |
||
| 28 | f"?v={cls.version}" |
||
| 29 | f"&encoding={cls.encoding}" |
||
| 30 | ) + f"&compress={cls.compression}" * cls.compressed() |
||
| 31 | |||
| 32 | @classmethod |
||
| 33 | def compressed(cls) -> bool: |
||
| 34 | """ |
||
| 35 | Returns |
||
| 36 | ------- |
||
| 37 | :class:`bool`: |
||
| 38 | Whether the Gateway should compress payloads or not. |
||
| 39 | """ |
||
| 40 | return cls.compression in ["zlib-stream", "zlib-payload"] |
||
| 41 |