Skip to content

Commit fbd8bd1

Browse files
committed
read_default_group implementation
1 parent 7a05a0c commit fbd8bd1

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pymysql/connections.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,14 @@ def __init__(self, host="localhost", user=None, passwd="",
426426
init_command: Initial SQL statement to run when connection is established.
427427
connect_timeout: Timeout before throwing an exception when connecting.
428428
ssl: A dict of arguments similar to mysql_ssl_set()'s parameters. For now the capath and cipher arguments are not supported.
429-
read_default_group: Not supported
429+
read_default_group: Group to read from in the configuration file.
430430
compress; Not supported
431431
named_pipe: Not supported
432432
"""
433433

434434

435-
if read_default_group or compress or named_pipe:
436-
raise NotImplementedError, "read_default_group, compress and named_pipe arguments are not supported"
435+
if compress or named_pipe:
436+
raise NotImplementedError, "compress and named_pipe arguments are not supported"
437437

438438
if ssl and (ssl.has_key('capath') or ssl.has_key('cipher')):
439439
raise NotImplementedError, 'ssl options capath and cipher are not supported'
@@ -448,13 +448,22 @@ def __init__(self, host="localhost", user=None, passwd="",
448448
v = ssl[k]
449449
setattr(self, k, v)
450450

451+
if read_default_group and not read_default_file:
452+
if sys.platform.startswith("win"):
453+
read_default_file = "c:\\my.ini"
454+
else:
455+
read_default_file = "/etc/my.cnf"
456+
451457
if read_default_file:
458+
if not read_default_group:
459+
read_default_group = "client"
460+
452461
cfg = ConfigParser.RawConfigParser()
453462
cfg.read(os.path.expanduser(read_default_file))
454463

455464
def _config(key, default):
456465
try:
457-
return cfg.get("client",key)
466+
return cfg.get(read_default_group,key)
458467
except:
459468
return default
460469

0 commit comments

Comments
 (0)