#20809: Python 2.7.3 Django 1.5.1 QueryDict.urlencode returns unicode
------------------------------+--------------------
     Reporter:  stargrave@…   |      Owner:  nobody
         Type:  Bug           |     Status:  new
    Component:  Core (Other)  |    Version:  1.5
     Severity:  Normal        |   Keywords:
 Triage Stage:  Unreviewed    |  Has patch:  0
Easy pickings:  0             |      UI/UX:  0
------------------------------+--------------------
 QueryDict's urlencode methods always returns unicode strings:
 {{{
 >>> from django.http.request import QueryDict
 >>> QueryDict('foo=bar').urlencode()
 u'foo=bar'
 }}}
 I suppose it is not expected behaviour at all. Django 1.4.x returns str-s.

 After looking at urlencode's source code, force_bytes should translate all
 unicode-s to str-s. But the problem lies in the very beginning of that
 file in `from __future__ import unicode_literals` that forces ""-s to be
 unicode-s. So anyway '&'.join() will result in u'&'.join(), as '%s=%s' one
 too.
 {{{
 if safe:
     safe = force_bytes(safe, self.encoding)
     encode = lambda k, v: '%s=%s' % ((quote(k, safe), quote(v, safe)))
 else:
     encode = lambda k, v: urlencode({k: v})
 for k, list_ in self.lists():
     k = force_bytes(k, self.encoding)
     output.extend([encode(k, force_bytes(v, self.encoding))
                    for v in list_])
 return '&'.join(output)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/20809>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.f58ce194e248c2c973a1b0daa37d1bb2%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to