Created
March 15, 2019 12:44
-
-
Save dungwinux/969c7bbd1ecacb10a0b6aa528ec65afb to your computer and use it in GitHub Desktop.
Encode and decode Themis config files
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 zlib | |
from sys import argv | |
def decode(s): | |
dec = zlib.decompress(s) | |
res = dec.decode("utf-8") | |
return res | |
def encode(s): | |
enc = zlib.compress(s) | |
return enc | |
if __name__ == "__main__": | |
with open(argv[1], "rb") as fi: | |
s = fi.read() | |
if argv[1][-4:] == ".xml": | |
out = encode(s) | |
with open(argv[1][:-4], "wb") as fo: | |
fo.write(out) | |
else: | |
out = decode(s) | |
with open(argv[1] + ".xml", "w", encoding="utf-8") as fo: | |
fo.write(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit to @TrungNguyen1909 for the idea.