Created
October 18, 2021 03:10
-
-
Save MestreLion/674261b21ceb96d598d0c8f42f835074 to your computer and use it in GitHub Desktop.
Playing with Enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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