Skip to content

Commit 3b80aab

Browse files
author
Bastien Vallet
committed
[compat] Remove py27 support as Python 2.7 will be deprecated beginning of 2020
1 parent 52d677b commit 3b80aab

10 files changed

+9
-41
lines changed

INSTALL.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ MySQLdb Installation
88
Prerequisites
99
-------------
1010

11-
+ Python 2.7, 3.5 or higher
11+
+ Python 3.5 or higher
1212

1313
+ setuptools
1414

MySQLdb/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
paramstyle = "format"
2727

2828
from ._mysql import *
29-
from MySQLdb.compat import PY2
3029
from MySQLdb.constants import FIELD_TYPE
3130
from MySQLdb.times import Date, Time, Timestamp, \
3231
DateFromTicks, TimeFromTicks, TimestampFromTicks
@@ -71,12 +70,8 @@ def test_DBAPISet_set_equality_membership():
7170
def test_DBAPISet_set_inequality_membership():
7271
assert FIELD_TYPE.DATE != STRING
7372

74-
if PY2:
75-
def Binary(x):
76-
return bytearray(x)
77-
else:
78-
def Binary(x):
79-
return bytes(x)
73+
def Binary(x):
74+
return bytes(x)
8075

8176
def Connect(*args, **kwargs):
8277
"""Factory function for connections.Connection."""

MySQLdb/_exceptions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
55
https://www.python.org/dev/peps/pep-0249/
66
"""
7-
from .compat import StandardError
87

9-
10-
class MySQLError(StandardError):
8+
class MySQLError(Exception):
119
"""Exception related to operation with MySQL."""
1210

1311

MySQLdb/compat.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

MySQLdb/connections.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import sys
99

1010
from MySQLdb import cursors, _mysql
11-
from MySQLdb.compat import unicode, PY2
1211
from MySQLdb._exceptions import (
1312
Warning, Error, InterfaceError, DataError,
1413
DatabaseError, OperationalError, IntegrityError, InternalError,
@@ -147,7 +146,7 @@ class object, used to create cursors (keyword only)
147146
cursorclass = kwargs2.pop('cursorclass', self.default_cursor)
148147
charset = kwargs2.get('charset', '')
149148

150-
if charset or not PY2:
149+
if charset:
151150
use_unicode = True
152151
else:
153152
use_unicode = False
@@ -253,10 +252,7 @@ def literal(self, o):
253252
elif isinstance(o, bytearray):
254253
s = self._bytes_literal(o)
255254
elif isinstance(o, bytes):
256-
if PY2:
257-
s = self.string_literal(o)
258-
else:
259-
s = self._bytes_literal(o)
255+
s = self._bytes_literal(o)
260256
elif isinstance(o, (tuple, list)):
261257
s = self._tuple_literal(o)
262258
else:

MySQLdb/converters.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from MySQLdb._mysql import string_literal, escape
3636
from MySQLdb.constants import FIELD_TYPE, FLAG
3737
from MySQLdb.times import *
38-
from MySQLdb.compat import PY2, long, unicode
3938
from MySQLdb._exceptions import ProgrammingError
4039

4140
NoneType = type(None)

MySQLdb/cursors.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import re
99
import sys
1010

11-
from .compat import unicode
1211
from ._exceptions import (
1312
Warning, Error, InterfaceError, DataError,
1413
DatabaseError, OperationalError, IntegrityError, InternalError,

metadata.cfg

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ classifiers:
1919
Operating System :: Unix
2020
Programming Language :: C
2121
Programming Language :: Python
22-
Programming Language :: Python :: 2
23-
Programming Language :: Python :: 2.7
2422
Programming Language :: Python :: 3
2523
Programming Language :: Python :: 3.5
2624
Programming Language :: Python :: 3.6
@@ -30,7 +28,6 @@ classifiers:
3028
Topic :: Database :: Database Engines/Servers
3129
py_modules:
3230
MySQLdb._exceptions
33-
MySQLdb.compat
3431
MySQLdb.connections
3532
MySQLdb.converters
3633
MySQLdb.cursors

tests/capabilities.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import unittest
1111
from configdb import connection_factory
1212

13-
from MySQLdb.compat import unichr
14-
1513

1614
class DatabaseTest(unittest.TestCase):
1715

@@ -27,8 +25,8 @@ def setUp(self):
2725
db = connection_factory(**self.connect_kwargs)
2826
self.connection = db
2927
self.cursor = db.cursor()
30-
self.BLOBUText = u''.join([unichr(i) for i in range(16384)])
31-
self.BLOBBinary = self.db_module.Binary((u''.join([unichr(i) for i in range(256)] * 16)).encode('latin1'))
28+
self.BLOBUText = u''.join([chr(i) for i in range(16384)])
29+
self.BLOBBinary = self.db_module.Binary((u''.join([chr(i) for i in range(256)] * 16)).encode('latin1'))
3230

3331
leak_test = True
3432

tests/test_MySQLdb_nonstandard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_client_flag(self):
9292

9393
self.assertIsInstance(conn.client_flag, (int, MySQLdb.compat.long))
9494
self.assertTrue(conn.client_flag & MySQLdb.constants.CLIENT.FOUND_ROWS)
95-
with self.assertRaises(TypeError if MySQLdb.compat.PY2 else AttributeError):
95+
with self.assertRaises(AttributeError):
9696
conn.client_flag = 0
9797

9898
conn.close()

0 commit comments

Comments
 (0)