File: compat.py

package info (click to toggle)
python-petl 1.7.17-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,224 kB
  • sloc: python: 22,617; makefile: 109; xml: 9
file content (72 lines) | stat: -rw-r--r-- 1,730 bytes parent folder | download | duplicates (2)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from __future__ import absolute_import, print_function, division


import sys



##########################
# Python 3 compatibility #
##########################

PY2 = sys.version_info.major == 2
PY3 = sys.version_info.major == 3

if PY2:
    from itertools import ifilter, ifilterfalse, imap, izip, izip_longest
    from string import maketrans
    from decimal import Decimal
    string_types = basestring,
    integer_types = int, long
    numeric_types = bool, int, long, float, Decimal
    text_type = unicode
    binary_type = str
    from urllib2 import urlopen
    try:
        from cStringIO import StringIO
    except ImportError:
        from StringIO import StringIO
    BytesIO = StringIO
    try:
        import cPickle as pickle
    except ImportError:
        import pickle
    maxint = sys.maxint
    long = long
    xrange = xrange
    reduce = reduce

else:
    ifilter = filter
    imap = map
    izip = zip
    xrange = range
    from decimal import Decimal
    from itertools import filterfalse as ifilterfalse
    from itertools import zip_longest as izip_longest
    from functools import reduce
    maketrans = str.maketrans
    string_types = str,
    integer_types = int,
    numeric_types = bool, int, float, Decimal
    class_types = type,
    text_type = str
    binary_type = bytes
    long = int
    from urllib.request import urlopen
    from io import StringIO, BytesIO
    import pickle
    maxint = sys.maxsize

try:
    advance_iterator = next
except NameError:
    def advance_iterator(it):
        return it.next()
next = advance_iterator

try:
    callable = callable
except NameError:
    def callable(obj):
        return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)