Skip to content

Commit

Permalink
Fixes #300. elegantly this time
Browse files Browse the repository at this point in the history
  • Loading branch information
SpheMakh committed May 20, 2024
1 parent 8083872 commit a377593
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions stimela/backends/flavours/casa.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,12 @@ def get_arguments(self, cab: Cab, params: Dict[str, Any], subst: Dict[str, Any],

# unicode instance only exists in python2, python3 bytes
code = f"""
import sys, json
kwin = json.loads('{params_string}')
try:
utype = unicode
except NameError:
utype = bytes
kw = dict()
for key, val in kwin.items():
# stringify in a loop to avoid isue #300
if isinstance(val, (utype, str)):
x = str(val)
elif isinstance(val, list):
try:
x = list(map(lambda a: str(a) if isinstance(a, (unicode, str)) else a, val))
except NameError:
x = list(map(lambda a: str(a) if isinstance(a, (bytes, str)) else a, val))
else:
x = val
kw[key] = x
import json
from io import StringIO
# cast to string/bytes
stdr = StringIO('{params_string}').read()
kw = json.loads(stdr.encode('ascii', errors='ignore'))
{command}(**kw)
Expand Down

0 comments on commit a377593

Please sign in to comment.