summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-08-22 18:58:01 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-08-22 18:58:01 +0000
commita8d1aecfabe288dcfce3c01bfd87a5a6aff3683c (patch)
tree506df1e9413dfcf96e475e9c668cf8bc52907283
parent3003239bebcc545a865888ded899199a99faa72c (diff)
downloadsqlalchemy-a8d1aecfabe288dcfce3c01bfd87a5a6aff3683c.tar.gz
- urls support escaped characters in passwords [ticket:281]
-rw-r--r--CHANGES1
-rw-r--r--lib/sqlalchemy/engine/url.py5
-rw-r--r--test/engine/parseconnect.py5
3 files changed, 8 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index f456647b3..4b8329012 100644
--- a/CHANGES
+++ b/CHANGES
@@ -27,6 +27,7 @@ flag for use with table reflection to help with quoting rules
[ticket:155]
- unit tests updated to run without any pysqlite installed; pool
test uses a mock DBAPI
+- urls support escaped characters in passwords [ticket:281]
0.2.7
- quoting facilities set up so that database-specific quoting can be
diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py
index bd8ee2643..7c3d947ca 100644
--- a/lib/sqlalchemy/engine/url.py
+++ b/lib/sqlalchemy/engine/url.py
@@ -1,5 +1,6 @@
import re
import cgi
+import urllib
import sqlalchemy.exceptions as exceptions
class URL(object):
@@ -19,7 +20,7 @@ class URL(object):
if self.username is not None:
s += self.username
if self.password is not None:
- s += ':' + self.password
+ s += ':' + urllib.quote_plus(self.password)
s += "@"
if self.host is not None:
s += self.host
@@ -81,6 +82,8 @@ def _parse_rfc1738_args(name):
else:
query = None
opts = {'username':username,'password':password,'host':host,'port':port,'database':database, 'query':query}
+ if opts['password'] is not None:
+ opts['password'] = urllib.unquote_plus(opts['password'])
return URL(name, **opts)
else:
raise exceptions.ArgumentError("Could not parse rfc1738 URL from string '%s'" % name)
diff --git a/test/engine/parseconnect.py b/test/engine/parseconnect.py
index cb77d96d0..9465af684 100644
--- a/test/engine/parseconnect.py
+++ b/test/engine/parseconnect.py
@@ -21,14 +21,15 @@ class ParseConnectTest(PersistTest):
'dbtype:///E:/work/src/LEM/db/hello.db?foo=bar&hoho=lala',
'dbtype://',
'dbtype://username:password@/db',
- 'dbtype:////usr/local/mailman/lists/_xtest@example.com/members.db'
+ 'dbtype:////usr/local/mailman/lists/_xtest@example.com/members.db',
+ 'dbtype://username:apples%2Foranges@hostspec/mydatabase',
):
u = url.make_url(text)
print u, text
print "username=", u.username, "password=", u.password, "database=", u.database, "host=", u.host
assert u.drivername == 'dbtype'
assert u.username == 'username' or u.username is None
- assert u.password == 'password' or u.password is None
+ assert u.password == 'password' or u.password == 'apples/oranges' or u.password is None
assert u.host == 'hostspec' or u.host == '127.0.0.1' or (not u.host)
assert str(u) == text