[DB-SIG] [SQLObject] Re: SQLite connection - relative filename

Ian Bicking ianb at colorstudy.com
Fri Apr 1 22:22:39 CEST 2005


Paul Moore wrote:
> Maybe _parseURI should use urllib.url2pathname? That would still be
> mildly suboptimal, as url2pathname doesn't accept the common form
> '///C:/a/b/...'. But that's a stdlib issue.

Incidentally, while we're on the topic of URIs, I'd like to move all 
this URI parsing stuff into a library that doesn't have SQLObject 
dependencies, so that other people can use the same syntax for defining 
DB-API connections in any system.  Since there's all sort of annoying 
aspects to URI parsing (many of which probably would have been avoided 
if I had used urllib from the start :( ), it seems like such a library 
would be useful.  Such a library would probably produce a connection 
function and keyword parameters, so that actual connection creation 
could be held off until after parsing, i.e.:


# in dburi.py:
def uri_connect(uri):
     func, args, kwargs = uri_parse('...')
     return func(*args, **kw)

module_aliases = {
     'pgsql': 'psycopg',
     'mysql': 'MySQLdb',
     # ...
     }

def uri_parse(uri):
     module_name = uri.split(':', 1)
     module_name = module_aliases.get(module_name.lower(), module_name)
     module = __import__(module_name)
     if hasattr(module, 'uri_parse'):
         return module.uri_parse(uri)
     elif globals().has_key('%s_uri_parse' % module_name):
         return globals()['%s_uri_parse' % module_name](uri, module)
     else:
         return generic_uri_parse(uri, module)


Then we'll start implementing parsers for backward compatibility, but 
perhaps upstream driver authors can start including their own uri_parse 
functions.

Well, the one missing part of this is that it would also be nice to 
construct a URI from an already-existing connection object, and to store 
the original URI if that's how that connection object was originally 
created.


-- 
Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org


More information about the DB-SIG mailing list