-
Notifications
You must be signed in to change notification settings - Fork 41
/
test.py
52 lines (38 loc) · 2.17 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Copyright © 2014 Eduard Tomasek <???>
This work is free. You can redistribute it and/or modify it under the
terms of the Do What The Fuck You Want To Public License, Version 2,
as published by Sam Hocevar. See the COPYING file for more details.
"""
import json
import lzstring
import pprint
if __name__ == '__main__':
x = lzstring.LZString()
s = 'Žluťoučký kůň úpěl ďábelské ódy!'
# generated with original js lib
jsLzStringBase64 = 'r6ABsK6KaAD2aLCADWBfgBPQ9oCAlAZAvgDobEARlB4QAEOAjAUxAGd4BL5AZ4BMBPAQiAAA'
jsLzStringBase64Json = 'N4Ig5gNg9gzjCGAnAniAXKALgS0xApuiPgB7wC2ADgQASSwIogA0IA4tHACLYBu6WXASIBlFu04wAMthiYBEhgFEAdpiYYQASS6i2AWSniRURJgCCMPYfEcGAFXyJyozPBUATJB5pt8Kp3gIbAAvfB99JABrAFdKGil3MBj4MEJWcwBjRCgVZBc0EBEDIwyAIzLEfH5CrREAeRoADiaAdgBONABGdqaANltJLnwAMwVKJHgicxpyfDcAWnJouJoIJJS05hoYmHCaTCgabPx4THxZlfj1lWTU/BgaGBjMgAsaeEeuKEyAISgoFEAHSDBgifD4cwQGBQdAAbXYNlYAA0bABdAC+rDscHBhEKy0QsUoIAxZLJQAAA=='
print('String for encode: ' + s)
print()
print('Compress to base64:')
base2 = x.compressToBase64(s)
print('result: ' + base2)
print('result js: ' + jsLzStringBase64)
print('equals: ' + str(base2 == jsLzStringBase64))
print()
print('Decompress from base64:')
print('result: ' + x.decompresFromBase64(base2))
print('result from js: ' + x.decompresFromBase64(jsLzStringBase64))
print()
jsonString = '{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}}'
print('Compress json to base64:')
jresult = x.compressToBase64(jsonString)
print('result: ' + jresult)
print()
print('result js: ' + jsLzStringBase64Json)
print()
print('equals: ' + str(jresult == jsLzStringBase64Json))
print()
print('Decompress json from base64:')
pprint.pprint(json.loads(x.decompresFromBase64(jsLzStringBase64Json)))