Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 43276c02d5
Fetching contributors…

Cannot retrieve contributors at this time

18 lines (15 sloc) 0.562 kb
# -*- coding: utf-8 -*-
import re
class StripWhitespace(object):
"""
Strips leading and trailing whitespace from response content.
"""
NEWLINE_RE = re.compile(r'>\s*\n\s*<')
SPACES_RE = re.compile(r'>\s{2,}<')
def process_response(self, request, response):
if response['Content-Type'].startswith('text/html'):
content = response.content
content = self.NEWLINE_RE.sub('>\n<', content)
content = self.SPACES_RE.sub('> <', content)
response.content = content
return response
Jump to Line
Something went wrong with that request. Please try again.