On Sep 25, 2006, at 7:25 AM, Stephen Chisholm wrote:

> Here is a method that works:
>
> If one runs a postgres server listening _only_ a Unix socket this code
> below shows how to connect and SA engine to it.
>
>    import sqlalchemy as sa
>
>    conn_args = {
>        'host':'/tmp/pg',
>        'database':'t-design',
>    }
>
>    db = sa.create_engine('postgres://', connect_args = conn_args)

If I add "unquote_plus" to all the arguments in the URL (right now  
its just on password), you can get it like this:

u = url.make_url("postgres://%2Ffoo%2Fbar/t-design")

diff is below.  there is at least one user who wants me to make this  
change.  the question is, is it rfc1738 compliant ?

Index: lib/sqlalchemy/engine/url.py
===================================================================
--- lib/sqlalchemy/engine/url.py        (revision 1894)
+++ lib/sqlalchemy/engine/url.py        (working copy)
@@ -18,12 +18,12 @@
      def __str__(self):
          s = self.drivername + "://"
          if self.username is not None:
-            s += self.username
+            s += urllib.quote_plus(self.username)
              if self.password is not None:
                  s += ':' + urllib.quote_plus(self.password)
              s += "@"
          if self.host is not None:
-            s += self.host
+            s += urllib.quote_plus(self.host)
          if self.port is not None:
              s += ':' + str(self.port)
          if self.database is not None:
@@ -31,7 +31,7 @@
          if len(self.query):
              keys = self.query.keys()
              keys.sort()
-            s += '?' + "&".join(["%s=%s" % (k, self.query[k]) for k  
in keys])
+            s += '?' + "&".join(["%s=%s" % (k, urllib.quote_plus 
(self.query[k])) for k in keys])
          return s
      def get_module(self):
          return getattr(__import__('sqlalchemy.databases.%s' %  
self.drivername).databases, self.drivername)
@@ -82,8 +82,9 @@
          else:
              query = None
          opts =  
{'username':username,'password':password,'host':host,'port':port,'databa 
se':database, 'query':query}
-        if opts['password'] is not None:
-            opts['password'] = urllib.unquote_plus(opts['password'])
+        for opt in ['username', 'password', 'host']:
+            if opts[opt] is not None:
+                opts[opt] = urllib.unquote_plus(opts[opt])
          return URL(name, **opts)
      else:
          raise exceptions.ArgumentError("Could not parse rfc1738 URL  
from string '%s'" % name)


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to