From 1a88a982b43f2f3a0735890b00a45e178727812f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 4 Aug 2013 15:28:40 -0400 Subject: find some more inline imports and move them out --- lib/sqlalchemy/engine/url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/sqlalchemy/engine/url.py') diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index ed5729eea..717eb54e1 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -16,6 +16,7 @@ be used directly and is also accepted directly by ``create_engine()``. import re from .. import exc, util from . import Dialect +from ..dialects import registry class URL(object): @@ -102,7 +103,6 @@ class URL(object): name = self.drivername else: name = self.drivername.replace('+', '.') - from sqlalchemy.dialects import registry cls = registry.load(name) # check for legacy dialects that # would return a module with 'dialect' as the -- cgit v1.2.1 From 610684bb080095dcd8a2ca6cef1ff45787e4bdcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gunnlaugur=20=C3=9E=C3=B3r=20Briem?= Date: Fri, 6 Sep 2013 17:55:19 +0000 Subject: Hide password in URL and Engine __repr__ Fixes #2821 --- lib/sqlalchemy/engine/url.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/engine/url.py') 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)) -- cgit v1.2.1 From 382cd56772efd92a9fe5ce46623029a04163c8cf Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 23 Oct 2013 15:02:36 -0400 Subject: - The regexp used by the :func:`.url.make_url` function now parses ipv6 addresses, e.g. surrounded by brackets. [ticket:2851] --- lib/sqlalchemy/engine/url.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/engine/url.py') diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index 1f192ae7f..74584b787 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -71,7 +71,10 @@ class URL(object): else util.quote_plus(self.password)) s += "@" if self.host is not None: - s += self.host + if ':' in self.host: + s += "[%s]" % self.host + else: + s += self.host if self.port is not None: s += ':' + str(self.port) if self.database is not None: @@ -170,7 +173,10 @@ def _parse_rfc1738_args(name): (?::(?P[^/]*))? @)? (?: - (?P[^/:]*) + (?: + \[(?P[^/]+)\] | + (?P[^/:]+) + )? (?::(?P[^/]*))? )? (?:/(?P.*))? @@ -193,6 +199,9 @@ def _parse_rfc1738_args(name): components['password'] = \ util.unquote_plus(components['password']) + ipv4host = components.pop('ipv4host') + ipv6host = components.pop('ipv6host') + components['host'] = ipv4host or ipv6host name = components.pop('name') return URL(name, **components) else: -- cgit v1.2.1 From 6dc72a1355dbebd8676481a2530c6e558fc403a9 Mon Sep 17 00:00:00 2001 From: Vraj Mohan Date: Wed, 13 Nov 2013 09:40:17 -0500 Subject: Ensure API doc for make_url and resolve references --- lib/sqlalchemy/engine/url.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/engine/url.py') diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index 74584b787..8f84ab039 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -24,8 +24,8 @@ class URL(object): Represent the components of a URL used to connect to a database. This object is suitable to be passed directly to a - ``create_engine()`` call. The fields of the URL are parsed from a - string by the ``module-level make_url()`` function. the string + :func:`~sqlalchemy.create_engine` call. The fields of the URL are parsed from a + string by the :func:`.make_url` function. the string format of the URL is an RFC-1738-style string. All initialization parameters are available as public attributes. -- cgit v1.2.1 From 2800e34710672b408fa4a7bdd6d58d63a7128f04 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 24 Nov 2013 18:11:37 -0500 Subject: - The :func:`.create_engine` routine and the related :func:`.make_url` function **no longer URL encode the password**. Database passwords that include characters like spaces, plus signs and anything else should now represent these characters directly, without any URL escaping. [ticket:2873] --- lib/sqlalchemy/engine/url.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'lib/sqlalchemy/engine/url.py') diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index 8f84ab039..28c15299e 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -67,8 +67,7 @@ class URL(object): if self.username is not None: s += self.username if self.password is not None: - s += ':' + ('***' if hide_password - else util.quote_plus(self.password)) + s += ':' + ('***' if hide_password else self.password) s += "@" if self.host is not None: if ':' in self.host: @@ -170,7 +169,7 @@ def _parse_rfc1738_args(name): (?P[\w\+]+):// (?: (?P[^:/]*) - (?::(?P[^/]*))? + (?::(?P.*))? @)? (?: (?: @@ -195,10 +194,6 @@ def _parse_rfc1738_args(name): query = None components['query'] = query - if components['password'] is not None: - components['password'] = \ - util.unquote_plus(components['password']) - ipv4host = components.pop('ipv4host') ipv6host = components.pop('ipv6host') components['host'] = ipv4host or ipv6host -- cgit v1.2.1 From 6029496bd3fb78caeab349ef8df5b58f058db16e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 25 Nov 2013 14:46:58 -0500 Subject: - adjustment, the spec says: "Within the user and password field, any ":", "@", or "/" must be encoded." - so re-apply encoding to both password and username, don't encode spaces as plus signs, don't encode any chars outside of :, @, / on stringification - but we still parse for any %XX character (is that right?) --- lib/sqlalchemy/engine/url.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/engine/url.py') diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index 28c15299e..77fbe2346 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -65,9 +65,10 @@ class URL(object): def __to_string__(self, hide_password=True): s = self.drivername + "://" if self.username is not None: - s += self.username + s += _rfc_1738_quote(self.username) if self.password is not None: - s += ':' + ('***' if hide_password else self.password) + s += ':' + ('***' if hide_password + else _rfc_1738_quote(self.password)) s += "@" if self.host is not None: if ':' in self.host: @@ -194,6 +195,12 @@ def _parse_rfc1738_args(name): query = None components['query'] = query + if components['username'] is not None: + components['username'] = _rfc_1738_unquote(components['username']) + + if components['password'] is not None: + components['password'] = _rfc_1738_unquote(components['password']) + ipv4host = components.pop('ipv4host') ipv6host = components.pop('ipv6host') components['host'] = ipv4host or ipv6host @@ -204,6 +211,12 @@ def _parse_rfc1738_args(name): "Could not parse rfc1738 URL from string '%s'" % name) +def _rfc_1738_quote(text): + return re.sub(r'[:@/]', lambda m: "%%%X" % ord(m.group(0)), text) + +def _rfc_1738_unquote(text): + return util.unquote(text) + def _parse_keyvalue_args(name): m = re.match(r'(\w+)://(.*)', name) if m is not None: -- cgit v1.2.1 From f89d4d216bd7605c920b7b8a10ecde6bfea2238c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 5 Jan 2014 16:57:05 -0500 Subject: - happy new year --- lib/sqlalchemy/engine/url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/sqlalchemy/engine/url.py') diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index 77fbe2346..78ac06187 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -1,5 +1,5 @@ # engine/url.py -# Copyright (C) 2005-2013 the SQLAlchemy authors and contributors +# Copyright (C) 2005-2014 the SQLAlchemy authors and contributors # # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -- cgit v1.2.1