Skip to content

Commit 08680b1

Browse files
author
Jun Yamasaki
committed
Modify ssl_mode setting from constant to string
1 parent 73c4296 commit 08680b1

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

MySQLdb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
paramstyle = "format"
2727

2828
from ._mysql import *
29-
from MySQLdb.constants import FIELD_TYPE, SSL_MODE
29+
from MySQLdb.constants import FIELD_TYPE
3030
from MySQLdb.times import Date, Time, Timestamp, \
3131
DateFromTicks, TimeFromTicks, TimestampFromTicks
3232

MySQLdb/connections.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ class object, used to create cursors (keyword only)
102102
:param int client_flag:
103103
flags to use or 0 (see MySQL docs or constants/CLIENTS.py)
104104
105+
:param str ssl_mode
106+
specify the security settings for connection to the server;
107+
see the MySQL documentation for more details
108+
(mysql_option(), MYSQL_OPT_SSL_MODE).
109+
Only one of 'DISABLED', 'PREFERRED', 'REQUIRED',
110+
'VERIFY_CA', 'VERIFY_IDENTITY' can be specified.
111+
105112
:param dict ssl:
106113
dictionary or mapping contains SSL connection parameters;
107114
see the MySQL documentation for more details
@@ -123,7 +130,7 @@ class object, used to create cursors (keyword only)
123130
There are a number of undocumented, non-standard methods. See the
124131
documentation for the MySQL C API for some hints on what they do.
125132
"""
126-
from MySQLdb.constants import CLIENT, FIELD_TYPE
133+
from MySQLdb.constants import CLIENT, FIELD_TYPE, SSL_MODE
127134
from MySQLdb.converters import conversions, _bytes_or_str
128135
from weakref import proxy
129136

@@ -162,6 +169,12 @@ class object, used to create cursors (keyword only)
162169

163170
kwargs2['client_flag'] = client_flag
164171

172+
if 'ssl_mode' in kwargs:
173+
if hasattr(SSL_MODE, kwargs['ssl_mode']):
174+
kwargs2['ssl_mode'] = getattr(SSL_MODE, kwargs['ssl_mode'])
175+
else:
176+
raise NotSupportedError('Unknown MySQL ssl_mode specification: %s' % kwargs['ssl_mode'])
177+
165178
# PEP-249 requires autocommit to be initially off
166179
autocommit = kwargs2.pop('autocommit', False)
167180

doc/user_guide.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,12 @@ connect(parameters...)
360360
ssl_mode
361361
If present, specify the security settings for the
362362
connection to the server. For more information on ssl_mode,
363-
see the MySQL documentation. The constants can be referenced
364-
as follows: ``MySQLdb.constants.SSL_MODE.PREFERRED``
363+
see the MySQL documentation. Only one of 'DISABLED',
364+
'PREFERRED', 'REQUIRED', 'VERIFY_CA', 'VERIFY_IDENTITY'
365+
can be specified.
365366

366367
If not present, the session ssl_mode will be unchanged,
367-
but it becomes PREFERRED in Version 5.7 or later.
368+
but in version 5.7 and later, the default is PREFERRED.
368369

369370
*This must be a keyword parameter.*
370371

0 commit comments

Comments
 (0)