Fix convertion error on Py3 and use_unicode=False
This commit is contained in:
@@ -161,6 +161,8 @@ def convert_datetime(obj):
|
|||||||
True
|
True
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if not PY2 and isinstance(obj, (bytes, bytearray)):
|
||||||
|
obj = obj.decode('ascii')
|
||||||
if ' ' in obj:
|
if ' ' in obj:
|
||||||
sep = ' '
|
sep = ' '
|
||||||
elif 'T' in obj:
|
elif 'T' in obj:
|
||||||
@@ -196,6 +198,8 @@ def convert_timedelta(obj):
|
|||||||
can accept values as (+|-)DD HH:MM:SS. The latter format will not
|
can accept values as (+|-)DD HH:MM:SS. The latter format will not
|
||||||
be parsed correctly by this function.
|
be parsed correctly by this function.
|
||||||
"""
|
"""
|
||||||
|
if not PY2 and isinstance(obj, (bytes, bytearray)):
|
||||||
|
obj = obj.decode('ascii')
|
||||||
try:
|
try:
|
||||||
microseconds = 0
|
microseconds = 0
|
||||||
if "." in obj:
|
if "." in obj:
|
||||||
@@ -238,6 +242,8 @@ def convert_time(obj):
|
|||||||
to be treated as time-of-day and not a time offset, then you can
|
to be treated as time-of-day and not a time offset, then you can
|
||||||
use set this function as the converter for FIELD_TYPE.TIME.
|
use set this function as the converter for FIELD_TYPE.TIME.
|
||||||
"""
|
"""
|
||||||
|
if not PY2 and isinstance(obj, (bytes, bytearray)):
|
||||||
|
obj = obj.decode('ascii')
|
||||||
try:
|
try:
|
||||||
microseconds = 0
|
microseconds = 0
|
||||||
if "." in obj:
|
if "." in obj:
|
||||||
@@ -263,6 +269,8 @@ def convert_date(obj):
|
|||||||
True
|
True
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if not PY2 and isinstance(obj, (bytes, bytearray)):
|
||||||
|
obj = obj.decode('ascii')
|
||||||
try:
|
try:
|
||||||
return datetime.date(*[ int(x) for x in obj.split('-', 2) ])
|
return datetime.date(*[ int(x) for x in obj.split('-', 2) ])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@@ -290,6 +298,8 @@ def convert_mysql_timestamp(timestamp):
|
|||||||
True
|
True
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if not PY2 and isinstance(timestamp, (bytes, bytearray)):
|
||||||
|
timestamp = timestamp.decode('ascii')
|
||||||
if timestamp[4] == '-':
|
if timestamp[4] == '-':
|
||||||
return convert_datetime(timestamp)
|
return convert_datetime(timestamp)
|
||||||
timestamp += "0"*(14-len(timestamp)) # padding
|
timestamp += "0"*(14-len(timestamp)) # padding
|
||||||
@@ -302,6 +312,8 @@ def convert_mysql_timestamp(timestamp):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def convert_set(s):
|
def convert_set(s):
|
||||||
|
if isinstance(s, (bytes, bytearray)):
|
||||||
|
return set(s.split(b","))
|
||||||
return set(s.split(","))
|
return set(s.split(","))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user