[Numpy-svn] r8181 - trunk/numpy/compat

numpy-svn@scip... numpy-svn@scip...
Sat Feb 20 12:17:51 CST 2010


Author: ptvirtan
Date: 2010-02-20 12:17:51 -0600 (Sat, 20 Feb 2010)
New Revision: 8181

Modified:
   trunk/numpy/compat/py3k.py
Log:
ENH: compat: additional Py3 convenience functions

Modified: trunk/numpy/compat/py3k.py
===================================================================
--- trunk/numpy/compat/py3k.py	2010-02-20 18:17:29 UTC (rev 8180)
+++ trunk/numpy/compat/py3k.py	2010-02-20 18:17:51 UTC (rev 8181)
@@ -4,7 +4,8 @@
 """
 
 __all__ = ['bytes', 'asbytes', 'isfileobj', 'getexception', 'strchar',
-           'unicode', 'asunicode', 'asbytes_nested', 'asunicode_nested']
+           'unicode', 'asunicode', 'asbytes_nested', 'asunicode_nested',
+           'asstr']
 
 import sys
 
@@ -16,7 +17,11 @@
     def asbytes(s):
         if isinstance(s, bytes):
             return s
-        return s.encode('iso-8859-1')
+        return s.encode('latin1')
+    def asstr(s):
+        if isinstance(s, str):
+            return s
+        return bytes.decode('latin1')
     def isfileobj(f):
         return isinstance(f, io.FileIO)
     strchar = 'U'
@@ -24,13 +29,14 @@
     bytes = str
     unicode = unicode
     asbytes = str
+    asstr = str
     strchar = 'S'
     def isfileobj(f):
         return isinstance(f, file)
     def asunicode(s):
         if isinstance(s, unicode):
             return s
-        return s.decode('iso-8859-1')
+        return s.decode('ascii')
 
 def getexception():
     return sys.exc_info()[1]



More information about the Numpy-svn mailing list