#3 Merged
mizhi mizhi
bbangert bbangert

Fix for unicode problems.

  1. Mitchell Peabody avatarMitchell Peabody

This fix forces the template function to consistently return unicode strings instead of unicode and str strings. Views that use the template function can thus consistently set the Response.text property without type error.

Background pip installs WebOb 1.2.3 as a supporting package for Dozer. So, I was using WebOb 1.2.3 when I sent you the pull request. It also appears that there are other places in the source where this switch from Response.body to Response.text is needed (the tree function for example). Looking a bit closer at some of the WebOb code, what's going on is the the default behavior for Response.init is to set the content type to utf-8. When the template (in leak.py) function returns, the type is sometimes unicode and sometimes str. You can verify this by comparing the type returned from applying the template function to graphs.html (Dozer.index) and the type return from applying the template function to trace.html (Dozer.trace).

The set method for Response.body detects if the content-type is binary or not and if it isn't, checks what the type the new value is and raises the TypeError if it's of a "text_type" which is defined in compat.py to be unicode for python versions < 3.

template was returning both str and unicode responses. When it's an str return, then setting Response.body works, but not Response.text. When it's a unicode return, then setting Response.text works, but not Response.body. So either there needs to be consistency in the return of the template function, a check needs to be made to set the appropriate response field, or a conversion to unicode when Response.text is set.

Comments (1)

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.