1
1
from __future__ import unicode_literals
2
-
3
- from builtins import str
4
- from past .builtins import basestring
5
2
import hashlib
3
+ import sys
4
+
5
+ if sys .version_info .major == 2 :
6
+ # noinspection PyUnresolvedReferences,PyShadowingBuiltins
7
+ str = unicode
8
+
9
+
10
+ # `past.builtins.basestring` module can't be imported on Python3 in some environments (Ubuntu).
11
+ # This code is copy-pasted from it to avoid crashes.
12
+ class BaseBaseString (type ):
13
+ def __instancecheck__ (cls , instance ):
14
+ return isinstance (instance , (bytes , str ))
15
+
16
+ def __subclasshook__ (cls , thing ):
17
+ # TODO: What should go here?
18
+ raise NotImplemented
19
+
20
+
21
+ def with_metaclass (meta , * bases ):
22
+ class metaclass (meta ):
23
+ __call__ = type .__call__
24
+ __init__ = type .__init__
25
+
26
+ def __new__ (cls , name , this_bases , d ):
27
+ if this_bases is None :
28
+ return type .__new__ (cls , name , (), d )
29
+ return meta (name , bases , d )
30
+
31
+ return metaclass ('temporary_class' , None , {})
32
+
33
+
34
+ if sys .version_info .major >= 3 :
35
+ class basestring (with_metaclass (BaseBaseString )):
36
+ pass
37
+ else :
38
+ # noinspection PyUnresolvedReferences,PyCompatibility
39
+ from builtins import basestring
6
40
7
41
8
42
def _recursive_repr (item ):
@@ -27,6 +61,7 @@ def get_hash(item):
27
61
repr_ = _recursive_repr (item ).encode ('utf-8' )
28
62
return hashlib .md5 (repr_ ).hexdigest ()
29
63
64
+
30
65
def get_hash_int (item ):
31
66
return int (get_hash (item ), base = 16 )
32
67
0 commit comments