|
8 | 8 | import sys |
9 | 9 |
|
10 | 10 | from MySQLdb import cursors, _mysql |
11 | | -from MySQLdb.compat import unicode, PY2 |
12 | 11 | from MySQLdb._exceptions import ( |
13 | 12 | Warning, Error, InterfaceError, DataError, |
14 | 13 | DatabaseError, OperationalError, IntegrityError, InternalError, |
@@ -85,14 +84,11 @@ class object, used to create cursors (keyword only) |
85 | 84 | columns are returned as bytes. Unicode objects will always |
86 | 85 | be encoded to the connection's character set regardless of |
87 | 86 | this setting. |
88 | | - Default to False on Python 2 and True on Python 3 |
89 | | - so that you can always get python `str` object by default. |
| 87 | + Default to True. |
90 | 88 |
|
91 | 89 | :param str charset: |
92 | 90 | If supplied, the connection character set will be changed |
93 | 91 | to this character set. |
94 | | - On Python 2, this option changes default value of `use_unicode` |
95 | | - option from False to True. |
96 | 92 |
|
97 | 93 | :param str auth_plugin: |
98 | 94 | If supplied, the connection default authentication plugin will be |
@@ -154,13 +150,7 @@ class object, used to create cursors (keyword only) |
154 | 150 |
|
155 | 151 | cursorclass = kwargs2.pop('cursorclass', self.default_cursor) |
156 | 152 | charset = kwargs2.get('charset', '') |
157 | | - |
158 | | - if charset or not PY2: |
159 | | - use_unicode = True |
160 | | - else: |
161 | | - use_unicode = False |
162 | | - |
163 | | - use_unicode = kwargs2.pop('use_unicode', use_unicode) |
| 153 | + use_unicode = kwargs2.pop('use_unicode', True) |
164 | 154 | sql_mode = kwargs2.pop('sql_mode', '') |
165 | 155 | self._binary_prefix = kwargs2.pop('binary_prefix', False) |
166 | 156 |
|
@@ -209,9 +199,9 @@ def unicode_literal(u, dummy=None): |
209 | 199 | self.converter[t] = _bytes_or_str |
210 | 200 | # Unlike other string/blob types, JSON is always text. |
211 | 201 | # MySQL may return JSON with charset==binary. |
212 | | - self.converter[FIELD_TYPE.JSON] = unicode |
| 202 | + self.converter[FIELD_TYPE.JSON] = str |
213 | 203 |
|
214 | | - self.encoders[unicode] = unicode_literal |
| 204 | + self.encoders[str] = unicode_literal |
215 | 205 | self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS |
216 | 206 | if self._transactional: |
217 | 207 | if autocommit is not None: |
@@ -256,20 +246,17 @@ def literal(self, o): |
256 | 246 | Non-standard. For internal use; do not use this in your |
257 | 247 | applications. |
258 | 248 | """ |
259 | | - if isinstance(o, unicode): |
| 249 | + if isinstance(o, str): |
260 | 250 | s = self.string_literal(o.encode(self.encoding)) |
261 | 251 | elif isinstance(o, bytearray): |
262 | 252 | s = self._bytes_literal(o) |
263 | 253 | elif isinstance(o, bytes): |
264 | | - if PY2: |
265 | | - s = self.string_literal(o) |
266 | | - else: |
267 | | - s = self._bytes_literal(o) |
| 254 | + s = self._bytes_literal(o) |
268 | 255 | elif isinstance(o, (tuple, list)): |
269 | 256 | s = self._tuple_literal(o) |
270 | 257 | else: |
271 | 258 | s = self.escape(o, self.encoders) |
272 | | - if isinstance(s, unicode): |
| 259 | + if isinstance(s, str): |
273 | 260 | s = s.encode(self.encoding) |
274 | 261 | assert isinstance(s, bytes) |
275 | 262 | return s |
|
0 commit comments