Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8fcd2c5

Browse filesBrowse files
committed
Use surrogateescape normally on Python 3.6
1 parent 118861f commit 8fcd2c5
Copy full SHA for 8fcd2c5

File tree

Expand file treeCollapse file tree

1 file changed

+17
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+17
-9
lines changed

‎MySQLdb/connections.py

Copy file name to clipboardExpand all lines: MySQLdb/connections.py
+17-9Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,29 @@
44
want to make your own subclasses. In most cases, you will probably
55
override Connection.default_cursor with a non-standard Cursor class.
66
"""
7+
import re
8+
import sys
9+
710
from MySQLdb import cursors
811
from MySQLdb.compat import unicode, PY2
9-
from _mysql_exceptions import Warning, Error, InterfaceError, DataError, \
10-
DatabaseError, OperationalError, IntegrityError, InternalError, \
11-
NotSupportedError, ProgrammingError
12+
from _mysql_exceptions import (
13+
Warning, Error, InterfaceError, DataError,
14+
DatabaseError, OperationalError, IntegrityError, InternalError,
15+
NotSupportedError, ProgrammingError,
16+
)
1217
import _mysql
13-
import re
1418

1519

1620
if not PY2:
17-
# See http://bugs.python.org/issue24870
18-
_surrogateescape_table = [chr(i) if i < 0x80 else chr(i + 0xdc00) for i in range(256)]
21+
if sys.version_info[:2] < (3, 6):
22+
# See http://bugs.python.org/issue24870
23+
_surrogateescape_table = [chr(i) if i < 0x80 else chr(i + 0xdc00) for i in range(256)]
1924

20-
def _fast_surroundescape(s):
21-
return s.decode('latin1').translate(_surrogateescape_table)
25+
def _fast_surrogateescape(s):
26+
return s.decode('latin1').translate(_surrogateescape_table)
27+
else:
28+
def _fast_surrogateescape(s):
29+
return s.decode('ascii', 'surrogateescape')
2230

2331

2432
def defaulterrorhandler(connection, cursor, errorclass, errorvalue):
@@ -312,7 +320,7 @@ def literal(self, o):
312320
# bytes to unicode and back again.
313321
# See http://python.org/dev/peps/pep-0383/
314322
if not PY2 and isinstance(s, (bytes, bytearray)):
315-
return _fast_surroundescape(s)
323+
return _fast_surrogateescape(s)
316324
return s
317325

318326
def begin(self):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.