From 9d8a9ba521803e7d78618556849022dab19b6bc8 Mon Sep 17 00:00:00 2001 From: Debra Venckus Date: Thu, 28 Jun 2018 14:35:45 -0500 Subject: [PATCH 1/3] Fixing python3-bytes-error via salt --- MySQLdb/cursors.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py index bc1334b7..82add397 100644 --- a/MySQLdb/cursors.py +++ b/MySQLdb/cursors.py @@ -22,6 +22,23 @@ text_type = str +def convert_to_str(var): + """ + Convert various datatypes to str + Required for Python 3 + """ + if isinstance(var,tuple): + return tuple(convert_to_str(item) for item in var) + if isinstance(var,list): + return ([convert_to_str(item) for item in var]) + elif isinstance(var,dict): + return {convert_to_str(key):convert_to_str(value) for key,value in var.items()} + elif isinstance(var,bytes): + return var.decode('utf-8') + + return var + + #: Regular expression for :meth:`Cursor.executemany`. #: executemany only supports simple bulk insert. #: You can use it to load large dataset. @@ -444,6 +461,9 @@ def fetchall(self): else: result = self._rows self.rownumber = len(self._rows) + if not PY2: + db = self._get_db() + result = tuple(convert_to_str(result)) return result def scroll(self, value, mode='relative'): From 72e843393b305671a13ba1e52b84095a6b91d0a2 Mon Sep 17 00:00:00 2001 From: Debra Venckus Date: Thu, 28 Jun 2018 15:25:12 -0500 Subject: [PATCH 2/3] correct build errors --- MySQLdb/cursors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py index 82add397..4d807a96 100644 --- a/MySQLdb/cursors.py +++ b/MySQLdb/cursors.py @@ -34,7 +34,7 @@ def convert_to_str(var): elif isinstance(var,dict): return {convert_to_str(key):convert_to_str(value) for key,value in var.items()} elif isinstance(var,bytes): - return var.decode('utf-8') + return var.decode('utf-8', 'ignore') return var From 02e2cee4402dd8429c7c35f131bc82887ff1ca58 Mon Sep 17 00:00:00 2001 From: dvenckus <8799279+dvenckus@users.noreply.github.com> Date: Thu, 28 Jun 2018 22:38:43 -0500 Subject: [PATCH 3/3] Update README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index cd91383d..317a55ee 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,14 @@ [![Build Status](https://secure.travis-ci.org/PyMySQL/mysqlclient-python.png)](http://travis-ci.org/PyMySQL/mysqlclient-python) +### This is a fork of a fork + +This fork corrects a byte string error between PyMySQL/mysqlclient-python, Python3, and Saltstack. This error prevented the Saltstack mysql_grants module from working correctly. + + + +### From the original + This is a fork of [MySQLdb1](https://github.com/farcepest/MySQLdb1). This project adds Python 3 support and bug fixes.