summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2010-02-20 18:09:00 +0000
committerPauli Virtanen <pav@iki.fi>2010-02-20 18:09:00 +0000
commit3243b041ad2f906c4b8e7c7782065bae253869f0 (patch)
treed19956b2e8399439082e6663376d00cb21f09c8d
parentff91dbef61f42479cbe46d4ed841a1fef16f4436 (diff)
downloadnumpy-3243b041ad2f906c4b8e7c7782065bae253869f0.tar.gz
ENH: Add some tools to numpy.compat
-rw-r--r--numpy/compat/_inspect.py2
-rw-r--r--numpy/compat/py3k.py17
2 files changed, 16 insertions, 3 deletions
diff --git a/numpy/compat/_inspect.py b/numpy/compat/_inspect.py
index 8be0b7696..612d1e147 100644
--- a/numpy/compat/_inspect.py
+++ b/numpy/compat/_inspect.py
@@ -7,7 +7,7 @@ no overhead.
import types
-__all__ = ['getarspec', 'formatargspec']
+__all__ = ['getargspec', 'formatargspec']
# ----------------------------------------------------------- type-checking
def ismethod(object):
diff --git a/numpy/compat/py3k.py b/numpy/compat/py3k.py
index b6113b661..534ae4d29 100644
--- a/numpy/compat/py3k.py
+++ b/numpy/compat/py3k.py
@@ -4,23 +4,25 @@ Python 3 compatibility tools.
"""
__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 @@ else:
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)