Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
Expand Down Expand Up @@ -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+.
Expand Down
11 changes: 6 additions & 5 deletions pg8000/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@


def connect(
user, host='localhost', 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, 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"
Expand Down
7 changes: 5 additions & 2 deletions pg8000/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,8 +1118,9 @@ def _getError(self, error):
return error

def __init__(
self, user, host, 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",
Expand Down Expand Up @@ -1151,6 +1152,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(
Expand Down
2 changes: 1 addition & 1 deletion versioneer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Version: 0.15
# Version: 0.16

"""
The Versioneer
Expand Down