Changeset: 2dd92bb63b34 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2dd92bb63b34 Modified Files: clients/ChangeLog.Aug2011 clients/python/monetdb/sql/connections.py Branch: Aug2011 Log Message:
python dbapi: support PEP 249-style connect arguments Allow use of suggested keywords for connect() function from PEP 249. This boils down to using "user" and "host" instead of "username" and "hostname". For backwards compatability, we now support both for the best of both worlds. diffs (49 lines): diff --git a/clients/ChangeLog.Aug2011 b/clients/ChangeLog.Aug2011 --- a/clients/ChangeLog.Aug2011 +++ b/clients/ChangeLog.Aug2011 @@ -1,6 +1,10 @@ # ChangeLog file for clients # This file is updated with Maddlog +* Wed Oct 12 2011 Fabian Groffen <[email protected]> +- Python DB API connect() function now supports PEP 249-style arguments + user and host, bug #2901 + * Wed Oct 12 2011 Sjoerd Mullender <[email protected]> - mclient now checks the result of encoding conversions using the iconv library. diff --git a/clients/python/monetdb/sql/connections.py b/clients/python/monetdb/sql/connections.py --- a/clients/python/monetdb/sql/connections.py +++ b/clients/python/monetdb/sql/connections.py @@ -31,12 +31,12 @@ class Connection: def __init__(self, username="monetdb", password="monetdb", hostname="localhost", port=50000, database="demo", autocommit=False, - use_unicode=False): + use_unicode=False, user=None, host=None): """ Set up a connection to a MonetDB SQL database. - username -- username for connection (default: monetdb) + user/username -- username for connection (default: monetdb) password -- password for connection (default: monetdb) - hostname -- hostname to connect to (default: localhost) + host/hostname -- hostname to connect to (default: localhost) port -- port to connect to (default: 50000) database -- name of the database (default: demo) autocommit -- enable/disable auto commit (default: False, @@ -44,8 +44,15 @@ class Connection: use_unicode -- use unicode for strings or not (default: False, only has effect on python2 since python3 is always unicode) + + If user and username are provided, user overrides the value of username. + If host and hostname are provided, host overrides the value of hostname. """ + if user is not None: + username = user + if host is not None: + hostname = host self.mapi = mapi.Server() self.autocommit = autocommit self.mapi.connect(hostname=hostname, port=int(port), username=username, _______________________________________________ Checkin-list mailing list [email protected] http://mail.monetdb.org/mailman/listinfo/checkin-list
