Changes between Initial Version and Version 1 of StripWhitespaceMiddleware


Ignore:
Timestamp:
Aug 23, 2006, 12:40:16 AM (18 years ago)
Author:
Gary Wilson <gary.wilson@…>
Comment:

giving this its own page so it can be updated if need be.

Legend:

Unmodified
Added
Removed
Modified
  • StripWhitespaceMiddleware

    v1 v1  
     1= Strip Whitespace Middleware =
     2
     3{{{
     4#!python
     5"""
     6Tightens up response content by removed superflous line breaks and whitespace.
     7By Doug Van Horn
     8"""
     9
     10import re
     11class StripWhitespaceMiddleware:
     12    """
     13    Strips leading and trailing whitespace from response content.
     14    """
     15    def __init__(self):
     16        self.whitespace = re.compile('\s*\n+\s*')
     17
     18    def process_response(self, request, response):
     19        new_content = self.whitespace.sub('\n', response.content)
     20        response.content = new_content
     21        return response
     22}}}
Back to Top