Changes between Version 9 and Version 10 of StripWhitespaceMiddleware
- Timestamp:
- May 28, 2012, 3:40:32 AM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
StripWhitespaceMiddleware
v9 v10 19 19 import re 20 20 21 class StripWhitespaceMiddleware :21 class StripWhitespaceMiddleware(object): 22 22 """ 23 23 Strips leading and trailing whitespace from response content. … … 26 26 def __init__(self): 27 27 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) 30 30 31 31 32 32 def process_response(self, request, response): 33 33 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) 36 38 # Uncomment the next line to remove empty lines 37 # new_content = self.whitespace.sub('', new_content)38 response.content = new_content39 if hasattr(self, 'whitespace'): 40 response.content = self.whitespace.sub('', response.content) 39 41 return response 40 42 else: 41 return response 43 return response 42 44 43 45 }}}