]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - misc/infrastructure/python/slist/utils.py
slist: init
[xonotic/xonotic.git] / misc / infrastructure / python / slist / utils.py
diff --git a/misc/infrastructure/python/slist/utils.py b/misc/infrastructure/python/slist/utils.py
new file mode 100644 (file)
index 0000000..1cc36aa
--- /dev/null
@@ -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