mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-14 18:12:35 +08:00
Remove py27 support from Python sources. (#394)
This commit is contained in:

committed by
Inada Naoki

parent
5811678dea
commit
026e87f7b5
@ -8,7 +8,7 @@ MySQLdb Installation
|
||||
Prerequisites
|
||||
-------------
|
||||
|
||||
+ Python 2.7, 3.5 or higher
|
||||
+ Python 3.5 or higher
|
||||
|
||||
+ setuptools
|
||||
|
||||
|
@ -26,7 +26,6 @@ apilevel = "2.0"
|
||||
paramstyle = "format"
|
||||
|
||||
from ._mysql import *
|
||||
from MySQLdb.compat import PY2
|
||||
from MySQLdb.constants import FIELD_TYPE
|
||||
from MySQLdb.times import Date, Time, Timestamp, \
|
||||
DateFromTicks, TimeFromTicks, TimestampFromTicks
|
||||
@ -71,11 +70,7 @@ def test_DBAPISet_set_equality_membership():
|
||||
def test_DBAPISet_set_inequality_membership():
|
||||
assert FIELD_TYPE.DATE != STRING
|
||||
|
||||
if PY2:
|
||||
def Binary(x):
|
||||
return bytearray(x)
|
||||
else:
|
||||
def Binary(x):
|
||||
def Binary(x):
|
||||
return bytes(x)
|
||||
|
||||
def Connect(*args, **kwargs):
|
||||
|
@ -4,10 +4,8 @@ These classes are dictated by the DB API v2.0:
|
||||
|
||||
https://www.python.org/dev/peps/pep-0249/
|
||||
"""
|
||||
from .compat import StandardError
|
||||
|
||||
|
||||
class MySQLError(StandardError):
|
||||
class MySQLError(Exception):
|
||||
"""Exception related to operation with MySQL."""
|
||||
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] == 2:
|
||||
PY2 = True
|
||||
unicode = unicode
|
||||
unichr = unichr
|
||||
long = long
|
||||
StandardError = StandardError
|
||||
else:
|
||||
PY2 = False
|
||||
unicode = str
|
||||
unichr = chr
|
||||
long = int
|
||||
StandardError = Exception
|
@ -8,7 +8,6 @@ import re
|
||||
import sys
|
||||
|
||||
from MySQLdb import cursors, _mysql
|
||||
from MySQLdb.compat import unicode, PY2
|
||||
from MySQLdb._exceptions import (
|
||||
Warning, Error, InterfaceError, DataError,
|
||||
DatabaseError, OperationalError, IntegrityError, InternalError,
|
||||
@ -85,14 +84,11 @@ class Connection(_mysql.connection):
|
||||
columns are returned as bytes. Unicode objects will always
|
||||
be encoded to the connection's character set regardless of
|
||||
this setting.
|
||||
Default to False on Python 2 and True on Python 3
|
||||
so that you can always get python `str` object by default.
|
||||
Default to True.
|
||||
|
||||
:param str charset:
|
||||
If supplied, the connection character set will be changed
|
||||
to this character set.
|
||||
On Python 2, this option changes default value of `use_unicode`
|
||||
option from False to True.
|
||||
|
||||
:param str auth_plugin:
|
||||
If supplied, the connection default authentication plugin will be
|
||||
@ -154,13 +150,7 @@ class Connection(_mysql.connection):
|
||||
|
||||
cursorclass = kwargs2.pop('cursorclass', self.default_cursor)
|
||||
charset = kwargs2.get('charset', '')
|
||||
|
||||
if charset or not PY2:
|
||||
use_unicode = True
|
||||
else:
|
||||
use_unicode = False
|
||||
|
||||
use_unicode = kwargs2.pop('use_unicode', use_unicode)
|
||||
use_unicode = kwargs2.pop('use_unicode', True)
|
||||
sql_mode = kwargs2.pop('sql_mode', '')
|
||||
self._binary_prefix = kwargs2.pop('binary_prefix', False)
|
||||
|
||||
@ -209,9 +199,9 @@ class Connection(_mysql.connection):
|
||||
self.converter[t] = _bytes_or_str
|
||||
# Unlike other string/blob types, JSON is always text.
|
||||
# MySQL may return JSON with charset==binary.
|
||||
self.converter[FIELD_TYPE.JSON] = unicode
|
||||
self.converter[FIELD_TYPE.JSON] = str
|
||||
|
||||
self.encoders[unicode] = unicode_literal
|
||||
self.encoders[str] = unicode_literal
|
||||
self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS
|
||||
if self._transactional:
|
||||
if autocommit is not None:
|
||||
@ -256,20 +246,17 @@ class Connection(_mysql.connection):
|
||||
Non-standard. For internal use; do not use this in your
|
||||
applications.
|
||||
"""
|
||||
if isinstance(o, unicode):
|
||||
if isinstance(o, str):
|
||||
s = self.string_literal(o.encode(self.encoding))
|
||||
elif isinstance(o, bytearray):
|
||||
s = self._bytes_literal(o)
|
||||
elif isinstance(o, bytes):
|
||||
if PY2:
|
||||
s = self.string_literal(o)
|
||||
else:
|
||||
s = self._bytes_literal(o)
|
||||
elif isinstance(o, (tuple, list)):
|
||||
s = self._tuple_literal(o)
|
||||
else:
|
||||
s = self.escape(o, self.encoders)
|
||||
if isinstance(s, unicode):
|
||||
if isinstance(s, str):
|
||||
s = s.encode(self.encoding)
|
||||
assert isinstance(s, bytes)
|
||||
return s
|
||||
|
@ -35,7 +35,6 @@ from decimal import Decimal
|
||||
from MySQLdb._mysql import string_literal, escape
|
||||
from MySQLdb.constants import FIELD_TYPE, FLAG
|
||||
from MySQLdb.times import *
|
||||
from MySQLdb.compat import PY2, long, unicode
|
||||
from MySQLdb._exceptions import ProgrammingError
|
||||
|
||||
NoneType = type(None)
|
||||
@ -85,11 +84,10 @@ def array2Str(o, d):
|
||||
return Thing2Literal(o.tostring(), d)
|
||||
|
||||
# bytes or str regarding to BINARY_FLAG.
|
||||
_bytes_or_str = ((FLAG.BINARY, bytes), (None, unicode))
|
||||
_bytes_or_str = ((FLAG.BINARY, bytes), (None, str))
|
||||
|
||||
conversions = {
|
||||
int: Thing2Str,
|
||||
long: Thing2Str,
|
||||
float: Float2Str,
|
||||
NoneType: None2NULL,
|
||||
ArrayType: array2Str,
|
||||
|
@ -3,12 +3,10 @@
|
||||
This module implements Cursors of various types for MySQLdb. By
|
||||
default, MySQLdb uses the Cursor class.
|
||||
"""
|
||||
from __future__ import print_function, absolute_import
|
||||
from functools import partial
|
||||
import re
|
||||
import sys
|
||||
|
||||
from .compat import unicode
|
||||
from ._exceptions import (
|
||||
Warning, Error, InterfaceError, DataError,
|
||||
DatabaseError, OperationalError, IntegrityError, InternalError,
|
||||
@ -101,7 +99,7 @@ class BaseCursor(object):
|
||||
literal = conn.literal
|
||||
|
||||
def ensure_bytes(x):
|
||||
if isinstance(x, unicode):
|
||||
if isinstance(x, str):
|
||||
return x.encode(encoding)
|
||||
elif isinstance(x, tuple):
|
||||
return tuple(map(ensure_bytes, x))
|
||||
@ -187,14 +185,14 @@ class BaseCursor(object):
|
||||
pass
|
||||
db = self._get_db()
|
||||
|
||||
if isinstance(query, unicode):
|
||||
if isinstance(query, str):
|
||||
query = query.encode(db.encoding)
|
||||
|
||||
if args is not None:
|
||||
if isinstance(args, dict):
|
||||
nargs = {}
|
||||
for key, item in args.items():
|
||||
if isinstance(key, unicode):
|
||||
if isinstance(key, str):
|
||||
key = key.encode(db.encoding)
|
||||
nargs[key] = db.literal(item)
|
||||
args = nargs
|
||||
@ -242,11 +240,11 @@ class BaseCursor(object):
|
||||
def _do_execute_many(self, prefix, values, postfix, args, max_stmt_length, encoding):
|
||||
conn = self._get_db()
|
||||
escape = self._escape_args
|
||||
if isinstance(prefix, unicode):
|
||||
if isinstance(prefix, str):
|
||||
prefix = prefix.encode(encoding)
|
||||
if isinstance(values, unicode):
|
||||
if isinstance(values, str):
|
||||
values = values.encode(encoding)
|
||||
if isinstance(postfix, unicode):
|
||||
if isinstance(postfix, str):
|
||||
postfix = postfix.encode(encoding)
|
||||
sql = bytearray(prefix)
|
||||
args = iter(args)
|
||||
@ -294,7 +292,7 @@ class BaseCursor(object):
|
||||
disconnected.
|
||||
"""
|
||||
db = self._get_db()
|
||||
if isinstance(procname, unicode):
|
||||
if isinstance(procname, str):
|
||||
procname = procname.encode(db.encoding)
|
||||
if args:
|
||||
fmt = b'@_' + procname + b'_%d=%s'
|
||||
|
@ -28,7 +28,6 @@ classifiers:
|
||||
Topic :: Database :: Database Engines/Servers
|
||||
py_modules:
|
||||
MySQLdb._exceptions
|
||||
MySQLdb.compat
|
||||
MySQLdb.connections
|
||||
MySQLdb.converters
|
||||
MySQLdb.cursors
|
||||
|
@ -10,8 +10,6 @@ import array
|
||||
import unittest
|
||||
from configdb import connection_factory
|
||||
|
||||
from MySQLdb.compat import unichr
|
||||
|
||||
|
||||
class DatabaseTest(unittest.TestCase):
|
||||
|
||||
@ -27,8 +25,8 @@ class DatabaseTest(unittest.TestCase):
|
||||
db = connection_factory(**self.connect_kwargs)
|
||||
self.connection = db
|
||||
self.cursor = db.cursor()
|
||||
self.BLOBUText = u''.join([unichr(i) for i in range(16384)])
|
||||
self.BLOBBinary = self.db_module.Binary((u''.join([unichr(i) for i in range(256)] * 16)).encode('latin1'))
|
||||
self.BLOBUText = u''.join([chr(i) for i in range(16384)])
|
||||
self.BLOBBinary = self.db_module.Binary((u''.join([chr(i) for i in range(256)] * 16)).encode('latin1'))
|
||||
|
||||
leak_test = True
|
||||
|
||||
|
@ -5,7 +5,6 @@ from datetime import timedelta
|
||||
from contextlib import closing
|
||||
import unittest
|
||||
import MySQLdb
|
||||
from MySQLdb.compat import unicode
|
||||
from MySQLdb import cursors
|
||||
from configdb import connection_factory
|
||||
import warnings
|
||||
|
@ -90,9 +90,9 @@ class CoreAPI(unittest.TestCase):
|
||||
use_unicode=True,
|
||||
client_flag=MySQLdb.constants.CLIENT.FOUND_ROWS)
|
||||
|
||||
self.assertIsInstance(conn.client_flag, (int, MySQLdb.compat.long))
|
||||
self.assertIsInstance(conn.client_flag, int)
|
||||
self.assertTrue(conn.client_flag & MySQLdb.constants.CLIENT.FOUND_ROWS)
|
||||
with self.assertRaises(TypeError if MySQLdb.compat.PY2 else AttributeError):
|
||||
with self.assertRaises(AttributeError):
|
||||
conn.client_flag = 0
|
||||
|
||||
conn.close()
|
||||
|
Reference in New Issue
Block a user