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 7676693

Browse filesBrowse files
author
adustman
committed
More Python 3 fixes. Py 3 blows up when testing BLOBs.
1 parent 8041cc6 commit 7676693
Copy full SHA for 7676693

File tree

Expand file treeCollapse file tree

4 files changed

+31
-20
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+31
-20
lines changed

‎MySQLdb/MySQLdb/connections.py

Copy file name to clipboardExpand all lines: MySQLdb/MySQLdb/connections.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class object, used to create cursors (keyword only)
151151

152152
kwargs2 = kwargs.copy()
153153

154-
if kwargs.has_key('conv'):
154+
if 'conv' in kwargs:
155155
conv = kwargs['conv']
156156
else:
157157
conv = conversions

‎MySQLdb/MySQLdb/converters.py

Copy file name to clipboardExpand all lines: MySQLdb/MySQLdb/converters.py
+26-16Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@
3535
from _mysql import string_literal, escape_sequence, escape_dict, escape, NULL
3636
from MySQLdb.constants import FIELD_TYPE, FLAG
3737
from MySQLdb.times import *
38-
import types
38+
39+
try:
40+
from types import IntType, LongType, FloatType, NoneType, TupleType, ListType, DictType, InstanceType, \
41+
StringType, UnicodeType, ObjectType, BooleanType, ClassType, TypeType
42+
except ImportError:
43+
# Python 3
44+
long = int
45+
IntType, LongType, FloatType, NoneType = int, long, float, type(None)
46+
TupleType, ListType, DictType, InstanceType = tuple, list, dict, None
47+
StringType, UnicodeType, ObjectType, BooleanType = bytes, str, object, bool
48+
3949
import array
4050

4151
try:
@@ -92,14 +102,14 @@ class to conversions; it will be handled by the default
92102
93103
"""
94104

95-
if d.has_key(o.__class__):
105+
if o.__class__ in d:
96106
return d[o.__class__](o, d)
97107
cl = filter(lambda x,o=o:
98-
type(x) is types.ClassType
108+
type(x) is ClassType
99109
and isinstance(o, x), d.keys())
100110
if not cl and hasattr(types, 'ObjectType'):
101111
cl = filter(lambda x,o=o:
102-
type(x) is types.TypeType
112+
type(x) is TypeType
103113
and isinstance(o, x)
104114
and d[x] is not Instance2Str,
105115
d.keys())
@@ -115,19 +125,19 @@ def array2Str(o, d):
115125
return Thing2Literal(o.tostring(), d)
116126

117127
conversions = {
118-
types.IntType: Thing2Str,
119-
types.LongType: Long2Int,
120-
types.FloatType: Float2Str,
121-
types.NoneType: None2NULL,
122-
types.TupleType: escape_sequence,
123-
types.ListType: escape_sequence,
124-
types.DictType: escape_dict,
125-
types.InstanceType: Instance2Str,
128+
IntType: Thing2Str,
129+
LongType: Long2Int,
130+
FloatType: Float2Str,
131+
NoneType: None2NULL,
132+
TupleType: escape_sequence,
133+
ListType: escape_sequence,
134+
DictType: escape_dict,
135+
InstanceType: Instance2Str,
126136
array.ArrayType: array2Str,
127-
types.StringType: Thing2Literal, # default
128-
types.UnicodeType: Unicode2Str,
129-
types.ObjectType: Instance2Str,
130-
types.BooleanType: Bool2Str,
137+
StringType: Thing2Literal, # default
138+
UnicodeType: Unicode2Str,
139+
ObjectType: Instance2Str,
140+
BooleanType: Bool2Str,
131141
DateTimeType: DateTime2literal,
132142
DateTimeDeltaType: DateTimeDelta2literal,
133143
set: Set2Str,

‎MySQLdb/tests/capabilities.py

Copy file name to clipboardExpand all lines: MySQLdb/tests/capabilities.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ def setUp(self):
2424
db = self.db_module.connect(*self.connect_args, **self.connect_kwargs)
2525
self.connection = db
2626
self.cursor = db.cursor()
27+
# TODO: this needs to be re-evaluated for Python 3
2728
self.BLOBText = ''.join([chr(i) for i in range(256)] * 100);
28-
self.BLOBUText = ''.join([unichr(i) for i in range(16384)])
29+
self.BLOBUText = u''.join([unichr(i) for i in range(16384)])
2930
self.BLOBBinary = self.db_module.Binary(''.join([chr(i) for i in range(256)] * 16))
3031

3132
leak_test = True

‎MySQLdb/tests/test_MySQLdb_capabilities.py

Copy file name to clipboardExpand all lines: MySQLdb/tests/test_MySQLdb_capabilities.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def test_bug_2671682(self):
7777
from MySQLdb.constants import ER
7878
try:
7979
self.cursor.execute("describe some_non_existent_table");
80-
except self.connection.ProgrammingError as (msg,):
81-
self.assertTrue(msg[0] == ER.NO_SUCH_TABLE)
80+
except self.connection.ProgrammingError as msg:
81+
self.assertTrue(msg.args[0].args[0] == ER.NO_SUCH_TABLE)
8282

8383
def test_bug_3514287(self):
8484
c = self.cursor

0 commit comments

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