diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2013-09-29 14:03:46 -0700 |
---|---|---|
committer | mike bayer <mike_mp@zzzcomputing.com> | 2013-09-29 14:03:46 -0700 |
commit | dda72ddcf06cdbda7205653601910449c1e293f6 (patch) | |
tree | dc307113c32efdce9bb97055bc5ae999191829d6 /lib/sqlalchemy | |
parent | 8f4002814907683ac0fb7b34f106a2cb7cfd7b34 (diff) | |
parent | 610684bb080095dcd8a2ca6cef1ff45787e4bdcf (diff) | |
download | sqlalchemy-dda72ddcf06cdbda7205653601910449c1e293f6.tar.gz |
Merge pull request #25 from gthb/ticket_2821
Hide password in URL and Engine __repr__
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/url.py | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 93539cb14..6110992bb 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -1417,7 +1417,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`. diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index 717eb54e1..1f192ae7f 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -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 += ':' + util.quote_plus(self.password) + s += ':' + ('***' if hide_password + else util.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)) |