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