Ian Bicking  committed 9da7b4e

a little pep8 whitespace

  • Participants
  • Parent commits 0d37abf

Comments (0)

Files changed (3)

File webtestrecorder/

 from webtest import TestRequest, TestResponse
 from webob import descriptors
 class Recorder(object):
     def __init__(self, app, file, intercept='/.webtestrecorder',
     return records
 def write_doctest(records, fp, default_host='http://localhost'):
     for req in records:
         write_doctest_item(req, fp, default_host)
 def write_doctest_item(req, fp, default_host='http://localhost'):
     resp = req.response
             fp.write('    %s\n' % line)
 def write_function_unittest(records, fp, func_name='test_app', include_intro=True,
                             indent='', default_host='http://localhost'):
     if include_intro:
         write_function_unittest_item(req, fp, indent + '    ', app_name='app',
 def write_function_unittest_item(req, fp, indent, app_name='app', default_host='http://localhost'):
     resp = req.response
     fp.write('%sassert resp.body == %s\n' % (indent, pyrepr(resp.body, indent)))
     ## FIXME: I could check other things, but what things specifically?
 def fixup_response(req):
     """Make sure the req has a TestResponse response"""
     if not isinstance(req.response, TestResponse):
         req.response = resp
 def internal_note(resp):
     """Returns the internal note, if the response is such a response.
     Otherwise returns None."""
         return resp.body
     return None
 def match_host(hostname, url):
     if not hostname.startswith('http://'):
         if ':' in hostname:
             return match_host('http://localhost', url)
         return url
 def str_method_call(req, resp=None, default_host='http://localhost'):
     """Returns a method call that represents the given request, as
     though you were generating that request with WebTest.
     ## FIXME: not all methods work this way (e.g., there's no app.mkcol()):
     return '.%s(%s)' % (req.method.lower(), params)
 def pyrepr(value, indent=''):
     if isinstance(value, basestring) and '\n' in value:
         v = repr(value)
     '--func-unittest', action='store_true',
     help="Write a functional unittest instead of a doctest")
 def main():
     options, args = parser.parse_args()
     records = get_records(sys.stdin)

File webtestrecorder/

 def parse_apache_log(fp, host='localhost',
                      RequestClass=Request, ResponseClass=Response):
     for line in fp:
     '[%(date)s] "%(REQUEST_METHOD)s %(path)s %(HTTP_PROTOCOL)s" '
     '%(status)s %(size)s "%(HTTP_REFERER)s" "%(HTTP_USER_AGENT)s"')
 def apache_log_line(req, resp):
     d = {}
     for var in ['REMOTE_HOST', 'REMOTE_IDENT', 'REMOTE_USER',
     d['size'] = resp.content_length or '-'
     return line_template % d
 def parse_apache_date(date):
     return datetime.strptime(date.split()[0], '%d/%b/%Y:%H:%M:%S')

File webtestrecorder/

 import httplib
 from wsgiproxy.exactproxy import proxy_exact_request
 def replay_records(records, host=None, methods=None):
     for req in records:
         if host:
         if resp is not None:
             yield req, resp
 def main():
     import sys
     import optparse
     return f
 def run_filters(filters, req):
     for f in filters:
         req = f(req)