Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/galaxy/util/tool_shed/encoding_util.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 import binascii | |
2 import json | |
3 | |
4 from galaxy.util import ( | |
5 smart_str, | |
6 unicodify | |
7 ) | |
8 from galaxy.util.hash_util import hmac_new | |
9 | |
10 | |
11 encoding_sep = '__esep__' | |
12 encoding_sep2 = '__esepii__' | |
13 | |
14 | |
15 def tool_shed_decode(value): | |
16 # Extract and verify hash | |
17 value = unicodify(value) | |
18 a, b = value.split(":") | |
19 value = binascii.unhexlify(b) | |
20 test = hmac_new(b'ToolShedAndGalaxyMustHaveThisSameKey', value) | |
21 assert a == test | |
22 # Restore from string | |
23 values = None | |
24 value = unicodify(value) | |
25 try: | |
26 values = json.loads(value) | |
27 except Exception: | |
28 pass | |
29 if values is None: | |
30 values = value | |
31 return values | |
32 | |
33 | |
34 def tool_shed_encode(val): | |
35 if isinstance(val, dict) or isinstance(val, list): | |
36 value = json.dumps(val) | |
37 else: | |
38 value = val | |
39 a = hmac_new(b'ToolShedAndGalaxyMustHaveThisSameKey', value) | |
40 b = unicodify(binascii.hexlify(smart_str(value))) | |
41 return f"{a}:{b}" |