forked from psyplot/psyplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpycompat.py
More file actions
executable file
·119 lines (98 loc) · 3.22 KB
/
pycompat.py
File metadata and controls
executable file
·119 lines (98 loc) · 3.22 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""Compatibility module for different python versions"""
# Disclaimer
# ----------
#
# Copyright (C) 2021 Helmholtz-Zentrum Hereon
# Copyright (C) 2020-2021 Helmholtz-Zentrum Geesthacht
# Copyright (C) 2016-2021 University of Lausanne
#
# This file is part of psyplot and is released under the GNU LGPL-3.O license.
# See COPYING and COPYING.LESSER in the root of the repository for full
# licensing details.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3.0 as
# published by the Free Software Foundation.
#
# This program 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 LGPL-3.0 license for more details.
#
# You should have received a copy of the GNU LGPL-3.0 license
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import six
import inspect
if six.PY3:
class DictMethods(object):
@staticmethod
def iteritems(d):
return iter(dict.items(d))
@staticmethod
def itervalues(d):
return iter(dict.values(d))
@staticmethod
def iterkeys(d):
return iter(dict.keys(d))
def getcwd(*args, **kwargs):
return os.getcwd(*args, **kwargs)
def get_default_value(func, arg):
argspec = inspect.getfullargspec(func)
return next(default for a, default in zip(reversed(argspec[0]),
reversed(argspec.defaults))
if a == arg)
basestring = str
unicode_type = str
bytes_type = bytes
range = range
zip = zip
filter = filter
map = map
from functools import reduce
from itertools import filterfalse
import builtins
from queue import Queue
elif six.PY2:
# Python 2
class DictMethods(object):
"""okay"""
@staticmethod
def iteritems(d):
"checked"
return dict.iteritems(d)
@staticmethod
def itervalues(d):
return dict.itervalues(d)
@staticmethod
def iterkeys(d):
return dict.iterkeys(d)
def getcwd(*args, **kwargs):
return os.getcwdu(*args, **kwargs)
def get_default_value(func, arg):
argspec = inspect.getargspec(func)
return next(default for a, default in zip(reversed(argspec[0]),
reversed(argspec.defaults))
if a == arg)
basestring = basestring
unicode_type = unicode
bytes_type = str
range = xrange
from itertools import (izip as zip, imap as map, ifilter as filter,
ifilterfalse as filterfalse)
reduce = reduce
import __builtin__ as builtins
from Queue import Queue
try:
from cyordereddict import OrderedDict
except ImportError:
try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict
try:
from collections import UserDict
except ImportError:
from UserDict import IterableUserDict as UserDict
def isstring(s):
return isinstance(s, six.string_types)