diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-04-17 20:49:35 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-04-17 20:49:35 +0000 |
commit | aabb6e530b05bee9cc5c2382a308a987abd6168e (patch) | |
tree | cd937947baf100d75e679e2f6d40e3a287ffc196 /lib/sqlalchemy/engine/url.py | |
parent | 8d7a271b8687dbcb58cac713f9e16e445d242881 (diff) | |
download | sqlalchemy-aabb6e530b05bee9cc5c2382a308a987abd6168e.tar.gz |
- the dialects within sqlalchemy.databases become a setuptools
entry points. loading the built-in database dialects works the
same as always, but if none found will fall back to trying
pkg_resources to load an external module [ticket:521]
Diffstat (limited to 'lib/sqlalchemy/engine/url.py')
-rw-r--r-- | lib/sqlalchemy/engine/url.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index faa0ffc11..c5ad90ee9 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -69,19 +69,28 @@ class URL(object): s += '?' + "&".join(["%s=%s" % (k, self.query[k]) for k in keys]) return s - def get_module(self): - """Return the SQLAlchemy database module corresponding to this URL's driver name.""" + def get_dialect(self): + """Return the SQLAlchemy database dialect class corresponding to this URL's driver name.""" + dialect=None if self.drivername == 'ansi': import sqlalchemy.ansisql - return sqlalchemy.ansisql - + return sqlalchemy.ansisql.dialect + try: - return getattr(__import__('sqlalchemy.databases.%s' % self.drivername).databases, self.drivername) + module=getattr(__import__('sqlalchemy.databases.%s' % self.drivername).databases, self.drivername) + dialect=module.dialect except ImportError: if sys.exc_info()[2].tb_next is None: - raise exceptions.ArgumentError('unknown database %r' % self.drivername) - raise - + import pkg_resources + for res in pkg_resources.iter_entry_points('sqlalchemy.databases'): + if res.name==self.drivername: + dialect=res.load() + else: + raise + if dialect is not None: + return dialect + raise ImportError('unknown database %r' % self.drivername) + def translate_connect_args(self, names): """Translate this URL's attributes into a dictionary of connection arguments. |