Skip to content

Instantly share code, notes, and snippets.

Created October 18, 2021 03:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment