Skip to content

Instantly share code, notes, and snippets.

@MestreLion
Created October 18, 2021 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MestreLion/674261b21ceb96d598d0c8f42f835074 to your computer and use it in GitHub Desktop.
Save MestreLion/674261b21ceb96d598d0c8f42f835074 to your computer and use it in GitHub Desktop.
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