aboutsummaryrefslogtreecommitdiff
path: root/python/mal_types.py
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2015-01-06 20:58:33 -0600
committerJoel Martin <github@martintribe.org>2015-01-09 16:16:56 -0600
commitd706ed5041f3b8eb90692d72d5e8db1a67cc7200 (patch)
treefa21d063ea63efb56dbd6fd0e3a247a87ae96bfd /python/mal_types.py
parent47930f746366d5730170e817ad233e8c3e020270 (diff)
downloadmal-d706ed5041f3b8eb90692d72d5e8db1a67cc7200.tar.gz
mal-d706ed5041f3b8eb90692d72d5e8db1a67cc7200.zip
Python: fix python3 support with keywords.
Diffstat (limited to 'python/mal_types.py')
-rw-r--r--python/mal_types.py18
1 files changed, 15 insertions, 3 deletions
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):