Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pymysql/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def convert_datetime(obj):
True

"""
if not PY2 and isinstance(obj, (bytes, bytearray)):
obj = obj.decode('ascii')
if ' ' in obj:
sep = ' '
elif 'T' in obj:
Expand Down Expand Up @@ -196,6 +198,8 @@ def convert_timedelta(obj):
can accept values as (+|-)DD HH:MM:SS. The latter format will not
be parsed correctly by this function.
"""
if not PY2 and isinstance(obj, (bytes, bytearray)):
obj = obj.decode('ascii')
try:
microseconds = 0
if "." in obj:
Expand Down Expand Up @@ -238,6 +242,8 @@ def convert_time(obj):
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.
"""
if not PY2 and isinstance(obj, (bytes, bytearray)):
obj = obj.decode('ascii')
try:
microseconds = 0
if "." in obj:
Expand All @@ -263,6 +269,8 @@ def convert_date(obj):
True

"""
if not PY2 and isinstance(obj, (bytes, bytearray)):
obj = obj.decode('ascii')
try:
return datetime.date(*[ int(x) for x in obj.split('-', 2) ])
except ValueError:
Expand Down Expand Up @@ -290,6 +298,8 @@ def convert_mysql_timestamp(timestamp):
True

"""
if not PY2 and isinstance(timestamp, (bytes, bytearray)):
timestamp = timestamp.decode('ascii')
if timestamp[4] == '-':
return convert_datetime(timestamp)
timestamp += "0"*(14-len(timestamp)) # padding
Expand All @@ -302,6 +312,8 @@ def convert_mysql_timestamp(timestamp):
return None

def convert_set(s):
if isinstance(s, (bytes, bytearray)):
return set(s.split(b","))
return set(s.split(","))


Expand Down