Guest User

Untitled

a guest
Jun 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #!/bin/python3
  2. # made by Lonami - lonamiwebs.github.io
  3. import zlib
  4. import json
  5. from sys import argv
  6. from io import BytesIO
  7. from base64 import b64decode, b64encode
  8.  
  9.  
  10. def decode(blueprint, out=dict):
  11. string = zlib.decompress(b64decode(blueprint.encode('ascii')[1:]))
  12. if out == dict:
  13. return json.loads(string)
  14. elif out == str:
  15. return string.decode('utf-8')
  16. elif out == bytes:
  17. return string
  18. elif callable(out):
  19. return out(json.dumps(json.loads(string), indent=2, sort_keys=True))
  20. else:
  21. raise TypeError('out must be dict, str, bytes or callable')
  22.  
  23.  
  24. def encode(data):
  25. if isinstance(data, dict):
  26. data = json.dumps(data).encode('utf-8')
  27. elif isinstance(data, str):
  28. data = data.encode('utf-8')
  29. elif not isinstance(data, bytes):
  30. raise TypeError('data must be dict, str or bytes')
  31. return '0' + b64encode(zlib.compress(data)).decode('ascii')
  32.  
  33.  
  34. __all__ = ['decode', 'encode']
  35.  
  36.  
  37. if __name__ == '__main__':
  38. for blueprint in argv[1:]:
  39. if '{' in blueprint:
  40. print(encode(blueprint))
  41. else:
  42. decode(blueprint, print)
Add Comment
Please, Sign In to add comment