summaryrefslogtreecommitdiff
path: root/numpy/compat/py3k.py
blob: a75bfebfd76cf8399d3316da9f43771b53d05dcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
Python 3 compatibility tools.

"""

__all__ = ['bytes', 'asbytes', 'isfileobj', 'getexception']

import sys

if sys.version_info[0] >= 3:
    import io
    bytes = bytes
    def asbytes(s):
        if isinstance(s, bytes):
            return s
        return s.encode('iso-8859-1')
    def isfileobj(f):
        return isinstance(f, io.IOBase)
else:
    bytes = str
    asbytes = str
    def isfileobj(f):
        return isinstance(f, file)

def getexception():
    return sys.exc_info()[1]