mailr20790 - /trunk/compat.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on September 04, 2013 - 10:37:
Author: bugman
Date: Wed Sep  4 10:37:19 2013
New Revision: 20790

URL: http://svn.gna.org/viewcvs/relax?rev=20790&view=rev
Log:
Defined two new functions called u() in the compat module for better unicode 
string support.

The two functions are defined differently for Python2 and Python3.  The 
Python3 function simply
returns the text unmodified, as all strings are unicode.  The Python2 
function converts the str
type to a unicode type.


Modified:
    trunk/compat.py

Modified: trunk/compat.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/compat.py?rev=20790&r1=20789&r2=20790&view=diff
==============================================================================
--- trunk/compat.py (original)
+++ trunk/compat.py Wed Sep  4 10:37:19 2013
@@ -349,8 +349,30 @@
         else:
             os.devnull = None
 
+    # Unicode string handling.
+    from codecs import unicode_escape_decode
+    def u(text):
+        """Create a unicode string for Python 2.
+
+        @param text:    The text to convert.
+        @type text:     str
+        @return:        The text converted to unicode.
+        @rtype:         unicode
+        """
+
+        return unicode_escape_decode(text)[0]
+
 
 # Python 3 work-arounds.
 if PY_VERSION == 3:
-    # The unicode conversion function - essential for the GUI in Python 2.
-    builtins.unicode = builtins.str
+    # Unicode string handling.
+    def u(text):
+        """Create a unicode string for Python 3.
+
+        @param text:    The text to convert.
+        @type text:     str
+        @return:        The unmodified text, as all strings in Python 3 are 
unicode and the unicode type does not exist.
+        @rtype:         str
+        """
+
+        return text




Related Messages


Powered by MHonArc, Updated Wed Sep 04 11:00:02 2013