Ticket #1569: 1569.unicode.trunk.diff
File 1569.unicode.trunk.diff, 2.2 KB (added by , 19 years ago) |
---|
-
django/utils/httpwrappers.py
151 151 if not mimetype: 152 152 mimetype = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE, settings.DEFAULT_CHARSET) 153 153 if hasattr(content, '__iter__'): 154 self. iterator = content154 self._iterator = content 155 155 self._is_string = False 156 156 else: 157 self. iterator = [content]157 self._iterator = [content] 158 158 self._is_string = True 159 159 self.headers = {'Content-Type': mimetype} 160 160 self.cookies = SimpleCookie() … … 200 200 pass 201 201 202 202 def _get_content(self): 203 content = ''.join(self. iterator)203 content = ''.join(self._iterator) 204 204 if isinstance(content, unicode): 205 205 content = content.encode(self._charset) 206 206 return content 207 207 208 208 def _set_content(self, value): 209 self. iterator = [value]209 self._iterator = [value] 210 210 self._is_string = True 211 211 212 212 content = property(_get_content, _set_content) 213 213 214 def _get_iterator(self): 215 "Output iterator. Converts data into client charset if necessary." 216 for chunk in self._iterator: 217 if isinstance(chunk, unicode): 218 chunk = chunk.encode(self._charset) 219 yield chunk 220 221 iterator = property(_get_iterator) 222 214 223 # The remaining methods partially implement the file-like object interface. 215 224 # See http://docs.python.org/lib/bltin-file-objects.html 216 225 def write(self, content): 217 226 if not self._is_string: 218 227 raise Exception, "This %s instance is not writable" % self.__class__ 219 self. iterator.append(content)228 self._iterator.append(content) 220 229 221 230 def flush(self): 222 231 pass … … 224 233 def tell(self): 225 234 if not self._is_string: 226 235 raise Exception, "This %s instance cannot tell its position" % self.__class__ 227 return sum([len(chunk) for chunk in self. iterator])236 return sum([len(chunk) for chunk in self._iterator]) 228 237 229 238 class HttpResponseRedirect(HttpResponse): 230 239 def __init__(self, redirect_to):