Skip to content

Commit f38063d

Browse files
committed
BUG24953913: Fix unittests that are failing in Linux
This patch fixes bugs.BugOra16217765.test_sha256_nonssl and style.LintTests.test_lint that were failing in Linux.
1 parent b3f25e3 commit f38063d

16 files changed

+118
-72
lines changed

lib/mysql/connector/abstracts.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ def config(self, **kwargs):
231231
except KeyError:
232232
self._consume_results = False
233233

234+
# Configure auth_plugin
235+
try:
236+
self._auth_plugin = config['auth_plugin']
237+
del config['auth_plugin']
238+
except KeyError:
239+
self._auth_plugin = ''
240+
234241
# Configure character set and collation
235242
if 'charset' in config or 'collation' in config:
236243
try:

lib/mysql/connector/connection.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,15 @@ def _get_connection(self, prtcls=None):
184184
185185
Returns subclass of MySQLBaseSocket.
186186
"""
187+
# pylint: disable=R0204
187188
conn = None
188189
if self.unix_socket and os.name != 'nt':
189190
conn = MySQLUnixSocket(unix_socket=self.unix_socket)
190191
else:
191192
conn = MySQLTCPSocket(host=self.server_host,
192193
port=self.server_port,
193194
force_ipv6=self._force_ipv6)
195+
# pylint: enable=R0204
194196
conn.set_connection_timeout(self._connection_timeout)
195197
return conn
196198

@@ -440,14 +442,17 @@ def get_rows(self, count=None, binary=False, columns=None):
440442
rows = self._protocol.read_binary_result(
441443
self._socket, columns, count)
442444
else:
443-
rows = self._protocol.read_text_result(self._socket, self._server_version, count=count)
445+
rows = self._protocol.read_text_result(self._socket,
446+
self._server_version,
447+
count=count)
444448
except errors.Error as err:
445449
self.unread_result = False
446450
raise err
447451

448452
if rows[-1] is not None:
449-
ek = rows[-1] # OK or EOF
450-
self._handle_server_status(ek['status_flag'] if 'status_flag' in ek else ek['server_status'])
453+
row = rows[-1] # OK or EOF
454+
self._handle_server_status(row['status_flag'] if 'status_flag' in
455+
row else row['server_status'])
451456
self.unread_result = False
452457

453458
return rows

lib/mysql/connector/connection_cext.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
HAVE_CMYSQL = True
5555
# pylint: enable=F0401,C0413
5656

57+
5758
class CMySQLConnection(MySQLConnectionAbstract):
5859

5960
"""Class initiating a MySQL Connection using Connector/C"""
@@ -139,8 +140,7 @@ def in_transaction(self):
139140

140141
def _open_connection(self):
141142
charset_name = CharacterSet.get_info(self._charset_id)[0]
142-
143-
self._cmysql = _mysql_connector.MySQL(
143+
self._cmysql = _mysql_connector.MySQL( # pylint: disable=E1101
144144
buffered=self._buffered,
145145
raw=self._raw,
146146
charset_name=charset_name,
@@ -260,6 +260,7 @@ def get_rows(self, count=None, binary=False, columns=None):
260260
raise AttributeError("count should be 1 or higher, or None")
261261

262262
counter = 0
263+
# pylint: disable=R0204
263264
try:
264265
row = self._cmysql.fetch_row()
265266
while row:
@@ -278,7 +279,7 @@ def get_rows(self, count=None, binary=False, columns=None):
278279
self.free_result()
279280
raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
280281
sqlstate=exc.sqlstate)
281-
282+
# pylint: enable=R0204
282283
return rows
283284

284285
def get_row(self, binary=False, columns=None):

lib/mysql/connector/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ def get_supported(cls):
686686
return tuple(res)
687687

688688

689-
class SQLMode(_Constants): # pylint: disable=R0921
689+
class SQLMode(_Constants):
690690
"""MySQL SQL Modes
691691
692692
The numeric values of SQL Modes are not interesting, only the names

lib/mysql/connector/cursor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
re.I | re.M | re.S)
4242
RE_SQL_INSERT_STMT = re.compile(
4343
r"({0}|\s)*INSERT({0}|\s)*INTO\s+[`'\"]?.+[`'\"]?(?:\.[`'\"]?.+[`'\"]?)"
44-
"{{0,2}}\s+VALUES\s*\(.+(?:\s*,.+)*\)".format(SQL_COMMENT),
44+
r"{{0,2}}\s+VALUES\s*\(.+(?:\s*,.+)*\)".format(SQL_COMMENT),
4545
re.I | re.M | re.S)
4646
RE_SQL_INSERT_VALUES = re.compile(r'.*VALUES\s*(\(.*\)).*', re.I | re.M | re.S)
4747
RE_PY_PARAM = re.compile(b'(%s)')
@@ -97,6 +97,7 @@ def _bytestr_format_dict(bytestr, value_dict):
9797
b'x=%(y)s y=%(x)s'
9898
"""
9999
def replace(matchobj):
100+
"""Replace pattern."""
100101
value = None
101102
groups = matchobj.groupdict()
102103
if groups["conversion_type"] == b"%":
@@ -112,6 +113,7 @@ def replace(matchobj):
112113
return RE_PY_MAPPING_PARAM.sub(replace, bytestr.decode("utf-8")
113114
if PY2 else bytestr)
114115

116+
115117
class CursorBase(MySQLCursorAbstract):
116118
"""
117119
Base for defining MySQLCursor. This class is a skeleton and defines
@@ -749,18 +751,20 @@ def callproc(self, procname, args=()):
749751
can_consume_results = self._connection._consume_results
750752
for result in self._connection.cmd_query_iter(call):
751753
self._connection._consume_results = False
754+
# pylint: disable=R0204
752755
if self._raw:
753756
tmp = MySQLCursorBufferedRaw(self._connection._get_self())
754757
else:
755758
tmp = MySQLCursorBuffered(self._connection._get_self())
759+
# pylint: enable=R0204
756760
tmp._executed = "(a result of {0})".format(call)
757761
tmp._handle_result(result)
758762
if tmp._warnings is not None:
759763
self._warnings = tmp._warnings
760764
if 'columns' in result:
761765
results.append(tmp)
762766
self._connection._consume_results = can_consume_results
763-
#pylint: enable=W0212
767+
# pylint: enable=W0212
764768

765769
if argnames:
766770
select = "SELECT {0}".format(','.join(argtypes))

lib/mysql/connector/cursor_cext.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# MySQL Connector/Python - MySQL driver written in Python.
2-
# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
33

44
# MySQL Connector/Python is licensed under the terms of the GPLv2
55
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -28,6 +28,8 @@
2828
import re
2929
import weakref
3030

31+
from _mysql_connector import MySQLInterfaceError # pylint: disable=F0401,E0611
32+
3133
from .abstracts import MySQLConnectionAbstract, MySQLCursorAbstract
3234
from .catch23 import PY2, isunicode
3335
from . import errors
@@ -39,7 +41,6 @@
3941
RE_SQL_SPLIT_STMTS
4042
)
4143

42-
from _mysql_connector import MySQLInterfaceError # pylint: disable=F0401
4344

4445
class _ParamSubstitutor(object):
4546

@@ -429,14 +430,14 @@ def callproc(self, procname, args=()):
429430
results = []
430431
while self._cnx.result_set_available:
431432
result = self._cnx.fetch_eof_columns()
432-
# pylint: disable=W0212
433+
# pylint: disable=W0212,R0204
433434
if self._raw:
434435
cur = CMySQLCursorBufferedRaw(self._cnx._get_self())
435436
else:
436437
cur = CMySQLCursorBuffered(self._cnx._get_self())
437438
cur._executed = "(a result of {0})".format(call)
438439
cur._handle_result(result)
439-
# pylint: enable=W0212
440+
# pylint: enable=W0212,R0204
440441
results.append(cur)
441442
self._cnx.next_result()
442443
self._stored_results = results
@@ -807,4 +808,3 @@ def __init__(self, connection):
807808
super(CMySQLCursorPrepared, self).__init__(connection)
808809
raise NotImplementedError(
809810
"Alternative: Use connection.MySQLCursorPrepared")
810-

lib/mysql/connector/fabric/__init__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# MySQL Connector/Python - MySQL driver written in Python.
2-
# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
33

44
# MySQL Connector/Python is licensed under the terms of the GPLv2
55
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -26,6 +26,15 @@
2626

2727
from collections import namedtuple
2828

29+
from .connection import (
30+
MODE_READONLY, MODE_READWRITE,
31+
STATUS_PRIMARY, STATUS_SECONDARY,
32+
SCOPE_GLOBAL, SCOPE_LOCAL,
33+
Fabric, FabricConnection,
34+
MySQLFabricConnection,
35+
FabricSet,
36+
)
37+
2938
# Order of field_names must match how Fabric is returning the data
3039
FabricMySQLServer = namedtuple(
3140
'FabricMySQLServer',
@@ -39,15 +48,6 @@
3948
'shard', 'shard_type', 'group', 'global_group']
4049
)
4150

42-
from .connection import (
43-
MODE_READONLY, MODE_READWRITE,
44-
STATUS_PRIMARY, STATUS_SECONDARY,
45-
SCOPE_GLOBAL, SCOPE_LOCAL,
46-
Fabric, FabricConnection,
47-
MySQLFabricConnection,
48-
FabricSet,
49-
)
50-
5151

5252
def connect(**kwargs):
5353
"""Create a MySQLFabricConnection object"""

lib/mysql/connector/fabric/caching.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# MySQL Connector/Python - MySQL driver written in Python.
2-
# Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
33

44
# MySQL Connector/Python is licensed under the terms of the GPLv2
55
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -116,32 +116,33 @@ def __getattr__(self, attr):
116116
def add_partition(self, key, group):
117117
"""Add sharding information for a group"""
118118
if self.shard_type == 'RANGE':
119-
key = int(key)
119+
_key = int(key)
120120
elif self.shard_type == 'RANGE_DATETIME':
121121
try:
122122
if ':' in key:
123-
key = datetime.strptime(key, "%Y-%m-%d %H:%M:%S")
123+
# pylint: disable=R0204
124+
_key = datetime.strptime(key, "%Y-%m-%d %H:%M:%S")
124125
else:
125-
key = datetime.strptime(key, "%Y-%m-%d").date()
126+
_key = datetime.strptime(key, "%Y-%m-%d").date()
126127
except:
127128
raise ValueError(
128129
"RANGE_DATETIME key could not be parsed, was: {0}".format(
129130
key
130131
))
131132
elif self.shard_type == 'RANGE_STRING':
132-
pass
133+
_key = key
133134
elif self.shard_type == "HASH":
134-
pass
135+
_key = key
135136
else:
136137
raise ValueError("Unsupported sharding type {0}".format(
137138
self.shard_type
138139
))
139-
self.partitioning[key] = {
140+
self.partitioning[_key] = {
140141
'group': group,
141142
}
142143
self.reset_ttl()
143-
bisect.insort_right(self.keys, key)
144-
insort_right_rev(self.keys_reversed, key)
144+
bisect.insort_right(self.keys, _key)
145+
insort_right_rev(self.keys_reversed, _key)
145146

146147
@classmethod
147148
def hash_index(cls, part1, part2=None):
@@ -175,6 +176,7 @@ def __repr__(self):
175176
group=self.group_name,
176177
)
177178

179+
178180
class FabricCache(object):
179181
"""Singleton class for caching Fabric data
180182

lib/mysql/connector/fabric/connection.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# MySQL Connector/Python - MySQL driver written in Python.
2-
# Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
33

44
# MySQL Connector/Python is licensed under the terms of the GPLv2
55
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -27,13 +27,34 @@
2727
import datetime
2828
import time
2929
import uuid
30-
from base64 import b16decode
31-
from bisect import bisect
32-
from hashlib import md5
3330
import logging
3431
import socket
3532
import collections
3633

34+
from base64 import b16decode
35+
from bisect import bisect
36+
from hashlib import md5
37+
38+
import mysql.connector
39+
40+
from ..connection import MySQLConnection
41+
from ..conversion import MySQLConverter
42+
from ..pooling import MySQLConnectionPool
43+
from ..errors import (
44+
Error, InterfaceError, NotSupportedError, MySQLFabricError, InternalError,
45+
DatabaseError
46+
)
47+
from ..cursor import (
48+
MySQLCursor, MySQLCursorBuffered,
49+
MySQLCursorRaw, MySQLCursorBufferedRaw
50+
)
51+
from .. import errorcode
52+
from . import FabricMySQLServer, FabricShard
53+
from .caching import FabricCache
54+
from .balancing import WeightedRoundRobin
55+
from .. import version
56+
from ..catch23 import PY2, isunicode, UNICODE_TYPES
57+
3758
# pylint: disable=F0401,E0611
3859
try:
3960
from xmlrpclib import Fault, ServerProxy, Transport
@@ -59,26 +80,7 @@
5980
HAVE_SSL = False
6081
else:
6182
HAVE_SSL = True
62-
# pylint: enable=F0401,E0611
6383

64-
import mysql.connector
65-
from ..connection import MySQLConnection
66-
from ..conversion import MySQLConverter
67-
from ..pooling import MySQLConnectionPool
68-
from ..errors import (
69-
Error, InterfaceError, NotSupportedError, MySQLFabricError, InternalError,
70-
DatabaseError
71-
)
72-
from ..cursor import (
73-
MySQLCursor, MySQLCursorBuffered,
74-
MySQLCursorRaw, MySQLCursorBufferedRaw
75-
)
76-
from .. import errorcode
77-
from . import FabricMySQLServer, FabricShard
78-
from .caching import FabricCache
79-
from .balancing import WeightedRoundRobin
80-
from .. import version
81-
from ..catch23 import PY2, isunicode, UNICODE_TYPES
8284

8385
RESET_CACHE_ON_ERROR = (
8486
errorcode.CR_SERVER_LOST,
@@ -213,8 +215,7 @@ def create_params(self, *args, **kwargs):
213215
kwargs = self._process_params_dict(kwargs)
214216
params.extend(kwargs)
215217

216-
params = ', '.join(params)
217-
return params
218+
return ', '.join(params)
218219

219220
def execute(self, group, command, *args, **kwargs):
220221
"""Executes the given command with MySQL protocol

lib/mysql/connector/locales/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# MySQL Connector/Python - MySQL driver written in Python.
2-
# Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
33

44
# MySQL Connector/Python is licensed under the terms of the GPLv2
55
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -68,4 +68,3 @@ def get_client_error(error, language='eng'):
6868
return None
6969

7070
raise ValueError("error argument needs to be either an integer or string")
71-

0 commit comments

Comments
 (0)