diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-12-05 00:36:11 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-12-05 00:36:11 +0000 |
commit | ffdbcbc89a2ac12be499944195572d3014b34061 (patch) | |
tree | aedd7bd2d345f815ebddcd4f35a1ea14d76cf1e9 /lib/sqlalchemy/engine/url.py | |
parent | a52ffc36476916988742098888ffae43a9b48e74 (diff) | |
download | sqlalchemy-ffdbcbc89a2ac12be499944195572d3014b34061.tar.gz |
- fixed the import for entrypoint-driven dialects to
not rely upon silly tb_info trick to determine import
error status. [ticket:1630]
Diffstat (limited to 'lib/sqlalchemy/engine/url.py')
-rw-r--r-- | lib/sqlalchemy/engine/url.py | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index c62f1cf10..5d658d7fc 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -102,13 +102,30 @@ class URL(object): return module.dialect except ImportError: - if sys.exc_info()[2].tb_next is None: - import pkg_resources - for res in pkg_resources.iter_entry_points('sqlalchemy.dialects'): - if res.name == self.drivername: - return res.load() - raise - + module = self._load_entry_point() + if module is not None: + return module + else: + raise + + def _load_entry_point(self): + """attempt to load this url's dialect from entry points, or return None + if pkg_resources is not installed or there is no matching entry point. + + Raise ImportError if the actual load fails. + + """ + try: + import pkg_resources + except ImportError: + return None + + for res in pkg_resources.iter_entry_points('sqlalchemy.dialects'): + if res.name == self.drivername: + return res.load() + else: + return None + def translate_connect_args(self, names=[], **kw): """Translate url attributes into a dictionary of connection arguments. |