diff --git a/torndb.py b/torndb.py index c1cad6a..77103dc 100644 --- a/torndb.py +++ b/torndb.py @@ -253,17 +253,21 @@ def __getattr__(self, name): raise AttributeError(name) if MySQLdb is not None: - # Fix the access conversions to properly recognize unicode/binary - FIELD_TYPE = MySQLdb.constants.FIELD_TYPE - FLAG = MySQLdb.constants.FLAG - CONVERSIONS = copy.copy(MySQLdb.converters.conversions) + if MySQLdb.__package__ != 'pymysql': + # Fix the access conversions to properly recognize unicode/binary + FIELD_TYPE = MySQLdb.constants.FIELD_TYPE + FLAG = MySQLdb.constants.FLAG + CONVERSIONS = copy.copy(MySQLdb.converters.conversions) - field_types = [FIELD_TYPE.BLOB, FIELD_TYPE.STRING, FIELD_TYPE.VAR_STRING] - if 'VARCHAR' in vars(FIELD_TYPE): - field_types.append(FIELD_TYPE.VARCHAR) + field_types = [FIELD_TYPE.BLOB, FIELD_TYPE.STRING, FIELD_TYPE.VAR_STRING] + if 'VARCHAR' in vars(FIELD_TYPE): + field_types.append(FIELD_TYPE.VARCHAR) + + for field_type in field_types: + CONVERSIONS[field_type] = [(FLAG.BINARY, str)] + CONVERSIONS[field_type] + else: + CONVERSIONS = {} - for field_type in field_types: - CONVERSIONS[field_type] = [(FLAG.BINARY, str)] + CONVERSIONS[field_type] # Alias some common MySQL exceptions IntegrityError = MySQLdb.IntegrityError