Issues (1445)

pincer/_config.py (1 issue)

1
# Copyright Pincer 2021-Present
0 ignored issues
show
Missing module docstring
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
from dataclasses import dataclass
5
6
7
@dataclass(repr=False)
8
class GatewayConfig:
9
    """This file is to make maintaining the library and its gateway
10
    configuration easier. Leave compression blank for no compression.
11
    """
12
13
    MAX_RETRIES: int = 5
14
    version: int = 9
15
    encoding: str = "json"
16
    compression: str = "zlib-payload"
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}" f"?v={cls.version}" f"&encoding={cls.encoding}"
28
        ) + f"&compress={cls.compression}" * cls.compressed()
29
30
    @classmethod
31
    def compressed(cls) -> bool:
32
        """
33
        Returns
34
        -------
35
        :class:`bool`:
36
            Whether the Gateway should compress payloads or not.
37
        """
38
        return cls.compression in ["zlib-stream", "zlib-payload"]
39