From f884739a7f628adcc5509c99c8849ba6c86af119 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Tue, 17 May 2016 19:06:39 +0900 Subject: [PATCH] Fix convertion error on Py3 and use_unicode=False --- pymysql/converters.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pymysql/converters.py b/pymysql/converters.py index 69115c0..eeef456 100644 --- a/pymysql/converters.py +++ b/pymysql/converters.py @@ -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: @@ -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: @@ -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: @@ -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: @@ -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 @@ -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(","))