move utils.py builtins defs to __init__.py py33
authorrobin
Thu, 21 Nov 2013 17:32:50 +0000
branchpy33
changeset 3820 47edc5ad9dc6
parent 3819 fc8a0ae06c14
child 3821 26e3d1fac3f7
move utils.py builtins defs to __init__.py
src/reportlab/__init__.py
src/reportlab/lib/utils.py
--- a/src/reportlab/__init__.py	Thu Nov 21 14:53:59 2013 +0000
+++ b/src/reportlab/__init__.py	Thu Nov 21 17:32:50 2013 +0000
@@ -43,3 +43,18 @@
     import reportlab.monitor
     mon = reportlab.monitor.ReportLabToolkitMonitor()
     return mon
+
+#define these early in reportlab's life
+isPy3 = sys.version_info[0]==3
+if isPy3:
+    def cmp(a,b):
+        return -1 if a<b else (1 if a>b else 0)
+
+    import builtins
+    builtins.cmp = cmp
+    del cmp, builtins
+else:
+    from future_builtins import ascii
+    import __builtin__
+    __builtin__.ascii = ascii
+    del ascii, __builtins__
--- a/src/reportlab/lib/utils.py	Thu Nov 21 14:53:59 2013 +0000
+++ b/src/reportlab/lib/utils.py	Thu Nov 21 17:32:50 2013 +0000
@@ -7,6 +7,7 @@
 import os, sys, imp, time
 import base64
 import pickle
+from reportlab import isPy3
 from reportlab.lib.logger import warnOnce
 from reportlab.lib.rltempfile import get_rl_tempfile, get_rl_tempdir, _rl_getuid
 
@@ -15,8 +16,6 @@
 except ImportError:
     import md5
 
-isPy3 = sys.version_info[0]==3
-
 def isFunction(v):
     return type(v) == type(isFunction)
 
@@ -68,13 +67,6 @@
             return x
         else:
             return str(x).encode(enc)
-
-    def cmp(a,b):
-        return -1 if a<b else (1 if a>b else 0)
-
-    import builtins
-    builtins.cmp = cmp
-    del builtins
 else:
     if sys.hexversion >= 0x02000000:
         def _digester(s):
@@ -98,10 +90,6 @@
     def isClass(v):
         import types
         return isinstance(v, types.ClassType)
-    from string import letters as ascii_letters, uppercase as ascii_uppercase, lowercase as ascii_lowercase
-    from future_builtins import ascii
-    import __builtin__
-    __builtin__.ascii = ascii
     int2byte = chr
     from StringIO import StringIO
 
@@ -118,7 +106,7 @@
             return x
         else:
             return str(x).encode(enc)
-    del __builtins__
+    from string import letters as ascii_letters, uppercase as ascii_uppercase, lowercase as ascii_lowercase
 
 def _findFiles(dirList,ext='.ttf'):
     from os.path import isfile, isdir, join as path_join