Changes between Version 9 and Version 10 of StripWhitespaceMiddleware


Ignore:
Timestamp:
May 28, 2012, 3:40:32 AM (12 years ago)
Author:
anonymous
Comment:

changed for supporting conditional remove

Legend:

Unmodified
Added
Removed
Modified
  • StripWhitespaceMiddleware

    v9 v10  
    1919import re
    2020
    21 class StripWhitespaceMiddleware:
     21class StripWhitespaceMiddleware(object):
    2222    """
    2323    Strips leading and trailing whitespace from response content.
     
    2626    def __init__(self):
    2727        self.whitespace = re.compile('^\s*\n', re.MULTILINE)
    28         self.whitespace_lead = re.compile('^\s+', re.MULTILINE)
    29         self.whitespace_trail = re.compile('\s+$', re.MULTILINE)
     28        # self.whitespace_lead = re.compile('^\s+', re.MULTILINE)
     29        # self.whitespace_trail = re.compile('\s+$', re.MULTILINE)
    3030
    3131
    3232    def process_response(self, request, response):
    3333        if "text" in response['Content-Type']:
    34             new_content = self.whitespace_lead.sub('', response.content)
    35             new_content = self.whitespace_trail.sub('\n', new_content)
     34            if hasattr(self, 'whitespace_lead'):
     35                response.content = self.whitespace_lead.sub('', response.content)
     36            if hasattr(self, 'whitespace_trail'):
     37                response.content = self.whitespace_trail.sub('\n', response.content)
    3638            # Uncomment the next line to remove empty lines
    37             # new_content = self.whitespace.sub('', new_content)
    38             response.content = new_content
     39            if hasattr(self, 'whitespace'):
     40                response.content = self.whitespace.sub('', response.content)
    3941            return response
    4042        else:
    41             return response
     43            return response   
    4244
    4345}}}
Back to Top