mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-17 04:50:55 +08:00
More Python 3 fixes. Py 3 blows up when testing BLOBs.
This commit is contained in:
@ -151,7 +151,7 @@ class Connection(_mysql.connection):
|
|||||||
|
|
||||||
kwargs2 = kwargs.copy()
|
kwargs2 = kwargs.copy()
|
||||||
|
|
||||||
if kwargs.has_key('conv'):
|
if 'conv' in kwargs:
|
||||||
conv = kwargs['conv']
|
conv = kwargs['conv']
|
||||||
else:
|
else:
|
||||||
conv = conversions
|
conv = conversions
|
||||||
|
@ -35,7 +35,17 @@ MySQL.connect().
|
|||||||
from _mysql import string_literal, escape_sequence, escape_dict, escape, NULL
|
from _mysql import string_literal, escape_sequence, escape_dict, escape, NULL
|
||||||
from MySQLdb.constants import FIELD_TYPE, FLAG
|
from MySQLdb.constants import FIELD_TYPE, FLAG
|
||||||
from MySQLdb.times import *
|
from MySQLdb.times import *
|
||||||
import types
|
|
||||||
|
try:
|
||||||
|
from types import IntType, LongType, FloatType, NoneType, TupleType, ListType, DictType, InstanceType, \
|
||||||
|
StringType, UnicodeType, ObjectType, BooleanType, ClassType, TypeType
|
||||||
|
except ImportError:
|
||||||
|
# Python 3
|
||||||
|
long = int
|
||||||
|
IntType, LongType, FloatType, NoneType = int, long, float, type(None)
|
||||||
|
TupleType, ListType, DictType, InstanceType = tuple, list, dict, None
|
||||||
|
StringType, UnicodeType, ObjectType, BooleanType = bytes, str, object, bool
|
||||||
|
|
||||||
import array
|
import array
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -92,14 +102,14 @@ def Instance2Str(o, d):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if d.has_key(o.__class__):
|
if o.__class__ in d:
|
||||||
return d[o.__class__](o, d)
|
return d[o.__class__](o, d)
|
||||||
cl = filter(lambda x,o=o:
|
cl = filter(lambda x,o=o:
|
||||||
type(x) is types.ClassType
|
type(x) is ClassType
|
||||||
and isinstance(o, x), d.keys())
|
and isinstance(o, x), d.keys())
|
||||||
if not cl and hasattr(types, 'ObjectType'):
|
if not cl and hasattr(types, 'ObjectType'):
|
||||||
cl = filter(lambda x,o=o:
|
cl = filter(lambda x,o=o:
|
||||||
type(x) is types.TypeType
|
type(x) is TypeType
|
||||||
and isinstance(o, x)
|
and isinstance(o, x)
|
||||||
and d[x] is not Instance2Str,
|
and d[x] is not Instance2Str,
|
||||||
d.keys())
|
d.keys())
|
||||||
@ -115,19 +125,19 @@ def array2Str(o, d):
|
|||||||
return Thing2Literal(o.tostring(), d)
|
return Thing2Literal(o.tostring(), d)
|
||||||
|
|
||||||
conversions = {
|
conversions = {
|
||||||
types.IntType: Thing2Str,
|
IntType: Thing2Str,
|
||||||
types.LongType: Long2Int,
|
LongType: Long2Int,
|
||||||
types.FloatType: Float2Str,
|
FloatType: Float2Str,
|
||||||
types.NoneType: None2NULL,
|
NoneType: None2NULL,
|
||||||
types.TupleType: escape_sequence,
|
TupleType: escape_sequence,
|
||||||
types.ListType: escape_sequence,
|
ListType: escape_sequence,
|
||||||
types.DictType: escape_dict,
|
DictType: escape_dict,
|
||||||
types.InstanceType: Instance2Str,
|
InstanceType: Instance2Str,
|
||||||
array.ArrayType: array2Str,
|
array.ArrayType: array2Str,
|
||||||
types.StringType: Thing2Literal, # default
|
StringType: Thing2Literal, # default
|
||||||
types.UnicodeType: Unicode2Str,
|
UnicodeType: Unicode2Str,
|
||||||
types.ObjectType: Instance2Str,
|
ObjectType: Instance2Str,
|
||||||
types.BooleanType: Bool2Str,
|
BooleanType: Bool2Str,
|
||||||
DateTimeType: DateTime2literal,
|
DateTimeType: DateTime2literal,
|
||||||
DateTimeDeltaType: DateTimeDelta2literal,
|
DateTimeDeltaType: DateTimeDelta2literal,
|
||||||
set: Set2Str,
|
set: Set2Str,
|
||||||
|
@ -24,8 +24,9 @@ class DatabaseTest(unittest.TestCase):
|
|||||||
db = self.db_module.connect(*self.connect_args, **self.connect_kwargs)
|
db = self.db_module.connect(*self.connect_args, **self.connect_kwargs)
|
||||||
self.connection = db
|
self.connection = db
|
||||||
self.cursor = db.cursor()
|
self.cursor = db.cursor()
|
||||||
|
# TODO: this needs to be re-evaluated for Python 3
|
||||||
self.BLOBText = ''.join([chr(i) for i in range(256)] * 100);
|
self.BLOBText = ''.join([chr(i) for i in range(256)] * 100);
|
||||||
self.BLOBUText = ''.join([unichr(i) for i in range(16384)])
|
self.BLOBUText = u''.join([unichr(i) for i in range(16384)])
|
||||||
self.BLOBBinary = self.db_module.Binary(''.join([chr(i) for i in range(256)] * 16))
|
self.BLOBBinary = self.db_module.Binary(''.join([chr(i) for i in range(256)] * 16))
|
||||||
|
|
||||||
leak_test = True
|
leak_test = True
|
||||||
|
@ -77,8 +77,8 @@ class test_MySQLdb(capabilities.DatabaseTest):
|
|||||||
from MySQLdb.constants import ER
|
from MySQLdb.constants import ER
|
||||||
try:
|
try:
|
||||||
self.cursor.execute("describe some_non_existent_table");
|
self.cursor.execute("describe some_non_existent_table");
|
||||||
except self.connection.ProgrammingError as (msg,):
|
except self.connection.ProgrammingError as msg:
|
||||||
self.assertTrue(msg[0] == ER.NO_SUCH_TABLE)
|
self.assertTrue(msg.args[0].args[0] == ER.NO_SUCH_TABLE)
|
||||||
|
|
||||||
def test_bug_3514287(self):
|
def test_bug_3514287(self):
|
||||||
c = self.cursor
|
c = self.cursor
|
||||||
|
Reference in New Issue
Block a user