Skip to content

Commit 55c69c0

Browse files
committed
Clean up url_to_dsn a bit; #37
Stop passing host=None when host is None per urlparse. Just leave that (and also user, password, and port) out entirely if not in the URL.
1 parent 67d5e27 commit 55c69c0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

postgres/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,17 @@ def url_to_dsn(url):
204204
port = parsed.port
205205
if port is None:
206206
port = '5432' # postgres default port
207-
dsn = "dbname=%s user=%s password=%s host=%s port=%s"
208-
dsn %= (dbname, user, password, host, port)
207+
208+
dsn = "dbname=" + dbname
209+
if user is not None:
210+
dsn += " user=" + user
211+
if password is not None:
212+
dsn += " password=" + password
213+
if host is not None:
214+
dsn += " host=" + host
215+
if port is not None:
216+
dsn += " port=" + port
217+
209218
return dsn
210219

211220

0 commit comments

Comments
 (0)