Ticket #6527: 6527-2.diff
File 6527-2.diff, 3.0 KB (added by , 17 years ago) |
---|
-
django/http/__init__.py
257 257 content_type = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE, 258 258 settings.DEFAULT_CHARSET) 259 259 if not isinstance(content, basestring) and hasattr(content, '__iter__'): 260 self._container = content 261 self._is_string = False 260 self._container = [''.join(content) ] 262 261 else: 263 262 self._container = [content] 264 self._is_string = True265 263 self.cookies = SimpleCookie() 266 264 if status: 267 265 self.status_code = status … … 332 330 333 331 def _set_content(self, value): 334 332 self._container = [value] 335 self._is_string = True336 333 337 334 content = property(_get_content, _set_content) 338 335 … … 353 350 # The remaining methods partially implement the file-like object interface. 354 351 # See http://docs.python.org/lib/bltin-file-objects.html 355 352 def write(self, content): 356 if not self._is_string:357 raise Exception, "This %s instance is not writable" % self.__class__358 353 self._container.append(content) 359 354 360 355 def flush(self): 361 356 pass 362 357 363 358 def tell(self): 364 if not self._is_string:365 raise Exception, "This %s instance cannot tell its position" % self.__class__366 359 return sum([len(chunk) for chunk in self._container]) 367 360 368 361 class HttpResponseRedirect(HttpResponse): -
tests/regressiontests/httpwrappers/tests.py
426 426 Traceback (most recent call last): 427 427 ... 428 428 UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format 429 430 ###################################### 431 # HttpResponse with iterable content # 432 ###################################### 433 434 >>> from django.http import HttpResponse 435 >>> response = HttpResponse(file('regressiontests/httpwrappers/helloworld.txt','r')) 436 >>> print response 437 Content-Type: text/html; charset=utf-8 438 <BLANKLINE> 439 Hello world. 440 Hello, world! 441 442 >>> print response 443 Content-Type: text/html; charset=utf-8 444 <BLANKLINE> 445 Hello world. 446 Hello, world! 447 448 >>> print response 449 Content-Type: text/html; charset=utf-8 450 <BLANKLINE> 451 Hello world. 452 Hello, world! 453 >>> response = HttpResponse("abc") 454 >>> print response 455 Content-Type: text/html; charset=utf-8 456 <BLANKLINE> 457 abc 458 >>> print response 459 Content-Type: text/html; charset=utf-8 460 <BLANKLINE> 461 abc 462 >>> print response 463 Content-Type: text/html; charset=utf-8 464 <BLANKLINE> 465 abc 466 429 467 430 468 """ 431 469 -
tests/regressiontests/httpwrappers/helloworld.txt
1 Hello world. 2 Hello, world! 3 No newline at end of file