Mike Bayer  committed 0dd62c7

- added 'url' attribute to Engine
- added docstring to 'echo' attribute

  • Participants
  • Parent commits 83ede5f

Comments (0)

Files changed (6)

       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]
+    - Engine contains a "url" attribute referencing the url.URL object
+      used by create_engine().
 - sql:
     - keys() of result set columns are not lowercased, come back
       exactly as they're expressed in cursor.description.  note this

File lib/sqlalchemy/engine/

         self.echo = echo
         self.logger = logging.instance_logger(self)
-    name = property(lambda s:sys.modules[s.dialect.__module__].descriptor()['name'])
+    name = property(lambda s:sys.modules[s.dialect.__module__].descriptor()['name'], doc="String name of the [sqlalchemy.engine#Dialect] in use by this ``Engine``.")
     engine = property(lambda s:s)
-    dialect = property(lambda s:s._dialect)
+    dialect = property(lambda s:s._dialect, doc="the [sqlalchemy.engine#Dialect] in use by this engine.")
     echo = logging.echo_property()
+    url = property(lambda s:s.connection_provider.url, doc="The [sqlalchemy.engine.url#URL] object representing this ``Engine`` object's datasource.")
     def dispose(self):

File lib/sqlalchemy/engine/

 """Provide default implementations of the engine interfaces"""
 class PoolConnectionProvider(base.ConnectionProvider):
-    def __init__(self, pool):
+    def __init__(self, url, pool):
+        self.url = url
         self._pool = pool
     def get_connection(self):

File lib/sqlalchemy/engine/

                 pool = pool
-        provider = self.get_pool_provider(pool)
+        provider = self.get_pool_provider(u, pool)
         # create engine.
         engineclass = self.get_engine_cls()
     def pool_threadlocal(self):
         raise NotImplementedError()
-    def get_pool_provider(self, pool):
+    def get_pool_provider(self, url, pool):
         raise NotImplementedError()
     def get_engine_cls(self):
     def pool_threadlocal(self):
         return False
-    def get_pool_provider(self, pool):
-        return default.PoolConnectionProvider(pool)
+    def get_pool_provider(self, url, pool):
+        return default.PoolConnectionProvider(url, pool)
     def get_engine_cls(self):
         return base.Engine
     def pool_threadlocal(self):
         return True
-    def get_pool_provider(self, pool):
-        return threadlocal.TLocalConnectionProvider(pool)
+    def get_pool_provider(self, url, pool):
+        return threadlocal.TLocalConnectionProvider(url, pool)
     def get_engine_cls(self):
         return threadlocal.TLEngine

File lib/sqlalchemy/

 class echo_property(object):
     level_map={logging.DEBUG : "debug", logging.INFO:True}
+    __doc__ = "when ``True``, enable echoing for this element."
     def __get__(self, instance, owner):
         level = logging.getLogger(_get_instance_name(instance)).getEffectiveLevel()
         return echo_property.level_map.get(level, False)
     def __set__(self, instance, value):
+        if instance is None:
+            return self
         if value:
             logging.getLogger(_get_instance_name(instance)).setLevel(value == 'debug' and logging.DEBUG or logging.INFO)

File test/engine/

             assert False
         except exceptions.DBAPIError:
             assert True
+    def testurlattr(self):
+        """test the url attribute on ``Engine``."""
+        e = create_engine('mysql://scott:tiger@localhost/test', module=MockDBAPI())
+        u = url.make_url('mysql://scott:tiger@localhost/test')
+        e2 = create_engine(u, module=MockDBAPI())
+        assert e.url.drivername == e2.url.drivername == 'mysql'
+        assert e.url.username == e2.url.username == 'scott'
+        assert e2.url is u
     def testpoolargs(self):
         """test that connection pool args make it thru"""
         e = create_engine('postgres://', creator=None, pool_recycle=-1, echo_pool=None, auto_close_cursors=False, disallow_open_cursors=True, module=MockDBAPI())