From d706ed5041f3b8eb90692d72d5e8db1a67cc7200 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Tue, 6 Jan 2015 20:58:33 -0600 Subject: Python: fix python3 support with keywords. --- python/mal_types.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'python/mal_types.py') diff --git a/python/mal_types.py b/python/mal_types.py index 5fb9bba..b1b1b3b 100644 --- a/python/mal_types.py +++ b/python/mal_types.py @@ -1,4 +1,15 @@ import sys, copy, types as pytypes + +# python 3.0 differences +if sys.hexversion > 0x3000000: + def u(x): + return x +else: + import codecs + def u(x): + return codecs.unicode_escape_decode(x)[0] + + if sys.version_info[0] >= 3: str_types = [str] else: @@ -61,9 +72,10 @@ def _symbol_Q(exp): return type(exp) == Symbol # Keywords # A specially prefixed string def _keyword(str): - if str[0] == u"\u029e": return str - else: return u"\u029e" + str -def _keyword_Q(exp): return _string_Q(exp) and exp[0] == u"\u029e" + if str[0] == u("\u029e"): return str + else: return u("\u029e") + str +def _keyword_Q(exp): + return _string_Q(exp) and exp[0] == u("\u029e") # Functions def _function(Eval, Env, ast, env, params): -- cgit v1.2.3