1
1
from __future__ import unicode_literals
2
2
from builtins import str
3
- from past .builtins import basestring
4
3
import hashlib
5
4
import sys
6
5
7
6
8
- if sys .version_info .major == 2 :
9
- # noinspection PyUnresolvedReferences,PyShadowingBuiltins
10
- str = str
11
-
12
- try :
13
- from collections .abc import Iterable
14
- except ImportError :
15
- from collections import Iterable
16
-
17
-
18
- # `past.builtins.basestring` module can't be imported on Python3 in some environments (Ubuntu).
19
- # This code is copy-pasted from it to avoid crashes.
20
- class BaseBaseString (type ):
21
- def __instancecheck__ (cls , instance ):
22
- return isinstance (instance , (bytes , str ))
23
-
24
- def __subclasshook__ (cls , thing ):
25
- # TODO: What should go here?
26
- raise NotImplemented
27
-
28
-
29
7
def with_metaclass (meta , * bases ):
30
8
class metaclass (meta ):
31
9
__call__ = type .__call__
@@ -39,25 +17,13 @@ def __new__(cls, name, this_bases, d):
39
17
return metaclass ('temporary_class' , None , {})
40
18
41
19
42
- if sys .version_info .major >= 3 :
43
-
44
- class basestring (with_metaclass (BaseBaseString )):
45
- pass
46
-
47
- else :
48
- # noinspection PyUnresolvedReferences,PyCompatibility
49
- from builtins import basestring
50
-
51
-
52
20
def _recursive_repr (item ):
53
21
"""Hack around python `repr` to deterministically represent dictionaries.
54
22
55
23
This is able to represent more things than json.dumps, since it does not require
56
24
things to be JSON serializable (e.g. datetimes).
57
25
"""
58
- if isinstance (item , basestring ):
59
- result = str (item )
60
- elif isinstance (item , list ):
26
+ if isinstance (item , list ):
61
27
result = '[{}]' .format (', ' .join ([_recursive_repr (x ) for x in item ]))
62
28
elif isinstance (item , dict ):
63
29
kv_pairs = [
0 commit comments