pincer._config   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 16
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A GatewayConfig.compressed() 0 9 1
A GatewayConfig.make_uri() 0 11 1
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
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