diff options
author | Jason Gross <jgross@mit.edu> | 2017-11-10 12:18:07 -0500 |
---|---|---|
committer | Jason Gross <jgross@mit.edu> | 2017-11-10 12:18:07 -0500 |
commit | a5fc7539c5688190f7622266c8e0959efbca80be (patch) | |
tree | 2c6d62df349ec19ae283cf5994853b54f83e1629 /src/Specific/Framework | |
parent | 4758761b669078acb85e9071c05f546e5b2f0f13 (diff) |
Update make_curve.py for python3
In python2, we require unicode. In python3, "unicode" as a type doesn't
exist. In most places, we can replace the isinstance check for
str/unicode with basestring. In one place where we need to output
unicode, we do a terrible hack to set unicode to str if it doesn't
exist.
Diffstat (limited to 'src/Specific/Framework')
-rwxr-xr-x | src/Specific/Framework/make_curve.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/Specific/Framework/make_curve.py b/src/Specific/Framework/make_curve.py index b652090b8..0581a58e1 100755 --- a/src/Specific/Framework/make_curve.py +++ b/src/Specific/Framework/make_curve.py @@ -176,7 +176,7 @@ def format_c_code(header, code, numargs, sz, indent=' ', closing_indent=' def nested_list_to_string(v): if isinstance(v, bool): return {True:'true', False:'false'}[v] - elif isinstance(v, str) or isinstance(v, int) or isinstance(v, unicode): + elif isinstance(v, basestring) or isinstance(v, int): return str(v) elif isinstance(v, list): return '[%s]' % '; '.join(map(nested_list_to_string, v)) @@ -187,13 +187,13 @@ def nested_list_to_string(v): assert(False) def as_bool(v): - if isinstance(v, str) or isinstance(v, unicode): return {'true':True, 'false':False}[v] + if isinstance(v, basestring): return {'true':True, 'false':False}[v] if isinstance(v, bool): return v raise Exception('Not a bool: %s' % repr(v)) def make_curve_parameters(parameters): def fix_option(term, scope_string=''): - if not isinstance(term, str) and not isinstance(term, unicode): + if not isinstance(term, basestring): return term if term[:len('Some ')] != 'Some ' and term != 'None': if ' ' in term and (term[0] + term[-1]) not in ('()', '[]'): @@ -470,7 +470,11 @@ DONT_EDIT_HEADERS = { '.py' : '# ' + DONT_EDIT_STR.replace('\n', '\n# '), } - +# in python3, unicode doesn't exist, so we replace it +try: + unicode +except NameError: + unicode = str def main(*args): if '--help' in args[1:] or '-h' in args[1:]: usage(0) |