Mercurial > repos > shellac > sam_consensus_v3
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/env/lib/python3.9/site-packages/galaxy/util/tool_shed/encoding_util.py Mon Mar 22 18:12:50 2021 +0000 @@ -0,0 +1,41 @@ +import binascii +import json + +from galaxy.util import ( + smart_str, + unicodify +) +from galaxy.util.hash_util import hmac_new + + +encoding_sep = '__esep__' +encoding_sep2 = '__esepii__' + + +def tool_shed_decode(value): + # Extract and verify hash + value = unicodify(value) + a, b = value.split(":") + value = binascii.unhexlify(b) + test = hmac_new(b'ToolShedAndGalaxyMustHaveThisSameKey', value) + assert a == test + # Restore from string + values = None + value = unicodify(value) + try: + values = json.loads(value) + except Exception: + pass + if values is None: + values = value + return values + + +def tool_shed_encode(val): + if isinstance(val, dict) or isinstance(val, list): + value = json.dumps(val) + else: + value = val + a = hmac_new(b'ToolShedAndGalaxyMustHaveThisSameKey', value) + b = unicodify(binascii.hexlify(smart_str(value))) + return f"{a}:{b}"