summaryrefslogtreecommitdiff
path: root/gi/_compat.py
blob: 00f5fbb3612ae9ee47e15888ffc8a7890bee9d39 (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
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
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, see <http://www.gnu.org/licenses/>.

import sys

PY2 = PY3 = False
if sys.version_info[0] == 2:
    PY2 = True

    from StringIO import StringIO
    StringIO

    from UserList import UserList
    UserList

    long_ = eval("long")
    integer_types = eval("(int, long)")
    string_types = eval("(basestring,)")
    text_type = eval("unicode")

    reload = eval("reload")
    xrange = eval("xrange")
    cmp = eval("cmp")

    exec("def reraise(tp, value, tb):\n raise tp, value, tb")
else:
    PY3 = True

    from io import StringIO
    StringIO

    from collections import UserList
    UserList

    long_ = int
    integer_types = (int,)
    string_types = (str,)
    text_type = str

    from importlib import reload
    reload
    xrange = range
    cmp = lambda a, b: (a > b) - (a < b)

    def reraise(tp, value, tb):
        raise tp(value).with_traceback(tb)