Django

Code

Changeset 2641

Show
Ignore:
Timestamp:
04/09/06 19:05:05 (3 years ago)
Author:
adrian
Message:

magic-removal: Merged to [2640]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/AUTHORS

    r2549 r2641  
    7575    limodou 
    7676    Martin Maney <http://www.chipy.org/Martin_Maney> 
    77     Maniac <http://www.softwaremaniacs.org/> 
    7877    Manuzhai 
    7978    Petar Marić 
     
    9796    Brian Ray <http://brianray.chipy.org/> 
    9897    Oliver Rutherfurd <http://rutherfurd.net/> 
     98    Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/> 
    9999    David Schein 
    100100    sopel 
  • django/branches/magic-removal/django/core/handlers/modpython.py

    r2631 r2641  
    150150        mod_python_req.headers_out.add('Set-Cookie', c.output(header='')) 
    151151    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) 
    153154 
    154155def handler(req): 
  • django/branches/magic-removal/django/core/handlers/wsgi.py

    r2490 r2641  
    160160        for c in response.cookies.values(): 
    161161            response_headers.append(('Set-Cookie', c.output(header=''))) 
    162         output = [response.get_content_as_string(settings.DEFAULT_CHARSET)] 
    163162        start_response(status, response_headers) 
    164         return output 
     163        return response.iterator 
  • django/branches/magic-removal/django/http/__init__.py

    r2601 r2641  
    147147    return cookiedict 
    148148 
    149 class HttpResponse
     149class HttpResponse(object)
    150150    "A basic HTTP response, with content and dictionary-accessed headers" 
    151151    def __init__(self, content='', mimetype=None): 
     152        from django.conf import settings 
     153        self._charset = settings.DEFAULT_CHARSET 
    152154        if not mimetype: 
    153             from django.conf import settings 
    154155            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} 
    157163        self.cookies = SimpleCookie() 
    158164        self.status_code = 200 
     
    197203            pass 
    198204 
    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) 
    207216 
    208217    # The remaining methods partially implement the file-like object interface. 
    209218    # See http://docs.python.org/lib/bltin-file-objects.html 
    210219    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) 
    212223 
    213224    def flush(self): 
     
    215226 
    216227    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) 
    218231 
    219232class HttpResponseRedirect(HttpResponse): 
  • django/branches/magic-removal/django/middleware/common.py

    r2601 r2641  
    6969        # Use ETags, if requested. 
    7070        if settings.USE_ETAGS: 
    71             etag = md5.new(response.get_content_as_string(settings.DEFAULT_CHARSET)).hexdigest() 
     71            etag = md5.new(response.content).hexdigest() 
    7272            if request.META.get('HTTP_IF_NONE_MATCH') == etag: 
    7373                response = http.HttpResponseNotModified() 
  • django/branches/magic-removal/django/utils/cache.py

    r2602 r2641  
    7575    now = datetime.datetime.utcnow() 
    7676    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() 
    7878    if not response.has_header('Last-Modified'): 
    7979        response['Last-Modified'] = now.strftime('%a, %d %b %Y %H:%M:%S GMT') 
  • django/branches/magic-removal/docs/request_response.txt

    r2494 r2641  
    305305    string) and MIME type. The ``DEFAULT_MIME_TYPE`` is ``"text/html"``. 
    306306 
     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 
    307311``__setitem__(header, value)`` 
    308312    Sets the given header name to the given value. Both ``header`` and 
     
    342346``get_content_as_string(encoding)`` 
    343347    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()``. 
    345354 
    346355``write(content)``, ``flush()`` and ``tell()``