utils.py: move xrange hack to reportlab.__init__, add rl_add_builtins utility py33
authorrobin
Fri, 17 Jan 2014 15:34:41 +0000
branchpy33
changeset 4005 b7dee7fcd927
parent 4004 ebd460ef8d2f
child 4006 028bdf783369
utils.py: move xrange hack to reportlab.__init__, add rl_add_builtins utility
src/reportlab/__init__.py
src/reportlab/lib/utils.py
--- a/src/reportlab/__init__.py	Thu Jan 16 17:02:25 2014 +0000
+++ b/src/reportlab/__init__.py	Fri Jan 17 15:34:41 2014 +0000
@@ -18,6 +18,7 @@
 
     import builtins
     builtins.cmp = cmp
+    builtins.xrange = range
     del cmp, builtins
 else:
     from future_builtins import ascii
--- a/src/reportlab/lib/utils.py	Thu Jan 16 17:02:25 2014 +0000
+++ b/src/reportlab/lib/utils.py	Fri Jan 17 15:34:41 2014 +0000
@@ -124,7 +124,6 @@
         return s.encode('latin1') if isinstance(s,str) else s
     import builtins
     rl_exec = getattr(builtins,'exec')
-    builtins.xrange = range
     del builtins
     def char2int(s):
         return  s if isinstance(s,int) else ord(s if isinstance(s,str) else s.decode('latin1'))
@@ -132,7 +131,10 @@
         if v.__traceback__ is not b:
             raise v.with_traceback(b)
         raise v
-
+    def rl_add_builtins(**kwd):
+        import builtins
+        for k,v in kwd.items():
+            setattr(builtins,k,v)
 else:
     bytesT = str
     unicodeT = unicode
@@ -228,6 +230,10 @@
     rl_exec("""def rl_reraise(t, v, b=None):\n\traise t, v, b\n""")
 
     char2int = ord
+    def rl_add_builtins(**kwd):
+        import __builtin__
+        for k,v in kwd.items():
+            setattr(__builtin__,k,v)
 
 def zipImported(ldr=None):
     try: