mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2026-03-13 08:00:02 +08:00
Handle types in a Python 3 friendly way
This commit is contained in:
8
MySQLdb/compat.py
Normal file
8
MySQLdb/compat.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
unicode = str
|
||||
unichr = chr
|
||||
else:
|
||||
unicode = unicode
|
||||
unichr = unichr
|
||||
@@ -7,10 +7,11 @@ override Connection.default_cursor with a non-standard Cursor class.
|
||||
|
||||
"""
|
||||
from MySQLdb import cursors
|
||||
from MySQLdb.compat import unicode
|
||||
from _mysql_exceptions import Warning, Error, InterfaceError, DataError, \
|
||||
DatabaseError, OperationalError, IntegrityError, InternalError, \
|
||||
NotSupportedError, ProgrammingError
|
||||
import types, _mysql
|
||||
import _mysql
|
||||
import re
|
||||
|
||||
|
||||
@@ -233,8 +234,8 @@ class Connection(_mysql.connection):
|
||||
self.converter[FIELD_TYPE.VARCHAR].append((None, string_decoder))
|
||||
self.converter[FIELD_TYPE.BLOB].append((None, string_decoder))
|
||||
|
||||
self.encoders[types.StringType] = string_literal
|
||||
self.encoders[types.UnicodeType] = unicode_literal
|
||||
self.encoders[bytes] = string_literal
|
||||
self.encoders[unicode] = unicode_literal
|
||||
self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS
|
||||
if self._transactional:
|
||||
if autocommit is not None:
|
||||
|
||||
@@ -7,13 +7,8 @@ default, MySQLdb uses the Cursor class.
|
||||
|
||||
import re
|
||||
import sys
|
||||
try:
|
||||
from types import ListType, TupleType, UnicodeType
|
||||
except ImportError:
|
||||
# Python 3
|
||||
ListType = list
|
||||
TupleType = tuple
|
||||
UnicodeType = str
|
||||
|
||||
from MySQLdb.compat import unicode
|
||||
|
||||
restr = r"""
|
||||
\s
|
||||
@@ -305,7 +300,7 @@ class BaseCursor(object):
|
||||
q = "CALL %s(%s)" % (procname,
|
||||
','.join(['@_%s_%d' % (procname, i)
|
||||
for i in range(len(args))]))
|
||||
if type(q) is UnicodeType:
|
||||
if isinstance(q, unicode):
|
||||
q = q.encode(db.unicode_literal.charset)
|
||||
self._query(q)
|
||||
self._executed = q
|
||||
|
||||
@@ -44,6 +44,7 @@ classifiers:
|
||||
Topic :: Database :: Database Engines/Servers
|
||||
py_modules:
|
||||
_mysql_exceptions
|
||||
MySQLdb.compat
|
||||
MySQLdb.converters
|
||||
MySQLdb.connections
|
||||
MySQLdb.cursors
|
||||
|
||||
@@ -10,6 +10,8 @@ import array
|
||||
import unittest
|
||||
from configdb import connection_factory
|
||||
|
||||
from MySQLdb.compat import unichr
|
||||
|
||||
|
||||
class DatabaseTest(unittest.TestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user