From 2fc46f80667d76db2e69e6bfa21bcd7f09cf1078 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 30 Sep 2019 14:19:37 +0100 Subject: [PATCH 1/7] allow setting of source address --- pg8000/__init__.py | 4 ++-- pg8000/core.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pg8000/__init__.py b/pg8000/__init__.py index 56a06c6..13e9834 100644 --- a/pg8000/__init__.py +++ b/pg8000/__init__.py @@ -41,12 +41,12 @@ def connect( - user, host='localhost', unix_sock=None, port=5432, database=None, + user, host='localhost', source_address=None, unix_sock=None, port=5432, database=None, password=None, ssl=None, timeout=None, application_name=None, max_prepared_statements=1000, tcp_keepalive=True): return Connection( - user, host, unix_sock, port, database, password, ssl, timeout, + user, host, source_address, unix_sock, port, database, password, ssl, timeout, application_name, max_prepared_statements, tcp_keepalive) diff --git a/pg8000/core.py b/pg8000/core.py index aabb65f..7bb4f32 100644 --- a/pg8000/core.py +++ b/pg8000/core.py @@ -1151,6 +1151,8 @@ def __init__( try: if unix_sock is None and host is not None: self._usock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + if source_address is not None: + self._usock.bind((source_address,0)) elif unix_sock is not None: if not hasattr(socket, "AF_UNIX"): raise InterfaceError( From 75139ac7dbf7b965110ebe0d376976e2ae2ebe23 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 30 Sep 2019 14:28:27 +0100 Subject: [PATCH 2/7] fixing indent --- pg8000/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pg8000/core.py b/pg8000/core.py index 7bb4f32..c94f439 100644 --- a/pg8000/core.py +++ b/pg8000/core.py @@ -1151,8 +1151,8 @@ def __init__( try: if unix_sock is None and host is not None: self._usock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - if source_address is not None: - self._usock.bind((source_address,0)) + if source_address is not None: + self._usock.bind((source_address,0)) elif unix_sock is not None: if not hasattr(socket, "AF_UNIX"): raise InterfaceError( From c7759ddf3b384a960e6dc97858b0c6c6e206f914 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 30 Sep 2019 14:43:35 +0100 Subject: [PATCH 3/7] fix init of Connection --- pg8000/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pg8000/core.py b/pg8000/core.py index c94f439..aab99c9 100644 --- a/pg8000/core.py +++ b/pg8000/core.py @@ -1118,7 +1118,7 @@ def _getError(self, error): return error def __init__( - self, user, host, unix_sock, port, database, password, ssl, + self, user, host, source_address, unix_sock, port, database, password, ssl, timeout, application_name, max_prepared_statements, tcp_keepalive): self._client_encoding = "utf8" self._commands_with_count = ( From 272463f1d0d6b983fe70c49b0564d3625f4f329f Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 30 Sep 2019 14:50:12 +0100 Subject: [PATCH 4/7] updating docs --- README.adoc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index 47748c9..f84b013 100644 --- a/README.adoc +++ b/README.adoc @@ -461,7 +461,7 @@ ROWID type oid === Functions -==== pg8000.connect(user, host='localhost', unix_sock=None, port=5432, database=None, password=None, ssl=None, timeout=None, application_name=None, tcp_keepalive=True) +==== pg8000.connect(user, host='localhost', source_address=None, unix_sock=None, port=5432, database=None, password=None, ssl=None, timeout=None, application_name=None, tcp_keepalive=True) Creates a connection to a PostgreSQL database. @@ -478,6 +478,11 @@ host:: parameter is necessary for TCP/IP connections. One of either `host` or `unix_sock` must be provided. The default is `localhost`. +source_address:: + The source IP address which initiates the connection to the PostgreSQL server. + This is an optional parameter, if not set the operation system will choose an + source address + unix_sock:: The path to the UNIX socket to access the database through, for example, `'/tmp/.s.PGSQL.5432'`. One of either `host` or `unix_sock` must be provided. @@ -1288,7 +1293,7 @@ Note that this version is not backward compatible with previous versions. 2 it's recommended to send text as unicode() objects. * Dropped and added support for Python versions. Now pg8000 supports - Python 2.7+ and Python 3.3+. + Python 2.7+ and Python 3.3+. * Dropped and added support for PostgreSQL versions. Now pg8000 supports PostgreSQL 9.1+. From 8669a56b6b1ca708437cd37c13d5a7348d70de4e Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 30 Sep 2019 14:57:59 +0100 Subject: [PATCH 5/7] updating docs --- pg8000/__init__.py | 7 ++++--- pg8000/core.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pg8000/__init__.py b/pg8000/__init__.py index 13e9834..991694a 100644 --- a/pg8000/__init__.py +++ b/pg8000/__init__.py @@ -41,9 +41,10 @@ def connect( - user, host='localhost', source_address=None, unix_sock=None, port=5432, database=None, - password=None, ssl=None, timeout=None, application_name=None, - max_prepared_statements=1000, tcp_keepalive=True): + user, host='localhost', source_address=None, unix_sock=None, port=5432, + database=None, password=None, ssl=None, timeout=None, + application_name=None, max_prepared_statements=1000, + tcp_keepalive=True): return Connection( user, host, source_address, unix_sock, port, database, password, ssl, timeout, diff --git a/pg8000/core.py b/pg8000/core.py index aab99c9..85e7e21 100644 --- a/pg8000/core.py +++ b/pg8000/core.py @@ -1118,8 +1118,9 @@ def _getError(self, error): return error def __init__( - self, user, host, source_address, unix_sock, port, database, password, ssl, - timeout, application_name, max_prepared_statements, tcp_keepalive): + self, user, host, source_address, unix_sock, port, database, + password, ssl, timeout, application_name, max_prepared_statements, + tcp_keepalive): self._client_encoding = "utf8" self._commands_with_count = ( b"INSERT", b"DELETE", b"UPDATE", b"MOVE", b"FETCH", b"COPY", @@ -1152,7 +1153,7 @@ def __init__( if unix_sock is None and host is not None: self._usock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if source_address is not None: - self._usock.bind((source_address,0)) + self._usock.bind((source_address, 0)) elif unix_sock is not None: if not hasattr(socket, "AF_UNIX"): raise InterfaceError( From e0cd30a3b7599b759a7128e9660d05e53015f947 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 30 Sep 2019 14:58:56 +0100 Subject: [PATCH 6/7] update version --- versioneer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versioneer.py b/versioneer.py index c010f63..f188768 100644 --- a/versioneer.py +++ b/versioneer.py @@ -1,5 +1,5 @@ -# Version: 0.15 +# Version: 0.16 """ The Versioneer From e57a6cb8ebe25bea3b69eede5874a442e1ae8113 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 30 Sep 2019 15:03:18 +0100 Subject: [PATCH 7/7] fix line length --- pg8000/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pg8000/__init__.py b/pg8000/__init__.py index 991694a..d5e0cd4 100644 --- a/pg8000/__init__.py +++ b/pg8000/__init__.py @@ -47,8 +47,8 @@ def connect( tcp_keepalive=True): return Connection( - user, host, source_address, unix_sock, port, database, password, ssl, timeout, - application_name, max_prepared_statements, tcp_keepalive) + user, host, source_address, unix_sock, port, database, password, ssl, + timeout, application_name, max_prepared_statements, tcp_keepalive) apilevel = "2.0"