This patch doesn't look correct. The Unicode and str representations would only be identical if all the data was guaranteed to be ASCII and that's not true for the "content" attribute. Plus there should at least be a call to unicode() in there somewhere so that the right type is returned (rather than assuming Python's C layer will correct the problem, which is kind of accidental).
Thinking about the actual problem report, the whole approach looks like it's covering over a different problem: what should the encoding of the content be and how to represent that correctly as UTF-8 (in __str__
) or as Unicode (which is what the __unicode__
method must return)?
More thinking is required here. No question that something is going wrong, but I need to trace through our encoding assumptions so that we can lay down the right rules for how to treat the content. It's not immediately clear that a __unicode__
method is needed, since an HttpResponse is always sent as a sequence of bytes.