Skip to content

Use keyword only argument #930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions pymysql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@ def Binary(x):
return bytes(x)


def Connect(*args, **kwargs):
return connections.Connection(*args, **kwargs)


Connect.__doc__ = connections.Connection.__init__.__doc__
Connect = connect = Connection = connections.Connection


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


connect = Connection = Connect

# we include a doctored version_info here for MySQLdb compatibility
version_info = (1, 4, 0, "final", 0)

Expand Down
21 changes: 13 additions & 8 deletions pymysql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Connection:
See converters.
:param use_unicode:
Whether or not to default to unicode strings.
This option defaults to true for Py3k.
This option defaults to true.
:param client_flag: Custom flags to send to MySQL. Find potential values in constants.CLIENT.
:param cursorclass: Custom cursor class to use.
:param init_command: Initial SQL statement to run when connection is established.
Expand Down Expand Up @@ -164,12 +164,13 @@ class Connection:

def __init__(
self,
host=None,
user=None,
password="",
host=None,
database=None,
port=0,
*,
unix_socket=None,
port=0,
charset="",
sql_mode=None,
read_default_file=None,
Expand All @@ -179,13 +180,8 @@ def __init__(
cursorclass=Cursor,
init_command=None,
connect_timeout=10,
ssl=None,
read_default_group=None,
compress=None,
named_pipe=None,
autocommit=False,
db=None,
passwd=None,
local_infile=False,
max_allowed_packet=16 * 1024 * 1024,
defer_connect=False,
Expand All @@ -196,16 +192,25 @@ def __init__(
binary_prefix=False,
program_name=None,
server_public_key=None,
ssl=None,
ssl_ca=None,
ssl_cert=None,
ssl_disabled=None,
ssl_key=None,
ssl_verify_cert=None,
ssl_verify_identity=None,
compress=None, # not supported
named_pipe=None, # not supported
passwd=None, # deprecated
db=None, # deprecated
):
if db is not None and database is None:
warnings.warn("'db' is deprecated, use 'database'", DeprecationWarning, 3)
database = db
if passwd is not None and not password:
warnings.warn(
"'passwd' is deprecated, use 'password'", DeprecationWarning, 3
)
password = passwd

if compress or named_pipe:
Expand Down
52 changes: 0 additions & 52 deletions pymysql/tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,58 +383,6 @@ def realTestPamAuth(self):
# recreate the user
cur.execute(grants)

# select old_password("crummy p\tassword");
# | old_password("crummy p\tassword") |
# | 2a01785203b08770 |
@pytest.mark.skipif(not socket_auth, reason="connection to unix_socket required")
@pytest.mark.skipif(
not mysql_old_password_found, reason="no mysql_old_password plugin"
)
def testMySQLOldPasswordAuth(self):
conn = self.connect()
if self.mysql_server_is(conn, (5, 7, 0)):
pytest.skip("Old passwords aren't supported in 5.7")
# pymysql.err.OperationalError: (1045, "Access denied for user 'old_pass_user'@'localhost' (using password: YES)")
# from login in MySQL-5.6
if self.mysql_server_is(conn, (5, 6, 0)):
pytest.skip("Old passwords don't authenticate in 5.6")
db = self.db.copy()
db["password"] = "crummy p\tassword"
c = conn.cursor()

# deprecated in 5.6
if self.mysql_server_is(conn, (5, 6, 0)):
with self.assertWarns(pymysql.err.Warning) as cm:
c.execute("SELECT OLD_PASSWORD('%s')" % db["password"])
else:
c.execute("SELECT OLD_PASSWORD('%s')" % db["password"])
v = c.fetchone()[0]
self.assertEqual(v, "2a01785203b08770")
# only works in MariaDB and MySQL-5.6 - can't separate out by version
# if self.mysql_server_is(self.connect(), (5, 5, 0)):
# with TempUser(c, 'old_pass_user@localhost',
# self.databases[0]['db'], 'mysql_old_password', '2a01785203b08770') as u:
# cur = pymysql.connect(user='old_pass_user', **db).cursor()
# cur.execute("SELECT VERSION()")
c.execute("SELECT @@secure_auth")
secure_auth_setting = c.fetchone()[0]
c.execute("set old_passwords=1")
# 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
if self.mysql_server_is(conn, (5, 6, 0)):
with self.assertWarns(pymysql.err.Warning) as cm:
c.execute("set global secure_auth=0")
else:
c.execute("set global secure_auth=0")
with TempUser(
c,
"old_pass_user@localhost",
self.databases[0]["db"],
password=db["password"],
) as u:
cur = pymysql.connect(user="old_pass_user", **db).cursor()
cur.execute("SELECT VERSION()")
c.execute("set global secure_auth=%r" % secure_auth_setting)

@pytest.mark.skipif(not socket_auth, reason="connection to unix_socket required")
@pytest.mark.skipif(
not sha256_password_found,
Expand Down