[Python-Dev] [Python-checkins] python/dist/src/Lib urllib.py, 1.169, 1.170

Peter Otten __peter__ at web.de
Sat Sep 10 09:22:59 CEST 2005


Am Samstag, 10. September 2005 04:27 schrieb rhettinger at users.sourceforge.net:

> Update of /cvsroot/python/python/dist/src/Lib
> In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3622
>
> Modified Files:
> 	urllib.py
> Log Message:
> Simplify and speed-up quote_plus().
>
> Index: urllib.py
> ===================================================================
> RCS file: /cvsroot/python/python/dist/src/Lib/urllib.py,v
> retrieving revision 1.169
> retrieving revision 1.170
> diff -u -d -r1.169 -r1.170
> --- urllib.py	9 Sep 2005 22:27:13 -0000	1.169
> +++ urllib.py	10 Sep 2005 02:27:41 -0000	1.170
> @@ -1115,12 +1115,9 @@
>  def quote_plus(s, safe = ''):
>      """Quote the query fragment of a URL; replacing ' ' with '+'"""
>      if ' ' in s:
> -        l = s.split(' ')
> -        for i in range(len(l)):
> -            l[i] = quote(l[i], safe)
> -        return '+'.join(l)
> -    else:
> -        return quote(s, safe)
> +        s = s.replace(' ', '+')
> +        safe += '+'
> +    return quote(s, safe)
>
>  def urlencode(query,doseq=0):
>      """Encode a sequence of two-element tuples or dictionary into a URL
> query string.

You also change the behaviour. Before:

>>> urllib.quote_plus("alpha+beta gamma")
'alpha%2Bbeta+gamma'

After:

>>> urllib.quote_plus("alpha+beta gamma")
'alpha+beta+gamma'

Is that intentional? If so, you also have to update the documentation, which 
currently reads:

quote_plus(string[, safe])

... Plus signs in the original string are escaped unless they are included in 
safe. ...

Peter


More information about the Python-Dev mailing list