-
-
Notifications
You must be signed in to change notification settings - Fork 514
Add parse_dsn module function #321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Calls PQconninfoParse to parse the dsn into a list of keyword and value structs, then constructs a dictionary from that. Can be useful when one needs to alter some part of the the connection string reliably, but doesn't want to get into all the details of parsing a dsn string: quoting, URL format, etc.
@@ -91,6 +92,17 @@ The module interface respects the standard defined in the |DBAPI|_. | |||
The parameters *connection_factory* and *async* are Psycopg extensions | |||
to the |DBAPI|. | |||
|
|||
.. function:: parse_dsn(dsn) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should be exposed by psycopg2.extensions, not the main module.
Thank you for the contribution. The patch needs tests, both failing and successful, and possibly with some tricky values (quotes, non-quotes, spaces etc). |
Excellent points, thank you! I will have another look on it and re-submit. |
I've addressed your feedback on this patch, please have a look when you got a minute. |
Thank you, it seems much better. |
Good catch with libq version. I think it's just a matter of exposing PQlibVersion in python and having @skip_before_libpq decorator? |
Exposing the libpq version is another thing we should have done for a long time, see issue #35. We sort of dragged it because at the time of opening the likelyhood of that function not being available was high, but now we are planning several features for psycopg 2.7 requiring a more modern libpq so I guess it's time to implement it. |
Conflicts: lib/extensions.py
Hey Daniele, could you please merge this? We could really use reliable DSN parsing in #322 in order to specify the |
Ok, I'll give it a final review and merge it. |
I've made a few fixes and merged, thank you very much. |
Calls PQconninfoParse to parse the dsn into a list of keyword and value
structs, then constructs a dictionary from that. Can be useful when one
needs to alter some part of the the connection string reliably, but
doesn't want to get into all the details of parsing a dsn string:
quoting, URL format, etc.