Changeset 2641
- Timestamp:
- 04/09/06 19:05:05 (3 years ago)
- Files:
-
- django/branches/magic-removal/AUTHORS (modified) (2 diffs)
- django/branches/magic-removal/django/core/handlers/modpython.py (modified) (1 diff)
- django/branches/magic-removal/django/core/handlers/wsgi.py (modified) (1 diff)
- django/branches/magic-removal/django/http/__init__.py (modified) (3 diffs)
- django/branches/magic-removal/django/middleware/common.py (modified) (1 diff)
- django/branches/magic-removal/django/utils/cache.py (modified) (1 diff)
- django/branches/magic-removal/docs/request_response.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/AUTHORS
r2549 r2641 75 75 limodou 76 76 Martin Maney <http://www.chipy.org/Martin_Maney> 77 Maniac <http://www.softwaremaniacs.org/>78 77 Manuzhai 79 78 Petar Marić … … 97 96 Brian Ray <http://brianray.chipy.org/> 98 97 Oliver Rutherfurd <http://rutherfurd.net/> 98 Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/> 99 99 David Schein 100 100 sopel django/branches/magic-removal/django/core/handlers/modpython.py
r2631 r2641 150 150 mod_python_req.headers_out.add('Set-Cookie', c.output(header='')) 151 151 mod_python_req.status = http_response.status_code 152 mod_python_req.write(http_response.get_content_as_string(settings.DEFAULT_CHARSET)) 152 for chunk in http_response.iterator: 153 mod_python_req.write(chunk) 153 154 154 155 def handler(req): django/branches/magic-removal/django/core/handlers/wsgi.py
r2490 r2641 160 160 for c in response.cookies.values(): 161 161 response_headers.append(('Set-Cookie', c.output(header=''))) 162 output = [response.get_content_as_string(settings.DEFAULT_CHARSET)]163 162 start_response(status, response_headers) 164 return output163 return response.iterator django/branches/magic-removal/django/http/__init__.py
r2601 r2641 147 147 return cookiedict 148 148 149 class HttpResponse :149 class HttpResponse(object): 150 150 "A basic HTTP response, with content and dictionary-accessed headers" 151 151 def __init__(self, content='', mimetype=None): 152 from django.conf import settings 153 self._charset = settings.DEFAULT_CHARSET 152 154 if not mimetype: 153 from django.conf import settings154 155 mimetype = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE, settings.DEFAULT_CHARSET) 155 self.content = content 156 self.headers = {'Content-Type':mimetype} 156 if hasattr(content, '__iter__'): 157 self.iterator = content 158 self._is_string = False 159 else: 160 self.iterator = [content] 161 self._is_string = True 162 self.headers = {'Content-Type': mimetype} 157 163 self.cookies = SimpleCookie() 158 164 self.status_code = 200 … … 197 203 pass 198 204 199 def get_content_as_string(self, encoding): 200 """ 201 Returns the content as a string, encoding it from a Unicode object if 202 necessary. 203 """ 204 if isinstance(self.content, unicode): 205 return self.content.encode(encoding) 206 return self.content 205 def _get_content(self): 206 content = ''.join(self.iterator) 207 if isinstance(content, unicode): 208 content = content.encode(self._charset) 209 return content 210 211 def _set_content(self, value): 212 self.iterator = [value] 213 self._is_string = True 214 215 content = property(_get_content, _set_content) 207 216 208 217 # The remaining methods partially implement the file-like object interface. 209 218 # See http://docs.python.org/lib/bltin-file-objects.html 210 219 def write(self, content): 211 self.content += content 220 if not self._is_string: 221 raise Exception, "This %s instance is not writable" % self.__class__ 222 self.iterator.append(content) 212 223 213 224 def flush(self): … … 215 226 216 227 def tell(self): 217 return len(self.content) 228 if not self._is_string: 229 raise Exception, "This %s instance cannot tell its position" % self.__class__ 230 return sum(len(chunk) for chunk in self.iterator) 218 231 219 232 class HttpResponseRedirect(HttpResponse): django/branches/magic-removal/django/middleware/common.py
r2601 r2641 69 69 # Use ETags, if requested. 70 70 if settings.USE_ETAGS: 71 etag = md5.new(response. get_content_as_string(settings.DEFAULT_CHARSET)).hexdigest()71 etag = md5.new(response.content).hexdigest() 72 72 if request.META.get('HTTP_IF_NONE_MATCH') == etag: 73 73 response = http.HttpResponseNotModified() django/branches/magic-removal/django/utils/cache.py
r2602 r2641 75 75 now = datetime.datetime.utcnow() 76 76 if not response.has_header('ETag'): 77 response['ETag'] = md5.new(response. get_content_as_string('utf8')).hexdigest()77 response['ETag'] = md5.new(response.content).hexdigest() 78 78 if not response.has_header('Last-Modified'): 79 79 response['Last-Modified'] = now.strftime('%a, %d %b %Y %H:%M:%S GMT') django/branches/magic-removal/docs/request_response.txt
r2494 r2641 305 305 string) and MIME type. The ``DEFAULT_MIME_TYPE`` is ``"text/html"``. 306 306 307 **New in Django development version:** ``content`` can be an iterator 308 instead of a string. This iterator should return strings, and those strings 309 will be joined together to form the content of the response. 310 307 311 ``__setitem__(header, value)`` 308 312 Sets the given header name to the given value. Both ``header`` and … … 342 346 ``get_content_as_string(encoding)`` 343 347 Returns the content as a Python string, encoding it from a Unicode object 344 if necessary. 348 if necessary. **Removed in Django development version.** 349 350 ``content`` 351 **New in Django development version.** Returns the content as a Python 352 string, encoding it from a Unicode object if necessary. Note this is a 353 property, not a method, so use ``r.content`` instead of ``r.content()``. 345 354 346 355 ``write(content)``, ``flush()`` and ``tell()``
