Skip to content

Commit 511b6a2

Browse files
authored
Use keyword only argument (PyMySQL#930)
* Use keyword only argument for constructor. * Remove old password test
1 parent 255b5dd commit 511b6a2

File tree

3 files changed

+14
-67
lines changed

3 files changed

+14
-67
lines changed

pymysql/__init__.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ def Binary(x):
110110
return bytes(x)
111111

112112

113-
def Connect(*args, **kwargs):
114-
return connections.Connection(*args, **kwargs)
115-
116-
117-
Connect.__doc__ = connections.Connection.__init__.__doc__
113+
Connect = connect = Connection = connections.Connection
118114

119115

120116
def get_client_info(): # for MySQLdb compatibility
@@ -124,8 +120,6 @@ def get_client_info(): # for MySQLdb compatibility
124120
return ".".join(map(str, version))
125121

126122

127-
connect = Connection = Connect
128-
129123
# we include a doctored version_info here for MySQLdb compatibility
130124
version_info = (1, 4, 0, "final", 0)
131125

pymysql/connections.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class Connection:
120120
See converters.
121121
:param use_unicode:
122122
Whether or not to default to unicode strings.
123-
This option defaults to true for Py3k.
123+
This option defaults to true.
124124
:param client_flag: Custom flags to send to MySQL. Find potential values in constants.CLIENT.
125125
:param cursorclass: Custom cursor class to use.
126126
:param init_command: Initial SQL statement to run when connection is established.
@@ -164,12 +164,13 @@ class Connection:
164164

165165
def __init__(
166166
self,
167-
host=None,
168167
user=None,
169168
password="",
169+
host=None,
170170
database=None,
171-
port=0,
171+
*,
172172
unix_socket=None,
173+
port=0,
173174
charset="",
174175
sql_mode=None,
175176
read_default_file=None,
@@ -179,13 +180,8 @@ def __init__(
179180
cursorclass=Cursor,
180181
init_command=None,
181182
connect_timeout=10,
182-
ssl=None,
183183
read_default_group=None,
184-
compress=None,
185-
named_pipe=None,
186184
autocommit=False,
187-
db=None,
188-
passwd=None,
189185
local_infile=False,
190186
max_allowed_packet=16 * 1024 * 1024,
191187
defer_connect=False,
@@ -196,16 +192,25 @@ def __init__(
196192
binary_prefix=False,
197193
program_name=None,
198194
server_public_key=None,
195+
ssl=None,
199196
ssl_ca=None,
200197
ssl_cert=None,
201198
ssl_disabled=None,
202199
ssl_key=None,
203200
ssl_verify_cert=None,
204201
ssl_verify_identity=None,
202+
compress=None, # not supported
203+
named_pipe=None, # not supported
204+
passwd=None, # deprecated
205+
db=None, # deprecated
205206
):
206207
if db is not None and database is None:
208+
warnings.warn("'db' is deprecated, use 'database'", DeprecationWarning, 3)
207209
database = db
208210
if passwd is not None and not password:
211+
warnings.warn(
212+
"'passwd' is deprecated, use 'password'", DeprecationWarning, 3
213+
)
209214
password = passwd
210215

211216
if compress or named_pipe:

pymysql/tests/test_connection.py

-52
Original file line numberDiff line numberDiff line change
@@ -383,58 +383,6 @@ def realTestPamAuth(self):
383383
# recreate the user
384384
cur.execute(grants)
385385

386-
# select old_password("crummy p\tassword");
387-
# | old_password("crummy p\tassword") |
388-
# | 2a01785203b08770 |
389-
@pytest.mark.skipif(not socket_auth, reason="connection to unix_socket required")
390-
@pytest.mark.skipif(
391-
not mysql_old_password_found, reason="no mysql_old_password plugin"
392-
)
393-
def testMySQLOldPasswordAuth(self):
394-
conn = self.connect()
395-
if self.mysql_server_is(conn, (5, 7, 0)):
396-
pytest.skip("Old passwords aren't supported in 5.7")
397-
# pymysql.err.OperationalError: (1045, "Access denied for user 'old_pass_user'@'localhost' (using password: YES)")
398-
# from login in MySQL-5.6
399-
if self.mysql_server_is(conn, (5, 6, 0)):
400-
pytest.skip("Old passwords don't authenticate in 5.6")
401-
db = self.db.copy()
402-
db["password"] = "crummy p\tassword"
403-
c = conn.cursor()
404-
405-
# deprecated in 5.6
406-
if self.mysql_server_is(conn, (5, 6, 0)):
407-
with self.assertWarns(pymysql.err.Warning) as cm:
408-
c.execute("SELECT OLD_PASSWORD('%s')" % db["password"])
409-
else:
410-
c.execute("SELECT OLD_PASSWORD('%s')" % db["password"])
411-
v = c.fetchone()[0]
412-
self.assertEqual(v, "2a01785203b08770")
413-
# only works in MariaDB and MySQL-5.6 - can't separate out by version
414-
# if self.mysql_server_is(self.connect(), (5, 5, 0)):
415-
# with TempUser(c, 'old_pass_user@localhost',
416-
# self.databases[0]['db'], 'mysql_old_password', '2a01785203b08770') as u:
417-
# cur = pymysql.connect(user='old_pass_user', **db).cursor()
418-
# cur.execute("SELECT VERSION()")
419-
c.execute("SELECT @@secure_auth")
420-
secure_auth_setting = c.fetchone()[0]
421-
c.execute("set old_passwords=1")
422-
# pymysql.err.Warning: 'pre-4.1 password hash' is deprecated and will be removed in a future release. Please use post-4.1 password hash instead
423-
if self.mysql_server_is(conn, (5, 6, 0)):
424-
with self.assertWarns(pymysql.err.Warning) as cm:
425-
c.execute("set global secure_auth=0")
426-
else:
427-
c.execute("set global secure_auth=0")
428-
with TempUser(
429-
c,
430-
"old_pass_user@localhost",
431-
self.databases[0]["db"],
432-
password=db["password"],
433-
) as u:
434-
cur = pymysql.connect(user="old_pass_user", **db).cursor()
435-
cur.execute("SELECT VERSION()")
436-
c.execute("set global secure_auth=%r" % secure_auth_setting)
437-
438386
@pytest.mark.skipif(not socket_auth, reason="connection to unix_socket required")
439387
@pytest.mark.skipif(
440388
not sha256_password_found,

0 commit comments

Comments
 (0)