[Python-modules-commits] [mysql-connector-python] 02/09: Import mysql-connector-python_2.1.3.orig.tar.gz
Sandro Tosi
morph at moszumanska.debian.org
Fri Jun 17 20:11:43 UTC 2016
This is an automated email from the git hooks/post-receive script.
morph pushed a commit to branch master
in repository mysql-connector-python.
commit e07fecd08fbb0adb43a55d83a086901d3d7f86e6
Author: Sandro Tosi <morph at debian.org>
Date: Fri Jun 17 20:21:48 2016 +0100
Import mysql-connector-python_2.1.3.orig.tar.gz
---
CHANGES.txt | 92 +-
MANIFEST.in | 1 +
PKG-INFO | 2 +-
README.txt | 2 +-
examples/microseconds.py | 24 +-
examples/warnings.py | 13 +-
lib/cpy_distutils.py | 582 +++++
lib/mysql/connector/__init__.py | 31 +-
lib/mysql/connector/abstracts.py | 1161 +++++++++
lib/mysql/connector/authentication.py | 4 +-
lib/mysql/connector/catch23.py | 31 +-
lib/mysql/connector/charsets.py | 6 +-
lib/mysql/connector/connection.py | 802 +-----
lib/mysql/connector/connection_cext.py | 593 +++++
lib/mysql/connector/constants.py | 60 +-
lib/mysql/connector/conversion.py | 95 +-
lib/mysql/connector/cursor.py | 170 +-
lib/mysql/connector/cursor_cext.py | 810 ++++++
lib/mysql/connector/django/base.py | 522 ++--
lib/mysql/connector/django/client.py | 26 +-
lib/mysql/connector/django/compiler.py | 35 +-
lib/mysql/connector/django/creation.py | 72 +-
lib/mysql/connector/django/features.py | 127 +
lib/mysql/connector/django/introspection.py | 193 +-
lib/mysql/connector/django/operations.py | 308 +++
lib/mysql/connector/django/schema.py | 37 +-
lib/mysql/connector/django/validation.py | 9 +-
lib/mysql/connector/errorcode.py | 222 +-
lib/mysql/connector/errors.py | 16 +-
lib/mysql/connector/fabric/__init__.py | 6 -
lib/mysql/connector/fabric/caching.py | 4 +-
lib/mysql/connector/fabric/connection.py | 419 +++-
lib/mysql/connector/locales/eng/client_error.py | 9 +-
lib/mysql/connector/optionfiles.py | 4 +-
lib/mysql/connector/pooling.py | 1 -
lib/mysql/connector/protocol.py | 35 +-
lib/mysql/connector/version.py | 2 +-
setup.py | 5 +-
setupinfo.py | 28 +-
src/exceptions.c | 211 ++
.../version.py => src/force_cpp_linkage.cc | 24 +-
src/include/catch23.h | 91 +
.../version.py => src/include/exceptions.h | 22 +-
src/include/mysql_capi.h | 222 ++
.../include/mysql_capi_conversion.h | 98 +-
.../version.py => src/include/mysql_connector.h | 24 +-
src/mysql_capi.c | 2601 ++++++++++++++++++++
src/mysql_capi_conversion.c | 763 ++++++
src/mysql_connector.c | 340 +++
tests/__init__.py | 322 ++-
tests/cext/__init__.py | 0
tests/cext/test_cext_api.py | 763 ++++++
tests/cext/test_cext_connection.py | 115 +
tests/cext/test_cext_cursor.py | 573 +++++
tests/mysqld.py | 115 +-
tests/test_abstracts.py | 281 +++
tests/test_authentication.py | 6 +-
tests/test_bugs.py | 2042 +++++++++------
tests/test_connection.py | 379 +--
tests/test_constants.py | 41 +-
tests/test_cursor.py | 30 +-
tests/test_django.py | 76 +-
tests/test_examples.py | 60 +-
tests/test_fabric.py | 20 +-
tests/test_mysql_datatypes.py | 110 +-
tests/test_network.py | 4 -
tests/test_pep249.py | 14 +-
tests/test_protocol.py | 9 +-
unittests.py | 109 +-
69 files changed, 13227 insertions(+), 2797 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 7ee20de..54e1219 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,5 @@
====================================================
-MySQL Connector/Python 2.0 - Release Notes & Changes
+MySQL Connector/Python 2.1 - Release Notes & Changes
====================================================
MySQL Connector/Python
@@ -8,71 +8,51 @@ Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
Full release notes:
http://dev.mysql.com/doc/relnotes/connector-python/en/
-v2.0.4
+v2.1.3
======
-- BUG20324089: Fix HASH based sharding with MySQL Fabric
+- BUG#21782246: Fix Install check of bitness of libmysql c client fails
+- BUG#21505096: MySQL Connector python 2.1.2 does not ship with required __init.py__ files
+- BUG#21499127: Fix copyright year in README.txt
+- BUG#21420633: Fix CExtension crashing while fetching large number of NULL value
+- BUG#21420906: Fix connect using SHA256 user with blank password
+- BUG#21090014: Fix handshake with MySQL server 5.5.8
+- BUG#21054559: Using a binary field in Django raises an exception
+- BUG#21054556: Attribute error raised with Django
+- BUG#20638660: The account_locked needs value for MySQL 5.7.6
+- BUG#20653441: C/Py hangs if a query is killed
+- BUG#20987205: C/Py Django backend doesn't work with Django 1.8
+- BUG#21492815: Fix callproc when consuming results turned on
+- BUG#21529781: Fix usage of auth_plugin option with CExtension
+- BUG#21535573: Fix character decoding of identifiers using CExtension
+- BUG#21536507: Fix raising warnings as exceptions
+- BUG#21490865: Fix compiling CExtension with relocated libmysqlclient
+- BUG#21492428: Fix using passwords with leading/trailing whitespaces
+- BUG#21541244: Fix running unit tests for MySQL server 5.5
+- BUG#21782246: Fix Install check of bitness of libmysql c client fails
+
+v2.1.2b1
+========
+
+- WL7956: Support MySQL Protocol connecting to MySQL Fabric
- BUG20462427: Fix receiving large field data from server
+- BUG20365619: Fix MySQL version detection for C Extension
- BUG20301989: Fix conversion of empty set
- BUG20407036: Fix incorrect arguments to mysld_stmt_execute error
- BUG20106629: Support Django Safetext and SafeBytes type
-
-v2.0.3
-======
-
-- BUG19703022: Fix using passwords with integers only in option files
+- BUG20324089: Fix HASH baesd sharding with MySQL Fabric
+- BUG20217174: Fix install command honouring --install-lib when given
- BUG19777815: Add support for warnings with MySQLCursor.callproc()
+- BUG19331658: Fix connection pooling with fabric
- BUG19972427: Fix creating of redundant connections in Django
-- BUG19331658: Fix connection pooling with MySQL Fabric
-- BUG19930054: Lost connection to server error during query
+- BUG20022533: Fix failing Django inspectdb command with C/Python
+- BUG19703022: Fix using passwords with integers only in option files
- BUG19803702: Fix reporting errors with non-ascii characters
+- BUG20834643: Attribute Error while promoting servers using MySQL Fabric
+- BUG20811802: Fix buffered named tuple cursor with CExtension
-v2.0.2
-======
-
-- BUG19500097: Fix string decoding with binary character set
-- BUG19677659: Move testings of errors to internal repository
-- BUG19549363: Raise error when compression used with reset_session
-- BUG19642249: Improve errors reporting invalid sharding keys
-- BUG19711759: Fix Pylint issue in network module
-- BUG19667984: Fix converting invalid datetime values in Django backend
-- BUG19660283: Fix failing unit tests with MySQL server 5.7.5
-- BUG19584051: Fix comparison of type_code of columns for PEP-249
-- BUG19522948: Fix data corruption with TEXT and prepared statements
-- BUG19584116: Fix extra signal causing runtime error in Django
-
-
-v2.0.1
-======
-
-- WL7954: Add support for RANGE_STRING Fabric sharding type
-- WL7955: Add support for RANGE_DATETIME Fabric sharding type
-- BUG19440592: Fix exception not captured when SSL is unavailable
-- BUG19481761: Fix option files with !include with trailing newline
-- BUG18798953: Add MySQLConnection.shutdown() to abruply close connection
-- BUG19168737: Fix unsupported connection argument error with option files
-- BUG19282158: Fix NULL values to work with prepared statements
-- BUG19179711: Fix using '%s' in django backend
-- BUG19169143: Fix raising error with duplicate option files
-- BUG19170287: Fix duplicate section error with Python v3
-- BUG19163169: Add support for Django 1.7
-- BUG19225481: Fix floating point inaccuracy with Python v2
-- BUG19164627: Fix cursor trying to decode linestring data as utf-8
-
-
-v2.0.0a1
+v2.1.1a1
========
-- BUG19207922: Fix fetching multiple results when executing procedure
-- BUG19184025: Fix results containing NULL
-- BUG19169990: Fix sending/receiving using compressed connection
-- BUG18956789: Fix Django TimeField 00:00:00 converting to MySQL NULL
-- WL7228: Allow Connector/Python to use MySQL option files
-- BUG18843153: Fix Django to check connection on each request
-- WL7937: Allow LOAD DATA LOCAL INFILE by default
-- BUG18742429: Fix prepared statements returning lots of columns
-- BUG18814880: Fix stopping mysqld running unit tests on Windows
-- WL7292: Add cursors returning dict and namedtuple as rows
-- WL7462: Consolidate Python v2 and v3 code
-- WL7716: Move commercial files and distribution to CPYINT
+- WL7643: Add Python C Extension using Connector/C
diff --git a/MANIFEST.in b/MANIFEST.in
index 58d45d3..4f1836b 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -9,6 +9,7 @@ include MANIFEST.in
recursive-include examples *.py
recursive-include lib *.py
recursive-include tests *.py *.csv *.pem *.cnf
+recursive-include src *.c *.h *.cc
include docs/README_DOCS.txt
diff --git a/PKG-INFO b/PKG-INFO
index de8b3a5..2ab16ed 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: mysql-connector-python
-Version: 2.0.4
+Version: 2.1.3
Summary: MySQL driver written in Python
Home-page: http://dev.mysql.com/doc/connector-python/en/index.html
Author: Oracle and/or its affiliates
diff --git a/README.txt b/README.txt
index 2f88034..8d4cc3d 100644
--- a/README.txt
+++ b/README.txt
@@ -1,5 +1,5 @@
==========================
-MySQL Connector/Python 2.0
+MySQL Connector/Python 2.1
==========================
MySQL Connector/Python
diff --git a/examples/microseconds.py b/examples/microseconds.py
index a92a290..396241c 100644
--- a/examples/microseconds.py
+++ b/examples/microseconds.py
@@ -36,7 +36,7 @@ Story: We keep track of swimmers in a freestyle 4x 100m relay swimming event
with millisecond precision.
"""
-from datetime import time
+from datetime import time, datetime
import mysql.connector
@@ -45,6 +45,7 @@ CREATE_TABLE = (
"teamid TINYINT UNSIGNED NOT NULL, "
"swimmer TINYINT UNSIGNED NOT NULL, "
"lap TIME(3), "
+ "start_shot DATETIME(6), "
"PRIMARY KEY (teamid, swimmer)"
") ENGINE=InnoDB"
)
@@ -68,24 +69,29 @@ def main(config):
teams = {}
teams[1] = [
- (1, time(second=47, microsecond=510000)),
- (2, time(second=47, microsecond=20000)),
- (3, time(second=47, microsecond=650000)),
- (4, time(second=46, microsecond=60000)),
+ (1, time(second=47, microsecond=510000),
+ datetime(2009, 6, 7, 9, 15, 2, 234)),
+ (2, time(second=47, microsecond=20000),
+ datetime(2009, 6, 7, 9, 30, 5, 102345)),
+ (3, time(second=47, microsecond=650000),
+ datetime(2009, 6, 7, 9, 50, 23, 2300)),
+ (4, time(second=46, microsecond=60000),
+ datetime(2009, 6, 7, 10, 30, 56, 1)),
]
- insert = "INSERT INTO relay_laps (teamid,swimmer,lap) VALUES (%s,%s,%s)"
+ insert = ("INSERT INTO relay_laps (teamid, swimmer, lap, start_shot) "
+ "VALUES (%s, %s, %s, %s)")
for team, swimmers in teams.items():
for swimmer in swimmers:
- cursor.execute(insert, (team, swimmer[0], swimmer[1]))
+ cursor.execute(insert, (team, swimmer[0], swimmer[1], swimmer[2]))
cnx.commit()
cursor.execute("SELECT * FROM relay_laps")
for row in cursor:
- output.append("{0: 2d} | {1: 2d} | {2}".format(*row))
+ output.append("{0: 2d} | {1: 2d} | {2} | {3}".format(*row))
try:
- cursor.execute("DROP TABLE IF EXISTS relay_laps")
+ cursor.execute("DROP TABLE IF EXISTS relay_lapss")
except:
# Ignoring the fact that it was not there
pass
diff --git a/examples/warnings.py b/examples/warnings.py
index 3094c88..bd87c83 100755
--- a/examples/warnings.py
+++ b/examples/warnings.py
@@ -64,7 +64,16 @@ if __name__ == '__main__':
#
# Configure MySQL login and database to use in config.py
#
- import config
- config = config.Config.dbinfo().copy()
+ config = {
+ 'host': 'localhost',
+ 'port': 3306,
+ 'database': 'test',
+ 'user': 'root',
+ 'password': '',
+ 'charset': 'utf8',
+ 'use_unicode': True,
+ 'get_warnings': True,
+ }
+
out = main(config)
print('\n'.join(out))
diff --git a/lib/cpy_distutils.py b/lib/cpy_distutils.py
new file mode 100644
index 0000000..fbddc84
--- /dev/null
+++ b/lib/cpy_distutils.py
@@ -0,0 +1,582 @@
+# MySQL Connector/Python - MySQL driver written in Python.
+# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+
+
+# MySQL Connector/Python is licensed under the terms of the GPLv2
+# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
+# MySQL Connectors. There are special exceptions to the terms and
+# conditions of the GPLv2 as it is applied to this software, see the
+# FOSS License Exception
+# <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Implements the DistUtils command 'build_ext'
+"""
+
+from distutils.command.build_ext import build_ext
+from distutils.command.install import install
+from distutils.command.install_lib import install_lib
+from distutils.errors import DistutilsExecError
+from distutils.util import get_platform
+from distutils.dir_util import copy_tree
+from distutils import log
+from glob import glob
+import os
+import shlex
+import struct
+from subprocess import Popen, PIPE, STDOUT
+import sys
+import platform
+
+ARCH_64BIT = sys.maxsize > 2**32 # Works with Python 2.6 and greater
+py_arch = '64-bit' if ARCH_64BIT else '32-bit'
+
+CEXT_OPTIONS = [
+ ('with-mysql-capi=', None,
+ "Location of MySQL C API installation or path to mysql_config"),
+]
+
+CEXT_STATIC_OPTIONS = [
+ ('static', None,
+ "Link C libraries statically with the C Extension"),
+]
+
+INSTALL_OPTIONS = [
+ ('byte-code-only=', None,
+ "Remove Python .py files; leave byte code .pyc only"),
+]
+
+
+def win_dll_is64bit(dll_file):
+ """Check if a Windows DLL is 64 bit or not
+
+ Returns True if the library dll_file is 64bit.
+
+ Raises ValueError when magic of header is invalid.
+ Raises IOError when file could not be read.
+ Raises OSError when execute on none-Windows platform.
+
+ Returns True or False.
+ """
+ if os.name != 'nt':
+ raise OSError("win_ddl_is64bit only useful on Windows")
+
+ with open(dll_file, 'rb') as fp:
+ # IMAGE_DOS_HEADER
+ e_magic = fp.read(2)
+ if e_magic != b'MZ':
+ raise ValueError("Wrong magic in header")
+
+ fp.seek(60)
+ offset = struct.unpack("I", fp.read(4))[0]
+
+ # IMAGE_FILE_HEADER
+ fp.seek(offset)
+ file_header = fp.read(6)
+ (signature, machine) = struct.unpack("<4sH", file_header)
+ if machine == 0x014c: # IMAGE_FILE_MACHINE_I386
+ return False
+ elif machine in (0x8664, 0x2000): # IMAGE_FILE_MACHINE_I386/AMD64
+ return True
+
+
+def unix_lib_is64bit(lib_file):
+ """Check if a library on UNIX is 64 bit or not
+
+ This function uses the `file` command to check if a library on
+ UNIX-like platforms is 32 or 64 bit.
+
+ Returns True if the library is 64bit.
+
+ Raises ValueError when magic of header is invalid.
+ Raises IOError when file could not be read.
+ Raises OSError when execute on none-Windows platform.
+
+ Returns True or False.
+ """
+ if os.name != 'posix':
+ raise OSError("unix_lib_is64bit only useful on UNIX-like systems")
+
+ if os.isdir(lib_file):
+ mysqlclient_libs = []
+ for root, _, files in os.walk(lib_file):
+ for filename in files:
+ filepath = os.path.join(root, filename)
+ if filename.startswith('libmysqlclient') and \
+ not os.path.islink(filepath) and \
+ '_r' not in filename and \
+ '.a' not in filename:
+ mysqlclient_libs.append(filepath)
+ if mysqlclient_libs:
+ break
+ # give priority to .so files instead of .a
+ mysqlclient_libs.sort()
+ lib_file = mysqlclient_libs[-1]
+
+ log.debug("# Using file command to test lib_file {0}".format(lib_file))
+ prc = Popen(['file', '-L', lib_file], stdin=PIPE, stderr=STDOUT,
+ stdout=PIPE)
+ stdout = prc.communicate()[0]
+ stdout = stdout.split(':')[1]
+ log.debug("# lib_file {0} stdout: {1}".format(lib_file, stdout))
+ if 'x86_64' in stdout or 'x86-64' in stdout or '32-bit' not in stdout:
+ return True
+
+ return False
+
+
+def get_mysql_config_info(mysql_config):
+ """Get MySQL information using mysql_config tool
+
+ Returns a dict.
+ """
+ options = ['cflags', 'include', 'libs', 'libs_r', 'plugindir', 'version']
+
+ cmd = [mysql_config] + [ "--{0}".format(opt) for opt in options ]
+
+ try:
+ proc = Popen(cmd, stdout=PIPE, universal_newlines=True)
+ stdout, _ = proc.communicate()
+ except OSError as exc:
+ raise DistutilsExecError("Failed executing mysql_config: {0}".format(
+ str(exc)))
+ log.debug("# stdout: {0}".format(stdout))
+ info = {}
+ for option, line in zip(options, stdout.split('\n')):
+ log.debug("# option: {0}".format(option))
+ log.debug("# line: {0}".format(line))
+ info[option] = line.strip()
+
+ ver = info['version']
+ if '-' in ver:
+ ver, _ = ver.split('-', 2)
+
+ info['version'] = tuple([int(v) for v in ver.split('.')[0:3]])
+ libs = shlex.split(info['libs'])
+ info['lib_dir'] = libs[0].replace('-L', '')
+ info['libs'] = [ lib.replace('-l', '') for lib in libs[1:] ]
+ log.debug("# info['libs']: ")
+ for lib in info['libs']:
+ log.debug("# {0}".format(lib))
+ log.error("# info['libs']: {0}".format(info['libs']))
+ libs = shlex.split(info['libs_r'])
+ info['lib_r_dir'] = libs[0].replace('-L', '')
+ info['libs_r'] = [ lib.replace('-l', '') for lib in libs[1:] ]
+
+ info['include'] = info['include'].replace('-I', '')
+
+ # Try to figure out the architecture
+ info['arch'] = None
+ if os.name == 'posix':
+ pathname = os.path.join(info['lib_dir'], 'lib' + info['libs'][0]) + '*'
+ libs = glob(pathname)
+ log.debug("# libs: {0}".format(libs))
+ for lib in libs:
+ log.debug("#- {0}".format(lib))
+ mysqlclient_libs = []
+ for filepath in libs:
+ _, filename = os.path.split(filepath)
+ log.debug("# filename {0}".format(filename))
+ if filename.startswith('libmysqlclient') and \
+ not os.path.islink(filepath) and \
+ '_r' not in filename and \
+ '.a' not in filename:
+ mysqlclient_libs.append(filepath)
+ mysqlclient_libs.sort()
+
+ stdout = None
+ try:
+ log.debug("# mysqlclient_lib: {0}".format(mysqlclient_libs[-1]))
+ for mysqlclient_lib in mysqlclient_libs:
+ log.debug("#+ {0}".format(mysqlclient_lib))
+ log.debug("# tested mysqlclient_lib[-1]: "
+ "{0}".format(mysqlclient_libs[-1]))
+ proc = Popen(['file', '-L', mysqlclient_libs[-1]], stdout=PIPE,
+ universal_newlines=True)
+ stdout, _ = proc.communicate()
+ stdout = stdout.split(':')[1]
+ except OSError as exc:
+ raise DistutilsExecError(
+ "Although the system seems POSIX, the file-command could not "
+ "be executed: {0}".format(str(exc)))
+
+ if stdout:
+ if '64' in stdout:
+ info['arch'] = "x86_64"
+ else:
+ info['arch'] = "i386"
+ else:
+ raise DistutilsExecError(
+ "Failed getting out put from the file-command"
+ )
+ else:
+ raise DistutilsExecError(
+ "Cannot determine architecture on {0} systems".format(os.name))
+
+ return info
+
+
+def remove_cext(distribution):
+ """Remove the C Extension from the distribution
+
+ This function can be useful in Distutils commands for creating
+ pure Python modules.
+ """
+ to_remove = []
+ for ext_mod in distribution.ext_modules:
+ if ext_mod.name == '_mysql_connector':
+ to_remove.append(ext_mod)
+ for ext_mod in to_remove:
+ distribution.ext_modules.remove(ext_mod)
+
+
+class BuildExtDynamic(build_ext):
+
+ """Build Connector/Python C Extension"""
+
+ description = "build Connector/Python C Extension"
+
+ user_options = build_ext.user_options + CEXT_OPTIONS
+
+ min_connector_c_version = None
+ arch = None
+ _mysql_config_info = None
+
+ def initialize_options(self):
+ build_ext.initialize_options(self)
+ self.with_mysql_capi = None
+
+ def _finalize_connector_c(self, connc_loc):
+ """Finalize the --with-connector-c command line argument
+ """
+ platform = get_platform()
+ self._mysql_config_info = None
+ min_version = BuildExtDynamic.min_connector_c_version
+
+ err_invalid_loc = "MySQL C API location is invalid; was %s"
+
+ mysql_config = None
+ err_version = "MySQL C API {0}.{1}.{2} or later required".format(
+ *BuildExtDynamic.min_connector_c_version)
+
+ if not os.path.exists(connc_loc):
+ log.error(err_invalid_loc, connc_loc)
+ sys.exit(1)
+
+ if os.path.isdir(connc_loc):
+ # if directory, and no mysql_config is available, figure out the
+ # lib/ and include/ folders from the the filesystem
+ mysql_config = os.path.join(connc_loc, 'bin', 'mysql_config')
+ if os.path.isfile(mysql_config) and \
+ os.access(mysql_config, os.X_OK):
+ connc_loc = mysql_config
+ log.debug("# connc_loc: {0}".format(connc_loc))
+ else:
+ # Probably using MS Windows
+ myconfigh = os.path.join(connc_loc, 'include', 'my_config.h')
+
+ if not os.path.exists(myconfigh):
+ log.error("MySQL C API installation invalid "
+ "(my_config.h not found)")
+ sys.exit(1)
+ else:
+ with open(myconfigh, 'rb') as fp:
+ for line in fp.readlines():
+ if b'#define VERSION' in line:
+ version = tuple([
+ int(v) for v in
+ line.split()[2].replace(
+ b'"', b'').split(b'.')
+ ])
+ if version < min_version:
+ log.error(err_version);
+ sys.exit(1)
+ break
+
+ # On Windows we check libmysql.dll
+ if os.name == 'nt':
+ lib = os.path.join(self.with_mysql_capi, 'lib',
+ 'libmysql.dll')
+ connc_64bit = win_dll_is64bit(lib)
+ # On OSX we check libmysqlclient.dylib
+ elif 'macos' in platform:
+ lib = os.path.join(self.with_mysql_capi, 'lib',
+ 'libmysqlclient.dylib')
+ connc_64bit = unix_lib_is64bit(lib)
+ # On other Unices we check libmysqlclient (follow symlinks)
+ elif os.name == 'posix':
+ connc_64bit = unix_lib_is64bit(connc_loc)
+ else:
+ raise OSError("Unsupported platform: %s" % os.name)
+
+ include_dir = os.path.join(connc_loc, 'include')
+ if os.name == 'nt':
+ libraries = ['libmysql']
+ else:
+ libraries = ['-lmysqlclient']
+ library_dirs = os.path.join(connc_loc, 'lib')
+
+ log.debug("# connc_64bit: {0}".format(connc_64bit))
+ if connc_64bit:
+ self.arch = 'x86_64'
+ else:
+ self.arch = 'i386'
+
+ # We were given the location of the mysql_config tool (not on Windows)
+ if not os.name == 'nt' and os.path.isfile(connc_loc) \
+ and os.access(connc_loc, os.X_OK):
+ mysql_config = connc_loc
+ # Check mysql_config
+ myc_info = get_mysql_config_info(mysql_config)
+ log.debug("# myc_info: {0}".format(myc_info))
+
+ if myc_info['version'] < min_version:
+ log.error(err_version)
+ sys.exit(1)
+
+ include_dir = myc_info['include']
+ libraries = myc_info['libs']
+ library_dirs = myc_info['lib_dir']
+ self._mysql_config_info = myc_info
+ self.arch = self._mysql_config_info['arch']
+ connc_64bit = self.arch == 'x86_64'
+
+ if not os.path.exists(include_dir):
+ log.error(err_invalid_loc, connc_loc)
+ sys.exit(1)
+
+ # Set up the build_ext class
+ self.include_dirs.append(include_dir)
+ self.libraries.extend(libraries)
+ self.library_dirs.append(library_dirs)
+
+ # We try to offer a nice message when the architecture of Python
+ # is not the same as MySQL Connector/C binaries.
+ py_arch = '64-bit' if ARCH_64BIT else '32-bit'
+ log.debug("# Python architecture: {0}".format(py_arch))
+ log.debug("# Python ARCH_64BIT: {0}".format(ARCH_64BIT))
+ log.debug("# self.arch: {0}".format(self.arch))
+ if ARCH_64BIT != connc_64bit:
+ log.error("Python is {0}, but does not "
+ "match MySQL C API {1} architecture, "
+ "type: {2}"
+ "".format(py_arch,
+ '64-bit' if connc_64bit else '32-bit',
+ self.arch))
+ sys.exit(1)
+
+ def finalize_options(self):
+ self.set_undefined_options('install',
+ ('with_mysql_capi', 'with_mysql_capi'))
+
+ build_ext.finalize_options(self)
+
+ if self.with_mysql_capi:
+ self._finalize_connector_c(self.with_mysql_capi)
+
+ def fix_compiler(self):
+ platform = get_platform()
+
+ cc = self.compiler
+ if not cc:
+ return
+
+ if 'macosx-10.9' in platform:
+ for needle in ['-mno-fused-madd']:
+ try:
+ cc.compiler.remove(needle)
+ cc.compiler_so.remove(needle)
+ except ValueError:
+ # We are removing, so OK when needle not there
+ pass
+
+ for name, args in cc.__dict__.items():
+ if not args or not isinstance(args, list):
+ continue
+
+ new_args = []
+ enum_args = enumerate(args)
+ for i, arg in enum_args:
+ if arg == '-arch':
+ # Skip not needed architecture
+ if args[i+1] != self.arch:
+ next(enum_args)
+ else:
+ new_args.append(arg)
+ else:
+ new_args.append(arg)
+
+ try:
+ cc.setattr(name, new_args)
+ except AttributeError:
+ # Old class
+ cc.__dict__[name] = new_args
+
+ # Add system headers to Extensions extra_compile_args
+ sysheaders = [ '-isystem' + dir for dir in cc.include_dirs]
+ for ext in self.extensions:
+ for sysheader in sysheaders:
+ if sysheader not in ext.extra_compile_args:
+ ext.extra_compile_args.append(sysheader)
+
+ # Stop warnings about unknown pragma
+ if os.name != 'nt':
+ ext.extra_compile_args.append('-Wno-unknown-pragmas')
+
+ def run(self):
+ """Run the command"""
+ if not self.with_mysql_capi:
+ return
+
+ if os.name == 'nt':
+ build_ext.run(self)
+ else:
+ self.real_build_extensions = self.build_extensions
+ self.build_extensions = lambda: None
+ build_ext.run(self)
+ self.fix_compiler()
+ self.real_build_extensions()
+
+
+class BuildExtStatic(BuildExtDynamic):
+
+ """Build and Link libraries statically with the C Extensions"""
+
+ user_options = build_ext.user_options + CEXT_OPTIONS
+
+ def finalize_options(self):
+ if not self.with_mysql_capi:
+ self.set_undefined_options('install',
+ ('with_mysql_capi', 'with_mysql_capi'))
+
+ build_ext.finalize_options(self)
+ self.connc_lib = os.path.join(self.build_temp, 'connc', 'lib')
+ self.connc_include = os.path.join(self.build_temp, 'connc', 'include')
+
+ if self.with_mysql_capi:
+ self._finalize_connector_c(self.with_mysql_capi)
+
+ def _finalize_connector_c(self, connc_loc):
+ if not os.path.isdir(connc_loc):
+ log.error("MySQL C API should be a directory")
+ sys.exit(1)
+
+ copy_tree(os.path.join(connc_loc, 'lib'), self.connc_lib)
+ copy_tree(os.path.join(connc_loc, 'include'), self.connc_include)
+
+ # Remove all but static libraries to force static linking
+ for lib_file in os.listdir(self.connc_lib):
+ if os.name == 'posix' and not lib_file.endswith('.a'):
+ os.unlink(os.path.join(self.connc_lib, lib_file))
+
+ def fix_compiler(self):
+ BuildExtDynamic.fix_compiler(self)
+
+ include_dirs = []
+ library_dirs = []
+ libraries = []
+
+ if os.name == 'posix':
+ include_dirs.append(self.connc_include)
+ library_dirs.append(self.connc_lib)
+ libraries.append("mysqlclient")
+
+ # As we statically link and the "libmysqlclient.a" library
+ # carry no information what it depends on, we need to
+ # manually add library dependencies here.
+ if platform.system() not in ["Darwin", "Windows"]:
+ libraries.append("rt")
+
+ for ext in self.extensions:
+ ext.include_dirs.extend(include_dirs)
+ ext.library_dirs.extend(library_dirs)
+ ext.libraries.extend(libraries)
+
+
+class InstallLib(install_lib):
+
+ user_options = install_lib.user_options + CEXT_OPTIONS + INSTALL_OPTIONS
+
+ boolean_options = ['byte-code-only']
+
+ def initialize_options(self):
+ install_lib.initialize_options(self)
+ self.byte_code_only = None
+
+ def finalize_options(self):
+ install_lib.finalize_options(self)
+ self.set_undefined_options('install',
+ ('byte_code_only', 'byte_code_only'))
+ self.set_undefined_options('build', ('build_base', 'build_dir'))
+
+ def run(self):
+ self.build()
+ outfiles = self.install()
+
+ # (Optionally) compile .py to .pyc
+ if outfiles is not None and self.distribution.has_pure_modules():
+ self.byte_compile(outfiles)
+
+ if self.byte_code_only:
+ for source_file in outfiles:
+ if os.path.join('mysql', '__init__.py') in source_file:
+ continue
+ log.info("Removing %s", source_file)
+ os.remove(source_file)
+
+
+class Install(install):
+
+ """Install Connector/Python C Extension"""
+
+ description = "install MySQL Connector/Python"
+
+ user_options = install.user_options + CEXT_OPTIONS + INSTALL_OPTIONS + \
+ CEXT_STATIC_OPTIONS
+
+ boolean_options = ['byte-code-only', 'static']
+ need_ext = False
+
+ def initialize_options(self):
+ install.initialize_options(self)
+ self.with_mysql_capi = None
+ self.byte_code_only = None
+ self.static = None
+
+ def finalize_options(self):
+ if self.static:
+ self.distribution.cmdclass['build_ext'] = BuildExtStatic
+
+ if self.byte_code_only is None:
+ self.byte_code_only = False
+
+ if self.with_mysql_capi:
+ build_ext = self.distribution.get_command_obj('build_ext')
+ build_ext.with_mysql_capi = self.with_mysql_capi
+ build = self.distribution.get_command_obj('build_ext')
+ build.with_mysql_capi = self.with_mysql_capi
+ self.need_ext = True
+
+ if not self.need_ext:
+ remove_cext(self.distribution)
+
+ install.finalize_options(self)
+
+ def run(self):
+ if not self.need_ext:
+ log.info("Not Installing C Extension")
+ else:
+ log.info("Installing C Extension")
+ install.run(self)
diff --git a/lib/mysql/connector/__init__.py b/lib/mysql/connector/__init__.py
index a0e6800..464030a 100644
--- a/lib/mysql/connector/__init__.py
+++ b/lib/mysql/connector/__init__.py
@@ -22,9 +22,17 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
-MySQL Connector/Python - MySQL drive written in Python
+MySQL Connector/Python - MySQL driver written in Python
"""
+try:
+ import _mysql_connector # pylint: disable=F0401
+ from .connection_cext import CMySQLConnection
+except ImportError:
+ HAVE_CEXT = False
+else:
+ HAVE_CEXT = True
+
from . import version
from .connection import MySQLConnection
from .errors import ( # pylint: disable=W0622
@@ -42,7 +50,6 @@ from .optionfiles import read_option_files
_CONNECTION_POOLS = {}
-
def _get_pooled_connection(**kwargs):
"""Return a pooled MySQL connection"""
# If no pool name specified, generate one
@@ -151,15 +158,25 @@ def connect(*args, **kwargs):
# Pooled connections
try:
- from .pooling import CNX_POOL_ARGS
+ from .constants import CNX_POOL_ARGS
if any([key in kwargs for key in CNX_POOL_ARGS]):
return _get_pooled_connection(**kwargs)
except NameError:
# No pooling
pass
- # Regular connection
- return MySQLConnection(*args, **kwargs)
+ use_pure = kwargs.setdefault('use_pure', True)
+
+ try:
+ del kwargs['use_pure']
+ except KeyError:
+ # Just making sure 'use_pure' is not kwargs
+ pass
+
+ if HAVE_CEXT and not use_pure:
+ return CMySQLConnection(*args, **kwargs)
+ else:
+ return MySQLConnection(*args, **kwargs)
Connect = connect # pylint: disable=C0103
__version_info__ = version.VERSION
@@ -170,6 +187,7 @@ __all__ = [
# Some useful constants
'FieldType', 'FieldFlag', 'ClientFlag', 'CharacterSet', 'RefreshOption',
+ 'HAVE_CEXT',
# Error handling
'Error', 'Warning',
@@ -183,4 +201,7 @@ __all__ = [
'DateFromTicks', 'DateFromTicks', 'TimestampFromTicks', 'TimeFromTicks',
'STRING', 'BINARY', 'NUMBER',
'DATETIME', 'ROWID',
+
+ # C Extension
+ 'CMySQLConnection',
]
diff --git a/lib/mysql/connector/abstracts.py b/lib/mysql/connector/abstracts.py
new file mode 100644
index 0000000..9aa4ac9
--- /dev/null
+++ b/lib/mysql/connector/abstracts.py
@@ -0,0 +1,1161 @@
+# MySQL Connector/Python - MySQL driver written in Python.
+# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+
+# MySQL Connector/Python is licensed under the terms of the GPLv2
+# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
+# MySQL Connectors. There are special exceptions to the terms and
+# conditions of the GPLv2 as it is applied to this software, see the
+# FOSS License Exception
+# <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
... 19151 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/mysql-connector-python.git
More information about the Python-modules-commits
mailing list