Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Playing with Enum
import enum, gzip, zlib
class Compression(enum.IntEnum):
GZIP = 1 # GZip (RFC1952) (unused in practice)
ZLIB = 2 # Zlib (RFC1950)
NONE = 3 # Uncompressed. Mentioned in the wiki, but unused in practice
_compress = {
NONE: lambda _: _,
GZIP: gzip.compress,
ZLIB: zlib.compress,
}
_decompress = {
NONE: lambda _: _,
GZIP: gzip.decompress,
ZLIB: zlib.decompress,
}
def compress(self): return self._compress[self]
def decompress(self): return self._decompress[self]
compression = 0
if compression not in Compression:
print("not found!")
print(Compression(1).compress)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment