]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Merge pull request #25 from gthb/ticket_2821
authormike bayer <mike_mp@zzzcomputing.com>
Sun, 29 Sep 2013 21:03:46 +0000 (14:03 -0700)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 29 Sep 2013 21:10:54 +0000 (17:10 -0400)
Hide password in URL and Engine __repr__
Conflicts:
lib/sqlalchemy/engine/url.py

lib/sqlalchemy/engine/base.py
lib/sqlalchemy/engine/url.py
test/engine/test_parseconnect.py

index b4c9b1e1c7122c91e8ce31a6c9b40d3b3d2f6313..25167167d5304dbbf75555c24b26a05f00c49cd0 100644 (file)
@@ -1433,7 +1433,7 @@ class Engine(Connectable, log.Identified):
     echo = log.echo_property()
 
     def __repr__(self):
-        return 'Engine(%s)' % str(self.url)
+        return 'Engine(%r)' % self.url
 
     def dispose(self):
         """Dispose of the connection pool used by this :class:`.Engine`.
index c4931b48c31e0e80fb002a0dd0ebaea90f51e52a..b15bfbd5243eb804c98e85e58c29ef9784beb141 100644 (file)
@@ -62,12 +62,13 @@ class URL(object):
         self.database = database
         self.query = query or {}
 
-    def __str__(self):
+    def __to_string__(self, hide_password=True):
         s = self.drivername + "://"
         if self.username is not None:
             s += self.username
             if self.password is not None:
-                s += ':' + urllib.quote_plus(self.password)
+                s += ':' + ('***' if hide_password
+                            else urllib.quote_plus(self.password))
             s += "@"
         if self.host is not None:
             s += self.host
@@ -81,6 +82,12 @@ class URL(object):
             s += '?' + "&".join("%s=%s" % (k, self.query[k]) for k in keys)
         return s
 
+    def __str__(self):
+        return self.__to_string__(hide_password=False)
+
+    def __repr__(self):
+        return self.__to_string__()
+
     def __hash__(self):
         return hash(str(self))
 
index 437cccbe45c991fb5a5b090be86cf72dc0a4c147..b7edb655cd380c9f2095aa378edb83bc3f9d4ca7 100644 (file)
@@ -278,6 +278,10 @@ pool_timeout=10
         assert e.url.drivername == e2.url.drivername == 'mysql'
         assert e.url.username == e2.url.username == 'scott'
         assert e2.url is u
+        assert str(u) == 'mysql://scott:tiger@localhost/test'
+        assert repr(u) == 'mysql://scott:***@localhost/test'
+        assert repr(e) == 'Engine(mysql://scott:***@localhost/test)'
+        assert repr(e2) == 'Engine(mysql://scott:***@localhost/test)'
 
     def test_poolargs(self):
         """test that connection pool args make it thru"""