X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=misc%2Finfrastructure%2Fpython%2Fslist%2Futils.py;fp=misc%2Finfrastructure%2Fpython%2Fslist%2Futils.py;h=1cc36aa12c97176ea94498dd07fd8473bc9d7738;hb=72b221162ffe304baa3c226d9156df7a3d61cc72;hp=0000000000000000000000000000000000000000;hpb=5e4dcf48e4385bd4b125f5aefc99e1787bfe54fc;p=xonotic%2Fxonotic.git diff --git a/misc/infrastructure/python/slist/utils.py b/misc/infrastructure/python/slist/utils.py new file mode 100644 index 00000000..1cc36aa1 --- /dev/null +++ b/misc/infrastructure/python/slist/utils.py @@ -0,0 +1,31 @@ +from functools import wraps +from typing import * + +UTF_8 = "utf-8" + + +class Readable: + @classmethod + def decode(cls) -> Generator[Optional[object], bytes, None]: + raise NotImplementedError + + +class Writable: + def encode(self) -> bytes: + raise NotImplementedError + + +def generator(f): + O = TypeVar("O") + I = TypeVar("I") + R = TypeVar("R") + + def prepare(g: Generator[O, I, R]) -> Generator[O, I, R]: + next(g) + return g + + @wraps(f) + def w(*args, **kwargs): + return prepare(f(*args, **kwargs)) + + return w