Skip to content

Commit 6d94a93

Browse files
author
Geert Vanderkelen
committed
Merge branch 'release-2.0.1'
2 parents 89ab0e6 + e75455d commit 6d94a93

39 files changed

+1173
-1039
lines changed

CHANGES.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@ Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
88
Full release notes:
99
http://dev.mysql.com/doc/relnotes/connector-python/en/
1010

11+
v2.0.1
12+
======
13+
14+
- WL7954: Add support for RANGE_STRING Fabric sharding type
15+
- WL7955: Add support for RANGE_DATETIME Fabric sharding type
16+
- BUG19440592: Fix exception not captured when SSL is unavailable
17+
- BUG19481761: Fix option files with !include with trailing newline
18+
- BUG18798953: Add MySQLConnection.shutdown() to abruply close connection
19+
- BUG19168737: Fix unsupported connection argument error with option files
20+
- BUG19282158: Fix NULL values to work with prepared statements
21+
- BUG19179711: Fix using '%s' in django backend
22+
- BUG19169143: Fix raising error with duplicate option files
23+
- BUG19170287: Fix duplicate section error with Python v3
24+
- BUG19163169: Add support for Django 1.7
25+
- BUG19225481: Fix floating point inaccuracy with Python v2
26+
- BUG19164627: Fix cursor trying to decode linestring data as utf-8
27+
28+
1129
v2.0.0a1
1230
========
1331

cpyint

lib/mysql/connector/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
TimestampFromTicks, TimeFromTicks,
3939
STRING, BINARY, NUMBER, DATETIME, ROWID,
4040
apilevel, threadsafety, paramstyle)
41+
from .optionfiles import read_option_files
4142

4243
_CONNECTION_POOLS = {}
4344

@@ -129,6 +130,10 @@ def connect(*args, **kwargs):
129130
130131
Returns MySQLConnection or PooledMySQLConnection.
131132
"""
133+
# Option files
134+
if 'option_files' in kwargs:
135+
new_config = read_option_files(**kwargs)
136+
return connect(**new_config)
132137

133138
if all(['fabric' in kwargs, 'failover' in kwargs]):
134139
raise InterfaceError("fabric and failover arguments can not be used")

lib/mysql/connector/catch23.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535

3636
if PY2:
3737
NUMERIC_TYPES = (int, float, Decimal, HexLiteral, long)
38+
UNICODE_TYPES = (unicode,) # This should not contain str
3839
else:
3940
NUMERIC_TYPES = (int, float, Decimal, HexLiteral)
41+
UNICODE_TYPES = (str,)
4042

4143
def init_bytearray(payload=b'', encoding='utf-8'):
4244
"""Initializes a bytearray from the payload"""
@@ -65,6 +67,13 @@ def isstr(obj):
6567
else:
6668
return isinstance(obj, str)
6769

70+
def isunicode(obj):
71+
"""Returns whether a variable is a of unicode type"""
72+
if PY2:
73+
return isinstance(obj, unicode)
74+
else:
75+
return isinstance(obj, str)
76+
6877

6978
if PY2:
7079
def struct_unpack(fmt, buf):

lib/mysql/connector/connection.py

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
MySQLCursorDict, MySQLCursorBufferedDict, MySQLCursorNamedTuple,
4444
MySQLCursorBufferedNamedTuple)
4545
from .network import MySQLUnixSocket, MySQLTCPSocket
46-
from .optionfiles import MySQLOptionsParser
4746
from .protocol import MySQLProtocol
4847
from .utils import int4store
4948

@@ -239,59 +238,6 @@ def _auth_switch_request(self, username=None, password=None):
239238
elif packet[4] == 255:
240239
raise errors.get_exception(packet)
241240

242-
def _read_option_files(self, config):
243-
"""
244-
Read option files for connection parameters.
245-
246-
Checks if connection arguments contain option file arguments, and then
247-
reads option files accordingly.
248-
"""
249-
if 'option_files' in config:
250-
try:
251-
if isinstance(config['option_groups'], str):
252-
config['option_groups'] = [config['option_groups']]
253-
groups = config['option_groups']
254-
del config['option_groups']
255-
except KeyError:
256-
groups = ['client', 'connector_python']
257-
258-
if isinstance(config['option_files'], str):
259-
config['option_files'] = [config['option_files']]
260-
option_parser = MySQLOptionsParser(list(config['option_files']),
261-
keep_dashes=False)
262-
del config['option_files']
263-
264-
config_from_file = option_parser.get_groups_as_dict_with_priority(
265-
*groups)
266-
config_options = {}
267-
for group in groups:
268-
try:
269-
for option, value in config_from_file[group].items():
270-
try:
271-
if option == 'socket':
272-
option = 'unix_socket'
273-
# pylint: disable=W0104
274-
DEFAULT_CONFIGURATION[option]
275-
# pylint: enable=W0104
276-
277-
if (option not in config_options or
278-
config_options[option][1] <= value[1]):
279-
config_options[option] = value
280-
except KeyError:
281-
if group is 'connector_python':
282-
raise AttributeError("Unsupported argument "
283-
"'{0}'".format(option))
284-
except KeyError:
285-
continue
286-
287-
for option, value in config_options.items():
288-
if option not in config:
289-
try:
290-
config[option] = eval(value[0]) # pylint: disable=W0123
291-
except (NameError, SyntaxError):
292-
config[option] = value[0]
293-
return config
294-
295241
def config(self, **kwargs):
296242
"""Configure the MySQL Connection
297243
@@ -303,9 +249,6 @@ def config(self, **kwargs):
303249
if 'dsn' in config:
304250
raise errors.NotSupportedError("Data source name is not supported")
305251

306-
# Read option files
307-
self._read_option_files(config)
308-
309252
# Configure how we handle MySQL warnings
310253
try:
311254
self.get_warnings = config['get_warnings']
@@ -509,6 +452,17 @@ def connect(self, **kwargs):
509452
self._open_connection()
510453
self._post_connection()
511454

455+
def shutdown(self):
456+
"""Shut down connection to MySQL Server.
457+
"""
458+
if not self._socket:
459+
return
460+
461+
try:
462+
self._socket.shutdown()
463+
except (AttributeError, errors.Error):
464+
pass # Getting an exception would mean we are disconnected.
465+
512466
def disconnect(self):
513467
"""Disconnect from the MySQL server
514468
"""

lib/mysql/connector/conversion.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ def quote(self, buf):
138138
"""
139139
if isinstance(buf, NUMERIC_TYPES):
140140
if PY2:
141-
return str(buf)
141+
if isinstance(buf, float):
142+
return repr(buf)
143+
else:
144+
return str(buf)
142145
else:
143146
return str(buf).encode('ascii')
144147
elif isinstance(buf, type(None)):
@@ -337,7 +340,10 @@ def to_python(self, flddsc, value):
337340
return self._cache_field_types[flddsc[1]](value, flddsc)
338341
except KeyError:
339342
# If one type is not defined, we just return the value as str
340-
return value.decode('utf-8')
343+
try:
344+
return value.decode('utf-8')
345+
except UnicodeDecodeError:
346+
return value
341347
except ValueError as err:
342348
raise ValueError("%s (field %s)" % (err, flddsc[0]))
343349
except TypeError as err:
@@ -379,7 +385,10 @@ def row_to_python(self, row, fields):
379385
result[i] = self._cache_field_types[field_type](row[i], field)
380386
except KeyError:
381387
# If one type is not defined, we just return the value as str
382-
result[i] = row[i].decode('utf-8')
388+
try:
389+
result[i] = row[i].decode('utf-8')
390+
except UnicodeDecodeError:
391+
result[i] = row[i]
383392
except (ValueError, TypeError) as err:
384393
err.message = "{0} (field {1})".format(str(err), field[0])
385394
raise

lib/mysql/connector/cursor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,9 @@ def execute(self, operation, params=None, multi=False):
469469
"""
470470
if not operation:
471471
return None
472+
473+
if not self._connection:
474+
raise errors.ProgrammingError("Cursor is not connected.")
472475
if self._connection.unread_result is True:
473476
raise errors.InternalError("Unread result found.")
474477

lib/mysql/connector/custom_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import sys
2828

29+
2930
class HexLiteral(str):
3031

3132
"""Class holding MySQL hex literals"""

0 commit comments

Comments
 (0)