Code

Changes between Version 7 and Version 8 of StripWhitespaceMiddleware


Ignore:
Timestamp:
05/06/12 07:39:03 (2 years ago)
Author:
waldir
Comment:

add support for removing empty newlines. default behavior unchanged.

Legend:

Unmodified
Added
Removed
Modified
  • StripWhitespaceMiddleware

    v7 v8  
    2525 
    2626    def __init__(self): 
    27         self.whitespace = re.compile('^\s+', re.MULTILINE) 
     27        self.whitespace = re.compile('^\s*\n', re.MULTILINE) 
     28        self.whitespace_lead = re.compile('^\s+', re.MULTILINE) 
    2829        self.whitespace_trail = re.compile('\s+$', re.MULTILINE) 
    2930 
     
    3132    def process_response(self, request, response): 
    3233        if "text" in response['Content-Type']: 
    33             new_content = self.whitespace.sub('', response.content) 
     34            # Uncomment the next line to remove empty lines 
     35            # new_content = self.whitespace.sub('', new_content) 
     36            new_content = self.whitespace_lead.sub('', response.content) 
    3437            new_content = self.whitespace_trail.sub('\n', new_content) 
    3538            response.content = new_content 
     
    3841            return response 
    3942 
    40  
    4143}}}