OoO En cette  soirée bien amorcée du mardi 29  janvier 2008, vers 22:23,
Eric Evans <[EMAIL PROTECTED]> disait:

> There are some parsing functions in urllib and urlparse but none of them
> seemed to provide for a very clean solution.

> The attached patch should correctly parse urls with or without a
> username/password pair as well as setting up the appropriate header for
> proxy basic auth.

> Again, I don't have a ready means of testing this. I've made sure that
> it's parsing the url and setting the instance attributes correctly, and
> that it doesn't effect normal usage of boto. If you could apply the
> patch and let me know how it works for you, it would be appreciated.

Hi Eric !

I have tested your patch:
 - without http_proxy: OK
 - with empty http_proxy: OK
 - without password: OK
 - with password: OK

> +            pattern = re.compile(
> +                '(?:http://)?' \
> +                '(?:(?P<user>\w+):(?P<pass>\w+)@)?' \
> +                '(?P<host>[\w\-\.]+)' \
> +                '(?::(?P<port>\d+))?'

I think  that \w  is too  restrictive for password.  I can  have special
characters in  password. I would suggest  [EMAIL PROTECTED] instead of  \w+. It 
will
catch:
 http://user:[EMAIL PROTECTED]:3128

Well, in fact, you are better with .+ because you can catch:
 http://user:[EMAIL PROTECTED]@localhost:3128

As  long that  there  is '@'  in  the string,  we  have a  user/password
scheme. And '@' cannot appear in the  hostname or in the port, so we are
safe. Since password can be empty, I would suggest .* :

           pattern = re.compile(
               '(?:http://)?' \
               '(?:(?P<user>\w+):(?P<pass>.*)@)?' \
               '(?P<host>[\w\-\.]+)' \
               '(?::(?P<port>\d+))?'

Thanks for your patch !
-- 
BOFH excuse #231:
We had to turn off that service to comply with the CDA Bill.


Reply via email to