diff --git a/CHANGELOG b/CHANGELOG index 91e9baa7..8ca2509a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,22 @@ # Changes +## 0.7 + +Release date: 2016-01-10 + +Notable changes: + +* Faster binary escaping +* Add `"_binary" prefix` to string literal for binary types. + binary types are: `bytearray` on Python 2, `bytes` and `bytearray` on Python 3. + This is because recent MySQL show warnings when string literal is invalid for + connection encoding. +* `pymysql.Binary()` returns `bytearray` on Python 2. This is required to distinguish + binary and string. +* Auth plugin support. +* no_delay option is ignored. It will be removed in PyMySQL 0.8. + + ## 0.6.7 Release date: 2015-09-30 diff --git a/pymysql/__init__.py b/pymysql/__init__.py index 1aa8fc71..778be6ef 100644 --- a/pymysql/__init__.py +++ b/pymysql/__init__.py @@ -1,7 +1,7 @@ -''' +""" PyMySQL: A pure-Python MySQL client library. -Copyright (c) 2010, 2013 PyMySQL contributors +Copyright (c) 2010-2016 PyMySQL contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,12 +20,10 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +""" +import sys -''' - -VERSION = (0, 6, 7, None) - -from ._compat import text_type, JYTHON, IRONPYTHON, PY2 +from ._compat import PY2 from .constants import FIELD_TYPE from .converters import escape_dict, escape_sequence, escape_string from .err import Warning, Error, InterfaceError, DataError, \ @@ -34,15 +32,14 @@ from .times import Date, Time, Timestamp, \ DateFromTicks, TimeFromTicks, TimestampFromTicks -import sys - +VERSION = (0, 7, 0, None) threadsafety = 1 apilevel = "2.0" -paramstyle = "format" +paramstyle = "pyformat" -class DBAPISet(frozenset): +class DBAPISet(frozenset): def __ne__(self, other): if isinstance(other, set): @@ -73,15 +70,15 @@ def __hash__(self): DATETIME = TIMESTAMP ROWID = DBAPISet() + def Binary(x): """Return x as a binary type.""" - if isinstance(x, text_type) and not (JYTHON or IRONPYTHON): - x = x.encode() if PY2: return bytearray(x) else: return bytes(x) + def Connect(*args, **kwargs): """ Connect to the database; see connections.Connection.__init__() for @@ -92,11 +89,10 @@ def Connect(*args, **kwargs): from pymysql import connections as _orig_conn if _orig_conn.Connection.__init__.__doc__ is not None: - Connect.__doc__ = _orig_conn.Connection.__init__.__doc__ + (""" -See connections.Connection.__init__() for information about defaults. -""") + Connect.__doc__ = _orig_conn.Connection.__init__.__doc__ del _orig_conn + def get_client_info(): # for MySQLdb compatibility return '.'.join(map(str, VERSION)) @@ -110,7 +106,7 @@ def get_client_info(): # for MySQLdb compatibility __version__ = get_client_info() def thread_safe(): - return True # match MySQLdb.thread_safe() + return True # match MySQLdb.thread_safe() def install_as_MySQLdb(): """ @@ -119,6 +115,7 @@ def install_as_MySQLdb(): """ sys.modules["MySQLdb"] = sys.modules["_mysql"] = sys.modules["pymysql"] + __all__ = [ 'BINARY', 'Binary', 'Connect', 'Connection', 'DATE', 'Date', 'Time', 'Timestamp', 'DateFromTicks', 'TimeFromTicks', 'TimestampFromTicks', @@ -131,6 +128,5 @@ def install_as_MySQLdb(): 'paramstyle', 'threadsafety', 'version_info', "install_as_MySQLdb", - - "NULL","__version__", - ] + "NULL", "__version__", +] diff --git a/pymysql/connections.py b/pymysql/connections.py index c9f05979..1571325b 100644 --- a/pymysql/connections.py +++ b/pymysql/connections.py @@ -521,7 +521,6 @@ class Connection(object): The proper way to get an instance of this class is to call connect(). - """ socket = None diff --git a/pymysql/tests/test_connection.py b/pymysql/tests/test_connection.py index 454d6c76..518b6fe7 100644 --- a/pymysql/tests/test_connection.py +++ b/pymysql/tests/test_connection.py @@ -1,10 +1,10 @@ import datetime -import decimal import sys import time import unittest2 import pymysql from pymysql.tests import base +from pymysql._compat import text_type class TempUser: @@ -534,7 +534,7 @@ def test_escape_fallback_encoder(self): class Custom(str): pass - mapping = {pymysql.text_type: pymysql.escape_string} + mapping = {text_type: pymysql.escape_string} self.assertEqual(con.escape(Custom('foobar'), mapping), "'foobar'") def test_escape_no_default(self): diff --git a/pymysql/tests/thirdparty/test_MySQLdb/capabilities.py b/pymysql/tests/thirdparty/test_MySQLdb/capabilities.py index b0f7cb90..e4aae206 100644 --- a/pymysql/tests/thirdparty/test_MySQLdb/capabilities.py +++ b/pymysql/tests/thirdparty/test_MySQLdb/capabilities.py @@ -32,7 +32,8 @@ def setUp(self): self.BLOBUText = unicode().join(unichr(i) for i in range(16834)) else: self.BLOBUText = "".join(chr(i) for i in range(16834)) - self.BLOBBinary = self.db_module.Binary(''.join([chr(i) for i in range(256)] * 16)) + data = bytearray(range(256)) * 16 + self.BLOBBinary = self.db_module.Binary(data) leak_test = True diff --git a/pymysql/tests/thirdparty/test_MySQLdb/dbapi20.py b/pymysql/tests/thirdparty/test_MySQLdb/dbapi20.py index d6fcabf9..e8665248 100644 --- a/pymysql/tests/thirdparty/test_MySQLdb/dbapi20.py +++ b/pymysql/tests/thirdparty/test_MySQLdb/dbapi20.py @@ -827,8 +827,8 @@ def test_Timestamp(self): # self.assertEqual(str(t1),str(t2)) def test_Binary(self): - b = self.driver.Binary('Something') - b = self.driver.Binary('') + b = self.driver.Binary(b'Something') + b = self.driver.Binary(b'') def test_STRING(self): self.assertTrue(hasattr(self.driver,'STRING'), diff --git a/setup.cfg b/setup.cfg index 992ddaba..06be91c6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,4 +4,4 @@ universal = 1 [flake8] ignore = E226,E301,E701 exclude = tests,build -max-line-length = 99 +max-line-length = 119 diff --git a/setup.py b/setup.py index 92873a16..07371596 100755 --- a/setup.py +++ b/setup.py @@ -16,12 +16,11 @@ author_email='yutaka.matsubara@gmail.com', maintainer='INADA Naoki', maintainer_email='songofacandy@gmail.com', - description='Pure-Python MySQL Driver', + description='Pure Python MySQL Driver', license="MIT", packages=find_packages(), classifiers=[ 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', @@ -33,5 +32,5 @@ 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Topic :: Database', - ] + ], )