Senthil added the comment:

> Olivier Croquette added the comment:
> 
> 
> The problem right now is that urlparse parses silently an URL which is
> not compliant, but does the wrong thing with it (since usernames can
> contain @, and hostname can not, it's a more logical thing to parse from
> the right using rsplit instead of split).
> 
> I see two possibilities to address that:
> 
> 1. return a parse error if the URL contains two raw @
> This way users and app developers will notice the problem rapidly
> 
> 2. still accept this malformed URLs, but do what the user expects
> 
> Both solutions seem to me better than the current behaviour, so I would
> say a change is necessary anyways.

I am inclined towards the option 2, wherein even if the non-conformant URL is
given, which has "@" in the user name, the urlparse should be able atleast
recognize the hostname correctly. In this case, using rsplit instead of split
does the trick.

Attached is the patch against the trunk, which adds this. I notice duplicity
project also retorting to the same.

Unless anyone has an objection, we should commit this change.

Added file: http://bugs.python.org/file9030/urlparse_issue1698.patch

__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1698>
__________________________________
Index: Lib/urlparse.py
===================================================================
--- Lib/urlparse.py     (revision 59600)
+++ Lib/urlparse.py     (working copy)
@@ -82,7 +82,7 @@
     def username(self):
         netloc = self.netloc
         if "@" in netloc:
-            userinfo = netloc.split("@", 1)[0]
+            userinfo = netloc.rsplit("@", 1)[0]
             if ":" in userinfo:
                 userinfo = userinfo.split(":", 1)[0]
             return userinfo
@@ -92,7 +92,7 @@
     def password(self):
         netloc = self.netloc
         if "@" in netloc:
-            userinfo = netloc.split("@", 1)[0]
+            userinfo = netloc.rsplit("@", 1)[0]
             if ":" in userinfo:
                 return userinfo.split(":", 1)[1]
         return None
@@ -101,7 +101,7 @@
     def hostname(self):
         netloc = self.netloc
         if "@" in netloc:
-            netloc = netloc.split("@", 1)[1]
+            netloc = netloc.rsplit("@", 1)[1]
         if ":" in netloc:
             netloc = netloc.split(":", 1)[0]
         return netloc.lower() or None
@@ -110,7 +110,7 @@
     def port(self):
         netloc = self.netloc
         if "@" in netloc:
-            netloc = netloc.split("@", 1)[1]
+            netloc = netloc.rsplit("@", 1)[1]
         if ":" in netloc:
             port = netloc.split(":", 1)[1]
             return int(port, 10)

_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to