should urlparse return user and pass in separate components?

Larry Bates larry.bates at websafe.com
Thu Sep 7 19:05:06 EDT 2006


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:password@www.domain.com/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

metaperl wrote:
> The urlparse with Python 2.4.3 includes the user and pass in the site
> aspect of its parse:
> 
>>>> scheme, site, path, parms, query, fid = urlparse.urlparse("http://bill:james@docs.python.org/lib/module-urlparse.html")
> 
>>>> site
> 'bill:james at docs.python.org'
> 
> 
> I personally would prefer that it be broken down a bit further. What
> are existing opinions on this?
> 



More information about the Python-list mailing list