diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 48dbce46d..c4458cf07 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 strategy: matrix: - python-version: ['pypy2.7', 3.8, 3.9, '3.10', '3.11', '3.12', '3.13'] + python-version: ['3.10', '3.11', '3.12', '3.13'] steps: - uses: actions/checkout@v4 - name: Set up MySQL diff --git a/README.rst b/README.rst index dba9f73be..a08ecb9a0 100644 --- a/README.rst +++ b/README.rst @@ -9,7 +9,7 @@ This package contains a python MySQL client library. It is a fork project from PyMySQL https://pymysql.readthedocs.io/en/latest/. -CyMySQL is accerarated by Cython and supports Python versions 2 and 3. +CyMySQL is accerarated by Cython. Documentation on the MySQL client/server protocol can be found here: http://dev.mysql.com/doc/internals/en/client-server-protocol.html @@ -17,7 +17,7 @@ http://dev.mysql.com/doc/internals/en/client-server-protocol.html Requirements ------------- -- Python 2.7, 3.5+ +- Python 3.10+ - MySQL 5.7 or higher, MariaDB Installation @@ -109,10 +109,7 @@ https://peps.python.org/pep-0249/ asyncio ++++++++++++++++++++++++++++++++++++++ -In Python3, you can use asyncio to write the following. - -This API is experimental. -If there are any mistakes, please correct them in the pull request and send. +You can use asyncio to write the following. Use connect :: diff --git a/cymysql/__init__.py b/cymysql/__init__.py index c03a7b1ba..a9ea66149 100644 --- a/cymysql/__init__.py +++ b/cymysql/__init__.py @@ -22,7 +22,6 @@ THE SOFTWARE. ''' -import sys from cymysql import converters from cymysql.converters import escape_dict, escape_sequence, escape_string from cymysql.err import ( @@ -35,8 +34,7 @@ ) from cymysql.connections import Connection from cymysql.constants import FIELD_TYPE -if sys.version_info[0] > 2: - from cymysql import aio +from cymysql import aio from .__version__ import VERSION, __version__ diff --git a/cymysql/aio/connections.py b/cymysql/aio/connections.py index df95e81f6..a7b8bcc35 100644 --- a/cymysql/aio/connections.py +++ b/cymysql/aio/connections.py @@ -161,7 +161,7 @@ async def set_charset(self, charset): async def read_packet(self): """Read an entire "mysql packet" in its entirety from the network and return a MysqlPacket type that represents the results.""" - return MysqlPacket(await self.socket.recv_packet(self.loop), self.charset, self.encoding, self.use_unicode) + return MysqlPacket(await self.socket.recv_packet(self.loop), self.charset, self.encoding) async def _request_authentication(self): if self.user is None: diff --git a/cymysql/aio/result.py b/cymysql/aio/result.py index 5aa800a04..e722496dd 100644 --- a/cymysql/aio/result.py +++ b/cymysql/aio/result.py @@ -16,7 +16,6 @@ async def read_result(self): await self.connection.socket.recv_packet(self.connection.loop), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) if self.first_packet.is_ok_packet(): @@ -41,7 +40,6 @@ async def read_rest_rowdata_packet(self): await self.connection.socket.recv_packet(self.connection.loop), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) is_eof, warning_count, server_status = packet.is_eof_and_status() if is_eof: @@ -62,7 +60,6 @@ async def _get_descriptions(self): await self.connection.socket.recv_packet(self.connection.loop), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) self.fields.append(field) description.append(field.description()) @@ -71,7 +68,6 @@ async def _get_descriptions(self): await self.connection.socket.recv_packet(self.connection.loop), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) assert eof_packet.is_eof_packet(), 'Protocol error, expecting EOF' self.description = tuple(description) @@ -84,7 +80,6 @@ async def fetchone(self): await self.connection.socket.recv_packet(self.connection.loop), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) is_eof, warning_count, server_status = packet.is_eof_and_status() if is_eof: diff --git a/cymysql/connections.py b/cymysql/connections.py index bc9c4e33a..de151c03f 100644 --- a/cymysql/connections.py +++ b/cymysql/connections.py @@ -25,8 +25,6 @@ from cymysql.result import MySQLResult from cymysql.socketwrapper import SocketWrapper -PYTHON3 = sys.version_info[0] > 2 - DEFAULT_USER = getpass.getuser() DEFAULT_CHARSET = 'utf8mb4' @@ -47,17 +45,11 @@ def byte2int(b): def int2byte(i): - if PYTHON3: - return bytes([i]) - else: - return chr(i) + return bytes([i]) def pack_int24(n): - if PYTHON3: - return bytes([n & 0xFF, (n >> 8) & 0xFF, (n >> 16) & 0xFF]) - else: - return chr(n & 0xFF) + chr((n >> 8) & 0xFF) + chr((n >> 16) & 0xFF) + return bytes([n & 0xFF, (n >> 8) & 0xFF, (n >> 16) & 0xFF]) SCRAMBLE_LENGTH = 20 @@ -122,7 +114,7 @@ def errorhandler(connection, cursor, errorclass, errorvalue): def __init__(self, host="localhost", user=None, passwd="", db=None, port=3306, unix_socket=None, charset='', sql_mode=None, - read_default_file=None, use_unicode=None, + read_default_file=None, client_flag=0, cursorclass=None, init_command=None, connect_timeout=None, ssl=None, read_default_group=None, compress="", zstd_compression_level=3, named_pipe=None, @@ -141,7 +133,6 @@ def __init__(self, host="localhost", user=None, passwd="", sql_mode: Default SQL_MODE to use. read_default_file: Specifies my.cnf file to read these parameters from under the [client] section. conv: Decoders dictionary to use instead of the default one. This is used to provide custom marshalling of types. See converters. - use_unicode: Whether or not to default to unicode strings. This option defaults to true for Py3k. client_flag: Custom flags to send to MySQL. Find potential values in constants.CLIENT. cursorclass: Custom cursor class to use. init_command: Initial SQL statement to run when connection is established. @@ -152,10 +143,6 @@ def __init__(self, host="localhost", user=None, passwd="", zstd_compression_level: zstd compression leve (1-22), default is 3. named_pipe: Not supported """ - - if use_unicode is None and sys.version_info[0] > 2: - use_unicode = True - if named_pipe: raise NotImplementedError("named_pipe argument are not supported") @@ -230,16 +217,7 @@ def _config(key, default): self.unix_socket = unix_socket self.conv = conv self.encoders = encoders - if charset: - self.charset = charset - self.use_unicode = True - else: - self.charset = DEFAULT_CHARSET - self.use_unicode = False - - if use_unicode is not None: - self.use_unicode = use_unicode - + self.charset = charset if charset else DEFAULT_CHARSET self.encoding = encoding_by_charset(self.charset) client_flag |= CLIENT.CAPABILITIES @@ -439,7 +417,7 @@ def _connect(self): def read_packet(self): """Read an entire "mysql packet" in its entirety from the network and return a MysqlPacket type that represents the results.""" - return MysqlPacket(self.socket.recv_packet(), self.charset, self.encoding, self.use_unicode) + return MysqlPacket(self.socket.recv_packet(), self.charset, self.encoding) def insert_id(self): if self._result: @@ -451,10 +429,7 @@ def _execute_command(self, command, sql): if not self.socket: self.errorhandler(None, InterfaceError, (-1, 'socket not found')) - if ( - (PYTHON3 and isinstance(sql, str)) or - (not PYTHON3 and isinstance(sql, unicode)) - ): + if isinstance(sql, str): sql = sql.encode(self.encoding) if len(sql) + 1 > 0xffffff: @@ -525,7 +500,7 @@ def _request_authentication(self): self.socket.send_uncompress_packet(data) auth_packet = self.socket.recv_uncompress_packet() - if auth_packet[0] == (0xfe if PYTHON3 else b'\xfe'): # EOF packet + if auth_packet[0] == 0xfe: # EOF packet # AuthSwitchRequest # https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchRequest i = auth_packet.find(b'\0', 1) diff --git a/cymysql/converters.py b/cymysql/converters.py index 81ffa5c98..66ddc9e1f 100644 --- a/cymysql/converters.py +++ b/cymysql/converters.py @@ -1,13 +1,10 @@ import re import datetime import time -import sys import decimal from cymysql.constants import FIELD_TYPE -PYTHON3 = sys.version_info[0] > 2 - ESCAPE_REGEX = re.compile(r"[\0\n\r\032\'\"\\]") ESCAPE_MAP = {'\0': '\\0', '\n': '\\n', '\r': '\\r', '\032': '\\Z', '\'': '\\\'', '"': '\\"', '\\': '\\\\'} @@ -113,7 +110,7 @@ def convert_datetime(obj): True """ - if PYTHON3 and not isinstance(obj, str): + if not isinstance(obj, str): obj = obj.decode('ascii') if ' ' in obj: sep = ' ' @@ -150,7 +147,7 @@ def convert_timedelta(obj): can accept values as (+|-)DD HH:MM:SS. The latter format will not be parsed correctly by this function. """ - if PYTHON3 and not isinstance(obj, str): + if not isinstance(obj, str): obj = obj.decode('ascii') try: microseconds = 0 @@ -216,7 +213,7 @@ def convert_date(obj): True """ - if PYTHON3 and not isinstance(obj, str): + if not isinstance(obj, str): obj = obj.decode('ascii') try: return datetime.date(*[int(x) for x in obj.split('-', 2)]) @@ -245,7 +242,7 @@ def convert_mysql_timestamp(obj): True """ - if PYTHON3 and not isinstance(obj, str): + if not isinstance(obj, str): obj = obj.decode('ascii') if obj[4] == '-': return convert_datetime(obj) @@ -273,35 +270,29 @@ def convert_bit(b): return b -def convert_characters(data, encoding=None, field=None, use_unicode=None): +def convert_characters(data, encoding=None, field=None): if field.is_set: return convert_set(data.decode(field.encoding)) if field.is_binary: - if PYTHON3 and field.charset != 'binary': + if field.charset != 'binary': return data.decode(field.encoding) else: return data - if use_unicode or PYTHON3: - return data.decode(field.encoding) - elif encoding != field.encoding: - return data.decode(field.encoding).encode(encoding) - return data + return data.decode(field.encoding) -def convert_vector(data, encoding=None, field=None, use_unicode=None): +def convert_vector(data, encoding=None, field=None): import numpy as np return np.frombuffer(data, dtype=np.float32) -def convert_json(data, encoding=None, field=None, use_unicode=None): - if use_unicode or PYTHON3: - return data.decode(encoding) - return data +def convert_json(data, encoding=None, field=None): + return data.decode(encoding) def convert_decimal(obj): - if PYTHON3 and not isinstance(obj, str): + if not isinstance(obj, str): obj = obj.decode('ascii') return decimal.Decimal(obj) @@ -337,6 +328,7 @@ def convert_decimal(obj): } encoders = { + bytes:escape_bytes, bool: escape_bool, int: escape_int, float: escape_float, @@ -354,11 +346,6 @@ def convert_decimal(obj): time.struct_time: escape_struct_time, } -if PYTHON3: - encoders[bytes] = escape_bytes -else: - encoders[unicode] = escape_string - try: import numpy as np encoders[np.ndarray] = escape_vector diff --git a/cymysql/cursors.py b/cymysql/cursors.py index 11f08aad4..6f165abea 100644 --- a/cymysql/cursors.py +++ b/cymysql/cursors.py @@ -8,8 +8,6 @@ NotSupportedError, ProgrammingError ) -PYTHON3 = sys.version_info[0] > 2 - class Cursor(object): ''' @@ -115,10 +113,8 @@ def execute(self, query, args=None): encoding = conn.encoding del self.messages[:] - if PYTHON3 and (not isinstance(query, str)): + if not isinstance(query, str): query = query.decode(encoding) - if (not PYTHON3) and isinstance(query, unicode): - query = query.encode(encoding) if args is not None: if isinstance(args, (tuple, list)): @@ -187,20 +183,16 @@ def callproc(self, procname, args=()): conn = self._get_db() for index, arg in enumerate(args): q = "SET @_%s_%d=%s" % (procname, index, conn.escape(arg)) - if PYTHON3 and (not isinstance(q, str)): + if not isinstance(q, str): q = q.decode(conn.encoding) - if (not PYTHON3) and isinstance(q, unicode): - q = q.encode(conn.encoding) self._query(q) self.nextset() q = "CALL %s(%s)" % (procname, ','.join(['@_%s_%d' % (procname, i) for i in range(len(args))])) - if PYTHON3 and (not isinstance(q, str)): + if not isinstance(q, str): q = q.decode(conn.encoding) - if (not PYTHON3) and isinstance(q, unicode): - q = q.encode(conn.encoding) self._query(q) self._executed = q diff --git a/cymysql/err.py b/cymysql/err.py index 2fc07e661..ba4bb3062 100644 --- a/cymysql/err.py +++ b/cymysql/err.py @@ -2,13 +2,8 @@ import sys from cymysql.constants import ER -PYTHON3 = sys.version_info[0] > 2 -if PYTHON3: - StandardError = Exception - - -class MySQLError(StandardError): +class MySQLError(Exception): """Exception related to operation with MySQL.""" def __init__(self, *args): @@ -21,7 +16,7 @@ def __init__(self, *args): super(MySQLError, self).__init__(*args) -class Warning(MySQLError): +class Warning(Warning, MySQLError): """Exception raised for important warnings like data truncations while inserting, etc.""" @@ -121,11 +116,7 @@ def _map_error(exc, *errors): def _get_error_info(data): errno = struct.unpack(' 2 - FIELD_TYPE_VAR_STRING = 253 UNSIGNED_CHAR_COLUMN = 251 @@ -21,25 +18,15 @@ def unpack_uint16(n): - if PYTHON3: - return n[0] + (n[1] << 8) - else: - return ord(n[0]) + (ord(n[1]) << 8) + return n[0] + (n[1] << 8) def unpack_uint24(n): - if PYTHON3: - return n[0] + (n[1] << 8) + (n[2] << 16) - else: - return ord(n[0]) + (ord(n[1]) << 8) + (ord(n[2]) << 16) + return n[0] + (n[1] << 8) + (n[2] << 16) def unpack_uint32(n): - if PYTHON3: - return n[0] + (n[1] << 8) + (n[2] << 16) + (n[3] << 24) - else: - return ord(n[0]) + (ord(n[1]) << 8) + \ - (ord(n[2]) << 16) + (ord(n[3]) << 24) + return n[0] + (n[1] << 8) + (n[2] << 16) + (n[3] << 24) def unpack_uint64(n): @@ -51,13 +38,12 @@ class MysqlPacket(object): from the network socket, removes packet header and provides an interface for reading/parsing the packet results.""" - def __init__(self, data, charset, encoding, use_unicode): + def __init__(self, data, charset, encoding): self._charset = charset self._encoding = encoding - self._use_unicode = use_unicode self.__position = 0 self.__data = data - is_error = self.__data[0] == (0xff if PYTHON3 else b'\xff') + is_error = self.__data[0] == 0xff if is_error: self.__position += 1 # field_count == error (we already know that) unpack_uint16(self._read(2)) # errno @@ -119,7 +105,7 @@ def _read_length_coded_string(self): def read_decode_data(self, fields, decoders): return tuple([ None if value is None - else decoder(value, self._encoding, field, self._use_unicode) + else decoder(value, self._encoding, field) if decoder in (convert_characters, convert_json) else decoder(value) for value, field, decoder in [ @@ -129,13 +115,13 @@ def read_decode_data(self, fields, decoders): ]) def is_ok_packet(self): - return self.__data[0] == (0 if PYTHON3 else b'\x00') + return self.__data[0] == 0 def is_eof_packet(self): - return self.__data[0] == (0xfe if PYTHON3 else b'\xfe') + return self.__data[0] == 0xfe def is_eof_and_status(self): - if self.__data[0] != (0xfe if PYTHON3 else b'\xfe'): + if self.__data[0] != 0xfe: return False, 0, 0 return True, unpack_uint16(self._read(2)), unpack_uint16(self._read(2)) diff --git a/cymysql/packet.pyx b/cymysql/packet.pyx index 6b7106325..dcae62441 100644 --- a/cymysql/packet.pyx +++ b/cymysql/packet.pyx @@ -43,15 +43,14 @@ cdef class MysqlPacket(object): """Representation of a MySQL response packet. Reads in the packet from the network socket, removes packet header and provides an interface for reading/parsing the packet results.""" - cdef object connection, _socket, _charset, _encoding, _use_unicode + cdef object connection, _socket, _charset, _encoding cdef bytes __data cdef int __position - def __init__(self, data, charset, encoding, use_unicode): + def __init__(self, data, charset, encoding): cdef int is_error self._charset = charset self._encoding = encoding - self._use_unicode = use_unicode self.__position = 0 self.__data = data is_error = ((self.__data[0])) == 0xff @@ -117,7 +116,7 @@ cdef class MysqlPacket(object): cpdef read_decode_data(self, fields, decoders): return tuple([ None if value is None - else decoder(value, self._encoding, field, self._use_unicode) + else decoder(value, self._encoding, field) if decoder in (convert_characters, convert_json) else decoder(value) for value, field, decoder in [ diff --git a/cymysql/result.py b/cymysql/result.py index d94d21309..a5f1cbcb7 100644 --- a/cymysql/result.py +++ b/cymysql/result.py @@ -28,7 +28,6 @@ def read_result(self): self.connection.socket.recv_packet(), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) if self.first_packet.is_ok_packet(): @@ -53,7 +52,6 @@ def read_rest_rowdata_packet(self): self.connection.socket.recv_packet(), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) is_eof, warning_count, server_status = packet.is_eof_and_status() if is_eof: @@ -74,7 +72,6 @@ def _get_descriptions(self): self.connection.socket.recv_packet(), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) self.fields.append(field) description.append(field.description()) @@ -83,7 +80,6 @@ def _get_descriptions(self): self.connection.socket.recv_packet(), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) assert eof_packet.is_eof_packet(), 'Protocol error, expecting EOF' self.description = tuple(description) @@ -96,7 +92,6 @@ def fetchone(self): self.connection.socket.recv_packet(), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) is_eof, warning_count, server_status = packet.is_eof_and_status() if is_eof: diff --git a/cymysql/result.pyx b/cymysql/result.pyx index b4d3193bf..0c49d2296 100644 --- a/cymysql/result.pyx +++ b/cymysql/result.pyx @@ -34,7 +34,6 @@ cdef class MySQLResult(object): self.connection.socket.recv_packet(), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) if self.first_packet.is_ok_packet(): @@ -60,7 +59,6 @@ cdef class MySQLResult(object): self.connection.socket.recv_packet(), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) is_eof, warning_count, server_status = packet.is_eof_and_status() if is_eof: @@ -83,7 +81,6 @@ cdef class MySQLResult(object): self.connection.socket.recv_packet(), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) self.fields.append(field) description.append(field.description()) @@ -92,7 +89,6 @@ cdef class MySQLResult(object): self.connection.socket.recv_packet(), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) assert eof_packet.is_eof_packet(), 'Protocol error, expecting EOF' self.description = tuple(description) @@ -106,7 +102,6 @@ cdef class MySQLResult(object): self.connection.socket.recv_packet(), self.connection.charset, self.connection.encoding, - self.connection.use_unicode, ) is_eof, warning_count, server_status = packet.is_eof_and_status() if is_eof: diff --git a/cymysql/socketwrapper.py b/cymysql/socketwrapper.py index 13b95f6ca..0c971ff69 100644 --- a/cymysql/socketwrapper.py +++ b/cymysql/socketwrapper.py @@ -1,4 +1,3 @@ -import sys import zlib try: import pyzstd @@ -6,21 +5,13 @@ pyzstd = None from cymysql.err import OperationalError -PYTHON3 = sys.version_info[0] > 2 - def pack_int24(n): - if PYTHON3: - return bytes([n & 0xFF, (n >> 8) & 0xFF, (n >> 16) & 0xFF]) - else: - return chr(n & 0xFF) + chr((n >> 8) & 0xFF) + chr((n >> 16) & 0xFF) + return bytes([n & 0xFF, (n >> 8) & 0xFF, (n >> 16) & 0xFF]) def unpack_uint24(n): - if PYTHON3: - return n[0] + (n[1] << 8) + (n[2] << 16) - else: - return ord(n[0]) + (ord(n[1]) << 8) + (ord(n[2]) << 16) + return n[0] + (n[1] << 8) + (n[2] << 16) class SocketWrapper(): diff --git a/cymysql/tests/__init__.py b/cymysql/tests/__init__.py index 2f5eb4e36..1902ebfb8 100644 --- a/cymysql/tests/__init__.py +++ b/cymysql/tests/__init__.py @@ -1,11 +1,8 @@ -import sys - from cymysql.tests.test_issues import * # noqa from cymysql.tests.test_example import * # noqa from cymysql.tests.test_basic import * # noqa from cymysql.tests.test_DictCursor import * # noqa -if sys.version_info[0] > 2: - from cymysql.tests.test_async import * # noqa +from cymysql.tests.test_async import * # noqa if __name__ == "__main__": diff --git a/cymysql/tests/base.py b/cymysql/tests/base.py index 437e28f7b..a950148b1 100644 --- a/cymysql/tests/base.py +++ b/cymysql/tests/base.py @@ -9,7 +9,7 @@ class PyMySQLTestCase(unittest.TestCase): test_passwd = os.environ.get("MYSQL_ROOT_PASSWORD", "") databases = [ {"host": test_host, "user": "root", - "passwd": test_passwd, "db": "test_cymysql", "use_unicode": True}, + "passwd": test_passwd, "db": "test_cymysql"}, {"host": test_host, "user": "root", "passwd": test_passwd, "db": "test_cymysql2"}] def setUp(self): diff --git a/cymysql/tests/test_basic.py b/cymysql/tests/test_basic.py index ca616f82a..6b0839850 100644 --- a/cymysql/tests/test_basic.py +++ b/cymysql/tests/test_basic.py @@ -4,18 +4,9 @@ import time import datetime import struct -import sys import unittest -def u(x): - if sys.version_info[0] < 3: - import codecs - return codecs.unicode_escape_decode(x)[0] - else: - return x - - def int2byte(i): return struct.pack("!B", i) @@ -50,7 +41,7 @@ def test_datatypes(self): 123456789012, 5.7, "hello'\" world", - u"Espa\xc3\xb1ol", + "Espa\xc3\xb1ol", "binary\x00data".encode(conn.encoding), datetime.date(1988, 2, 2), datetime.datetime(2014, 5, 15, 7, 45, 57), @@ -158,9 +149,9 @@ def test_untyped(self): conn = self.connections[0] c = conn.cursor() c.execute("select null,''") - self.assertEqual((None, u('')), c.fetchone()) + self.assertEqual((None, ''), c.fetchone()) c.execute("select '',null") - self.assertEqual((u(''), None), c.fetchone()) + self.assertEqual(('', None), c.fetchone()) def test_datetime(self): """ test conversion of null, empty string """ @@ -194,7 +185,7 @@ def test_callproc(self): c.callproc('test_proc', ('Foo', )) r = c.fetchall() self.assertEqual(len(r), 1) - self.assertEqual(r[0], (u'foo', )) + self.assertEqual(r[0], ('foo', )) class TestCursor(base.PyMySQLTestCase): diff --git a/cymysql/tests/test_issues.py b/cymysql/tests/test_issues.py index 047ca3ce8..b0be1417c 100644 --- a/cymysql/tests/test_issues.py +++ b/cymysql/tests/test_issues.py @@ -1,24 +1,10 @@ +import sys +import datetime import cymysql from cymysql.tests import base import unittest from time import sleep -import sys -import datetime - - -PYTHON3 = sys.version_info[0] > 2 -if PYTHON3: - # suppress flake8 error - unicode = str - - -def u(x): - if sys.version_info[0] < 3: - import codecs - return codecs.unicode_escape_decode(x)[0] - else: - return x class TestOldIssues(base.PyMySQLTestCase): @@ -119,9 +105,9 @@ def test_issue_15(self): c.execute("create table issue15 (t varchar(32))") try: - c.execute("insert into issue15 (t) values (%s)", (u('\xe4\xf6\xfc'),)) + c.execute("insert into issue15 (t) values (%s)", ('\xe4\xf6\xfc',)) c.execute("select t from issue15") - self.assertEqual(u('\xe4\xf6\xfc'), c.fetchone()[0]) + self.assertEqual('\xe4\xf6\xfc', c.fetchone()[0]) finally: c.execute("drop table issue15") @@ -159,14 +145,6 @@ def test_issue_17(self): c.execute("drop table issue17") -def _uni(s, e): - # hack for py3 - if sys.version_info[0] > 2: - return str(bytes(s, sys.getdefaultencoding()), e) - else: - return unicode(s, e) - - class TestNewIssues(base.PyMySQLTestCase): def test_issue_34(self): try: @@ -187,12 +165,12 @@ def test_issue_33(self): ) c = conn.cursor() try: - c.execute(_uni("create table hei\xc3\x9fe (name varchar(32))", "utf8")) - c.execute(_uni("insert into hei\xc3\x9fe (name) values ('Pi\xc3\xb1ata')", "utf8")) - c.execute(_uni("select name from hei\xc3\x9fe", "utf8")) - self.assertEqual(_uni("Pi\xc3\xb1ata", "utf8"), c.fetchone()[0]) + c.execute("create table hei\xc3\x9fe (name varchar(32))") + c.execute("insert into hei\xc3\x9fe (name) values ('Pi\xc3\xb1ata')") + c.execute("select name from hei\xc3\x9fe") + self.assertEqual("Pi\xc3\xb1ata", c.fetchone()[0]) finally: - c.execute(_uni("drop table hei\xc3\x9fe", "utf8")) + c.execute("drop table hei\xc3\x9fe") @unittest.skip("This test requires manual intervention") def test_issue_35(self): diff --git a/misc/mysqlproxy.py b/misc/mysqlproxy.py index cd20d1b47..5aa742b88 100755 --- a/misc/mysqlproxy.py +++ b/misc/mysqlproxy.py @@ -22,7 +22,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. ################################################################################ -from __future__ import print_function import sys import socket import binascii diff --git a/setup.py b/setup.py index 3837c504d..bf12eb47f 100644 --- a/setup.py +++ b/setup.py @@ -1,19 +1,7 @@ -from os.path import abspath, dirname, join import sys from setuptools import setup, Command, Extension - -versionpath = join(abspath(dirname(__file__)), 'cymysql', '__version__.py') -cymysql_version = {} - -if sys.version_info[:2] == (2, 7): - execfile(versionpath, cymysql_version) # noqa: F821 'execfile' Py3 - -elif sys.version_info >= (3, 5): - exec(open(versionpath, 'r').read(), cymysql_version) - -else: - raise ImportError("CyMySQL requires Python 2.7 or 3.5+") +import cymysql try: from Cython.Build import cythonize @@ -54,18 +42,10 @@ def run(self): cmdclass = {'test': TestCommand} -version_tuple = cymysql_version['VERSION'] - -if version_tuple[2] is not None: - version = "%d.%d.%s" % version_tuple -else: - version = "%d.%d" % version_tuple[:2] - classifiers = [ 'Development Status :: 4 - Beta', 'Operating System :: OS Independent', 'Programming Language :: Python', - 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 3', 'Topic :: Database', 'Topic :: Database :: Front-Ends', @@ -74,7 +54,7 @@ def run(self): setup( name="cymysql", - version=version, + version=cymysql.__version__, url='https://github.com/nakagami/CyMySQL/', classifiers=classifiers, keywords=['MySQL'],