Package xmlschema_acue ::
Module compat
1
2
3
4
5
6
7
8
9
10
11 """
12 This module contains imports and definitions for Python 2 and 3 compatibility.
13 """
14 import sys
15 from collections import OrderedDict
16
17 PY3 = sys.version_info[0] == 3
18
19 if PY3:
20
21 from urllib.request import urlopen, urljoin, urlsplit, pathname2url
22 from urllib.parse import uses_relative, urlparse, urlunsplit
23 from urllib.error import URLError
24 from io import StringIO, BytesIO
25 from collections.abc import Iterable, MutableSet, Sequence, MutableSequence, Mapping, MutableMapping
26 from functools import lru_cache
27
28 long_type = int
29 string_base_type = str
30 unicode_type = str
31 unicode_chr = chr
32
33 else:
34
35 from urllib import pathname2url
36 from urllib2 import urlopen, URLError
37 from urlparse import urlsplit, urljoin, uses_relative, urlparse, urlunsplit
38 from StringIO import StringIO
39 from io import BytesIO
40 from collections import Iterable, MutableSet, Sequence, MutableSequence, Mapping, MutableMapping
41 from functools import wraps
42
43 long_type = long
44 string_base_type = basestring
45 unicode_type = unicode
46 unicode_chr = unichr
49 """
50 A fake lru_cache decorator function for Python 2.7 compatibility until support ends.
51 """
52 def lru_cache_decorator(f):
53 @wraps(f)
54 def wrapper(*args, **kwargs):
55 return f(*args, **kwargs)
56 return wrapper
57 return lru_cache_decorator
58
59
60 ordered_dict_class = dict if sys.version_info >= (3, 6) else OrderedDict
79 return wrapper
80