* Fixed compatibility with Python 2.6. (Closes Issue #53)
This commit is contained in:
parent
8c145f0512
commit
c57a912305
12
pylast.py
12
pylast.py
|
@ -33,7 +33,7 @@ import tempfile
|
||||||
import sys
|
import sys
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
if sys.version_info.major == 3:
|
if sys.version_info[0] == 3:
|
||||||
from http.client import HTTPConnection
|
from http.client import HTTPConnection
|
||||||
import html.entities as htmlentitydefs
|
import html.entities as htmlentitydefs
|
||||||
from urllib.parse import splithost as url_split_host
|
from urllib.parse import splithost as url_split_host
|
||||||
|
@ -41,7 +41,7 @@ if sys.version_info.major == 3:
|
||||||
|
|
||||||
unichr = chr
|
unichr = chr
|
||||||
|
|
||||||
elif sys.version_info.major == 2:
|
elif sys.version_info[0] == 2:
|
||||||
from httplib import HTTPConnection
|
from httplib import HTTPConnection
|
||||||
import htmlentitydefs
|
import htmlentitydefs
|
||||||
from urllib import splithost as url_split_host
|
from urllib import splithost as url_split_host
|
||||||
|
@ -3390,13 +3390,13 @@ def md5(text):
|
||||||
return h.hexdigest()
|
return h.hexdigest()
|
||||||
|
|
||||||
def _unicode(text):
|
def _unicode(text):
|
||||||
if sys.version_info.major == 3:
|
if sys.version_info[0] == 3:
|
||||||
if type(text) in (bytes, bytearray):
|
if type(text) in (bytes, bytearray):
|
||||||
return str(text, "utf-8")
|
return str(text, "utf-8")
|
||||||
else:
|
else:
|
||||||
return str(text)
|
return str(text)
|
||||||
|
|
||||||
elif sys.version_info.major ==2:
|
elif sys.version_info[0] ==2:
|
||||||
if type(text) in (str,):
|
if type(text) in (str,):
|
||||||
return unicode(text, "utf-8")
|
return unicode(text, "utf-8")
|
||||||
else:
|
else:
|
||||||
|
@ -3405,13 +3405,13 @@ def _unicode(text):
|
||||||
def _string(text):
|
def _string(text):
|
||||||
"""For Python2 routines that can only process str type."""
|
"""For Python2 routines that can only process str type."""
|
||||||
|
|
||||||
if sys.version_info.major == 3:
|
if sys.version_info[0] == 3:
|
||||||
if type(text) != str:
|
if type(text) != str:
|
||||||
return str(text)
|
return str(text)
|
||||||
else:
|
else:
|
||||||
return text
|
return text
|
||||||
|
|
||||||
elif sys.version_info.major == 2:
|
elif sys.version_info[0] == 2:
|
||||||
if type(text) == str:
|
if type(text) == str:
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue