Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Liu Qianqiao
Text_Analysis
Commits
eebeeeda
Commit
eebeeeda
authored
Feb 19, 2020
by
Liu Qianqiao
Browse files
initial commit
parent
5b34e9f0
Changes
1
Hide whitespace changes
Inline
Side-by-side
compat.py
0 → 100644
View file @
eebeeeda
"""
Compatibility layer for Python 3/Python 2 single codebase
"""
import
sys
import
hashlib
if
sys
.
version_info
[
0
]
==
3
:
import
pickle
import
io
import
urllib
_basestring
=
str
cPickle
=
pickle
StringIO
=
io
.
StringIO
BytesIO
=
io
.
BytesIO
_urllib
=
urllib
izip
=
zip
def
md5_hash
(
string
):
m
=
hashlib
.
md5
()
m
.
update
(
string
.
encode
(
'utf-8'
))
return
m
.
hexdigest
()
else
:
import
cPickle
import
StringIO
import
urllib
import
urllib2
import
urlparse
import
types
import
itertools
_basestring
=
basestring
cPickle
=
cPickle
StringIO
=
BytesIO
=
StringIO
.
StringIO
izip
=
itertools
.
izip
class
_module_lookup
(
object
):
modules
=
[
urlparse
,
urllib2
,
urllib
]
def
__getattr__
(
self
,
name
):
for
module
in
self
.
modules
:
if
hasattr
(
module
,
name
):
attr
=
getattr
(
module
,
name
)
if
not
isinstance
(
attr
,
types
.
ModuleType
):
return
attr
raise
NotImplementedError
(
'This function has not been imported properly'
)
module_lookup
=
_module_lookup
()
class
_urllib
():
request
=
module_lookup
error
=
module_lookup
parse
=
module_lookup
def
md5_hash
(
string
):
m
=
hashlib
.
md5
()
m
.
update
(
string
)
return
m
.
hexdigest
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment