diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2017-02-03 04:28:27 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2017-02-03 04:29:27 +0000 |
commit | e1ef55ffbcec7a9a7f8d978c572050f59b1dff4e (patch) | |
tree | a1da4c2e21a93c91b5229004d3d6183816d9b7b7 /lib/__init__.py | |
parent | c71559cf19adad51a029aebfd663401cdb130aa6 (diff) | |
download | psycopg2-async-keyword.tar.gz |
Added async_ as an alias for asyncasync-keyword
Added in argument for psycopg2.connect() and connection.__init__, and
for the connection.async attribute.
Diffstat (limited to 'lib/__init__.py')
-rw-r--r-- | lib/__init__.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/__init__.py b/lib/__init__.py index fb22b4c..492b924 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -82,8 +82,7 @@ else: del Decimal, Adapter -def connect(dsn=None, connection_factory=None, cursor_factory=None, - async=False, **kwargs): +def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs): """ Create a new database connection. @@ -111,17 +110,24 @@ def connect(dsn=None, connection_factory=None, cursor_factory=None, Using the *cursor_factory* parameter, a new default cursor factory will be used by cursor(). - Using *async*=True an asynchronous connection will be created. + Using *async*=True an asynchronous connection will be created. *async_* is + a valid alias (for Python versions where ``async`` is a keyword). Any other keyword parameter will be passed to the underlying client library: the list of supported parameters depends on the library version. """ + kwasync = {} + if 'async' in kwargs: + kwasync['async'] = kwargs.pop('async') + if 'async_' in kwargs: + kwasync['async_'] = kwargs.pop('async_') + if dsn is None and not kwargs: raise TypeError('missing dsn and no parameters') dsn = _ext.make_dsn(dsn, **kwargs) - conn = _connect(dsn, connection_factory=connection_factory, async=async) + conn = _connect(dsn, connection_factory=connection_factory, **kwasync) if cursor_factory is not None: conn.cursor_factory = cursor_factory |