From: Cliff W. <cl...@de...> - 2005-12-30 21:08:10
|
Hi, I'm trying to get sqlobject to connect to a unix domain socket in a non-standard location. This works using named parameters, but not with a dsn. For instance, the dsn would *seem* to be: postgres:/user:pass@/path/to/local/socket:/database This doesn't work because SO decides that /path/to/local/socket is the name of the database because it starts with a slash. The obvious workaround is to use postgres:///?host=/path/to/local/socket&dbname=database But this doesn't work either, because now the value of "host" is passed twice in the SO internals . I have, however, found a workaround. In the file sqlobject/postgres/pgconnection.py. change the connectionFromURI to the following: def connectionFromURI(cls, uri): user, password, host, port, path, args = cls._parseURI(uri) path = path.strip('/') kwargs = { 'host': host, 'port': port, 'db': path, 'user': user, 'passwd': password } kwargs.update(args) return cls(**kwargs) connectionFromURI = classmethod(connectionFromURI) By doing an update() on the arguments, rather than passing them separately as named arguments, followed by args, it allows the user to override what may be getting set as defaults with named parameters so that postgres:///?host=/path/to/local/socket&dbname=database now works. Still a bit of a workaround, but a livable one. Also, this should not break any existing code. Regards, Cliff P.S. Hi Oleg! I haven't seen you in what seems like years (on c.l.py). Hope things are well with you. |