Skip to content

Commit 924e548

Browse files
committed
Accept libpq schemes ('postgres://' and 'postgresql://') in addition to pq://
1 parent a89bd7b commit 924e548

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

postgresql/iri.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
Driver Parameters:
1616
17-
pq://user@host/?[driver_param]=value&[other_param]=value?setting=val
17+
pq://user@host/?[driver_param]=value&[other_param]=value?server_setting=val
1818
"""
1919
from .resolved import riparse as ri
2020
from .string import split_ident
@@ -30,8 +30,8 @@ def structure(d, fieldproc = ri.unescape):
3030
"""
3131
Create a clientparams dictionary from a parsed RI.
3232
"""
33-
if d.get('scheme', 'pq').lower() != 'pq':
34-
raise ValueError("PQ-IRI scheme is not 'pq'")
33+
if d.get('scheme', 'pq').lower() not in {'pq', 'postgres', 'postgresql'}:
34+
raise ValueError("PQ-IRI scheme is not 'pq', 'postgres', or 'postgresql'")
3535
cpd = {
3636
k : fieldproc(v) for k, v in d.items()
3737
if k not in ('path', 'fragment', 'query', 'host', 'scheme')

postgresql/test/test_iri.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
':pass@',
1919
'u:p@h',
2020
'u:p@h:1',
21+
'postgres://host/database',
2122
'pq://user:password@host:port/database?setting=value#public,private',
2223
'pq://fæm.com:123/õéf/á?param=val',
2324
'pq://l»»@fæm.com:123/õéf/á?param=val',
@@ -84,6 +85,20 @@
8485
]
8586

8687
class test_iri(unittest.TestCase):
88+
def testAlternateSchemes(self):
89+
field = pg_iri.parse("postgres://host")['host']
90+
self.assertEqual(field, 'host')
91+
92+
field = pg_iri.parse("postgresql://host")['host']
93+
self.assertEqual(field, 'host')
94+
95+
try:
96+
pg_iri.parse("reject://host")
97+
except ValueError:
98+
pass
99+
else:
100+
self.fail("unacceptable IRI scheme not rejected")
101+
87102
def testIP6Hosts(self):
88103
"""
89104
Validate that IPv6 hosts are properly extracted.
@@ -101,15 +116,19 @@ def testIP6Hosts(self):
101116
self.assertEqual(p['host'], h)
102117

103118
def testPresentPasswordObscure(self):
104-
"password is present in IRI, and obscure it"
119+
"""
120+
Password is present in IRI, and obscure it.
121+
"""
105122
s = 'pq://user:pass@host:port/dbname'
106123
o = 'pq://user:***@host:port/dbname'
107124
p = pg_iri.parse(s)
108125
ps = pg_iri.serialize(p, obscure_password = True)
109126
self.assertEqual(ps, o)
110127

111128
def testPresentPasswordObscure(self):
112-
"password is *not* present in IRI, and do nothing"
129+
"""
130+
Password is *not* present in IRI, and do nothing.
131+
"""
113132
s = 'pq://user@host:port/dbname'
114133
o = 'pq://user@host:port/dbname'
115134
p = pg_iri.parse(s)

0 commit comments

Comments
 (0)