should urlparse return user and pass in separate components?

M

metaperl

The urlparse with Python 2.4.3 includes the user and pass in the site
aspect of its parse:
'bill:[email protected]'


I personally would prefer that it be broken down a bit further. What
are existing opinions on this?
 
S

skip

metaperl> I personally would prefer that it be broken down a bit
metaperl> further. What are existing opinions on this?

I believe there have been noises made in this direction, and not that long
ago. If a backward-compatible way of solving this problem could be worked
out, I imagine this could go in 2.6. If not, such a change would probably
have to wait until 3.0. I'm sure there are plenty of applications in the
wild that rely on the current behavior. You might try searching the bugs
and patches on SF to see if someone's already submitted a patch. If so,
feel free to try it out and add a review comment.

Skip
 
L

Larry Bates

metaperl said:
The urlparse with Python 2.4.3 includes the user and pass in the site
aspect of its parse:

'bill:[email protected]'


I personally would prefer that it be broken down a bit further. What
are existing opinions on this?
Here is a function that I wrote to do that. It doesn't do
exactly what you want, but might save you some time.

def spliturl(self, url):
'''
spliturl - method to split composite url into its component parts
ftp://username:p[email protected]/dav

gets split into:

scheme.............ftp
domain.............www.domain.com
username...........username
password...........password
rootfolder........./dav
port...............None

returns list of 6 strings/None containing above listed variables
'''
parts=urlparse.urlsplit(url)
scheme=parts[0]
usernameandpassword, domain=urllib.splituser(parts[1])
username, password=urllib.splitpasswd(usernameandpassword)
rootfolder, port=urllib.splitport(parts[2])
if port is not None: port=int(port)
return [scheme, domain, username, password, rootfolder, port]

-Larry Bates
 
L

Larry Bates

Oops, sorry missed something converting from a method to a function:

Here is a function that I wrote to do that. It doesn't do
exactly what you want, but might save you some time.

def spliturl(url):
'''
spliturl - method to split composite url into its component parts
ftp://username:p[email protected]/dav

gets split into:

scheme.............ftp
domain.............www.domain.com
username...........username
password...........password
rootfolder........./dav
port...............None

returns list of 6 strings/None containing above listed variables
'''
parts=urlparse.urlsplit(url)
scheme=parts[0]
usernameandpassword, domain=urllib.splituser(parts[1])
username, password=urllib.splitpasswd(usernameandpassword)
rootfolder, port=urllib.splitport(parts[2])
if port is not None: port=int(port)
return [scheme, domain, username, password, rootfolder, port]

-Larry Bates
 
J

John J. Lee

metaperl said:
The urlparse with Python 2.4.3 includes the user and pass in the site
aspect of its parse:

'bill:[email protected]'


I personally would prefer that it be broken down a bit further. What
are existing opinions on this?

Module urlparse should be deprecated in Python 2.6, to be replaced
with a new module (or modules) that implements the relevant parts of
RFC 3986 and 3987 (read the python-dev archives for discussion and
several people's first cuts at implementation).

Splitting "userinfo" (the bit before the '@' in
user:p[email protected]) should be a separate function. Mostly because
RFC 3986 talks a lot about 5-tuples into which ANY URL can be split,
and that splitting process doesn't involve splitting out userinfo. So
it makes sense to have one function do the splitting into RFC 3986
5-tuples, and another split out the userinfo. Also, though, the
userinfo syntax is deprecated, because people use it for semantic
spoofing attacks: people don't understand (or don't notice) that

http://microsoft.com&rhubarb=custard&[email protected]/more/stuff.htm

is not a microsoft.com URL. Note that userinfo has always been
illegal in HTTP URLs, and is no longer supported by newer browsers.
So relegating it to a separate function is a good thing, IMO.


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top