Skip to content

Utils

FLVersion dataclass

Source code in pyflp/_utils.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
@dt.dataclass
class FLVersion:
    string: dt.InitVar[str]
    major: int = dt.field(init=False)
    minor: int = dt.field(init=False)
    revision: int = dt.field(init=False)
    build: int = dt.field(init=False)

    def __post_init__(self, string: str):
        split = string.split(".")
        self.major = int(split[0])
        self.minor = int(split[1])
        self.revision = int(split[2])
        try:
            self.build = int(split[3])
        except IndexError:  # pragma: no cover
            pass

    def as_float(self) -> float:
        return float(f"{self.major}.{self.minor}")

build: int = dt.field(init=False) class-attribute

major: int = dt.field(init=False) class-attribute

minor: int = dt.field(init=False) class-attribute

revision: int = dt.field(init=False) class-attribute

string: dt.InitVar[str] class-attribute

__post_init__(string)

Source code in pyflp/_utils.py
47
48
49
50
51
52
53
54
55
def __post_init__(self, string: str):
    split = string.split(".")
    self.major = int(split[0])
    self.minor = int(split[1])
    self.revision = int(split[2])
    try:
        self.build = int(split[3])
    except IndexError:  # pragma: no cover
        pass

as_float()

Source code in pyflp/_utils.py
57
58
def as_float(self) -> float:
    return float(f"{self.major}.{self.minor}")

buflen_to_varint(buffer)

Source code in pyflp/_utils.py
25
26
27
28
29
30
31
32
33
34
35
36
def buflen_to_varint(buffer: bytes) -> bytes:
    ret = bytearray()
    buflen = len(buffer)
    while True:
        towrite = buflen & 0x7F
        buflen >>= 7
        if buflen > 0:
            towrite |= 0x80
        ret.append(towrite)
        if buflen <= 0:
            break
    return bytes(ret)

isascii(s)

str.isascii() for Python 3.6

Attribution: https://stackoverflow.com/a/18403812

Source code in pyflp/_utils.py
17
18
19
20
21
22
def isascii(s: str) -> bool:
    """str.isascii() for Python 3.6

    Attribution: https://stackoverflow.com/a/18403812
    """
    return len(s) == len(s.encode())