Files
galaxy/lib/tool_shed/util/encoding_util.py
T
Nicola Soranzo 21b44bf348 Fix all E201 and E202 style errors
using the following command:
```
autopep8 -i -r --exclude $(sed -e 's|^|./|' -e 's|/$||' .ci/flake8_blacklist.txt | paste -sd,) --select E201,E202 .
```
2017-08-17 11:35:39 +01:00

38 lines
846 B
Python

import binascii
import json
import logging
from galaxy.util.hash_util import hmac_new
log = logging.getLogger(__name__)
encoding_sep = '__esep__'
encoding_sep2 = '__esepii__'
def tool_shed_decode(value):
# Extract and verify hash
a, b = value.split(":")
value = binascii.unhexlify(b)
test = hmac_new('ToolShedAndGalaxyMustHaveThisSameKey', value)
assert a == test
# Restore from string
values = None
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('ToolShedAndGalaxyMustHaveThisSameKey', value)
b = binascii.hexlify(value)
return "%s:%s" % (a, b)