[Numpy-svn] r8150 - trunk/numpy/compat
numpy-svn at scipy.org
numpy-svn at scipy.org
Sat Feb 20 13:09:00 EST 2010
Author: ptvirtan
Date: 2010-02-20 12:09:00 -0600 (Sat, 20 Feb 2010)
New Revision: 8150
Modified:
trunk/numpy/compat/_inspect.py
trunk/numpy/compat/py3k.py
Log:
ENH: Add some tools to numpy.compat
Modified: trunk/numpy/compat/_inspect.py
===================================================================
--- trunk/numpy/compat/_inspect.py 2010-02-20 18:08:44 UTC (rev 8149)
+++ trunk/numpy/compat/_inspect.py 2010-02-20 18:09:00 UTC (rev 8150)
@@ -7,7 +7,7 @@
import types
-__all__ = ['getarspec', 'formatargspec']
+__all__ = ['getargspec', 'formatargspec']
# ----------------------------------------------------------- type-checking
def ismethod(object):
Modified: trunk/numpy/compat/py3k.py
===================================================================
--- trunk/numpy/compat/py3k.py 2010-02-20 18:08:44 UTC (rev 8149)
+++ trunk/numpy/compat/py3k.py 2010-02-20 18:09:00 UTC (rev 8150)
@@ -4,23 +4,25 @@
"""
__all__ = ['bytes', 'asbytes', 'isfileobj', 'getexception', 'strchar',
- 'asunicode']
+ 'unicode', 'asunicode', 'asbytes_nested', 'asunicode_nested']
import sys
if sys.version_info[0] >= 3:
import io
bytes = bytes
+ unicode = str
+ asunicode = str
def asbytes(s):
if isinstance(s, bytes):
return s
return s.encode('iso-8859-1')
- asunicode = str
def isfileobj(f):
return isinstance(f, io.IOBase)
strchar = 'U'
else:
bytes = str
+ unicode = unicode
asbytes = str
strchar = 'S'
def isfileobj(f):
@@ -33,3 +35,14 @@
def getexception():
return sys.exc_info()[1]
+def asbytes_nested(x):
+ if hasattr(x, '__iter__') and not isinstance(x, (bytes, unicode)):
+ return [asbytes_nested(y) for y in x]
+ else:
+ return asbytes(x)
+
+def asunicode_nested(x):
+ if hasattr(x, '__iter__') and not isinstance(x, (bytes, unicode)):
+ return [asunicode_nested(y) for y in x]
+ else:
+ return asunicode(x)
More information about the Numpy-svn
mailing list