Commits

Gael Pasgrimaud committed f8be909

pep8

  • Participants
  • Parent commits 1b96f74

Comments (0)

Files changed (6)

 class NoDefault(object):
     pass
 
-try:
-    sorted
-except NameError:
-    def sorted(l):
-        l = list(l)
-        l.sort()
-        return l
-
 
 class AppError(Exception):
     pass
         if hasattr(params, 'items'):
             params = urlencode(params.items(), doseq=True)
         if upload_files or \
-                (content_type and to_string(content_type).startswith('multipart')):
+            (content_type and to_string(content_type).startswith('multipart')):
             params = cgi.parse_qsl(params, keep_blank_values=True)
             content_type, params = self.encode_multipart(
                 params, upload_files or ())

webtest/compat.py

         l = [e for e in l]
         return sep.join(l)
 
+
 def print_stderr(value):
     if PY3:
         exec('print(value, file=sys.stderr)')

webtest/debugapp.py

         return [to_bytes('')]
     return [body]
 
+
 def make_debug_app(global_conf):
     """
     An application that displays the request environment, and does
-# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
-# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
-# Also licenced under the Apache License, 2.0: http://opensource.org/licenses/apache2.0.php
-# Licensed to PSF under a Contributor Agreement
+# (c) 2005 Ian Bicking and contributors; written for Paste
+# (http://pythonpaste.org)
+# Licensed under the MIT license:
+# http://www.opensource.org/licenses/mit-license.php Also licenced under the
+# Apache License, 2.0: http://opensource.org/licenses/apache2.0.php Licensed to
+# PSF under a Contributor Agreement
 """
 Middleware to check for obedience to the WSGI specification.
 
 header_re = re.compile(r'^[a-zA-Z][a-zA-Z0-9\-_]*$')
 bad_header_value_re = re.compile(r'[\000-\037]')
 
+
 class WSGIWarning(Warning):
     """
     Raised in response to WSGI-spec-related warnings
     """
 
+
 def middleware(application, global_conf=None):
 
     """
 
     return lint_app
 
+
 class InputWrapper(object):
 
     def __init__(self, wsgi_input):
     def close(self):
         assert 0, "input.close() must not be called"
 
+
 class ErrorWrapper(object):
 
     def __init__(self, wsgi_errors):
     def close(self):
         assert 0, "errors.close() must not be called"
 
+
 class WriteWrapper(object):
 
     def __init__(self, wsgi_writer):
         assert type(s) is type("")
         self.writer(s)
 
+
 class PartialIteratorWrapper(object):
 
     def __init__(self, wsgi_iterator):
         # We want to make sure __iter__ is called
         return IteratorWrapper(self.iterator)
 
+
 class IteratorWrapper(object):
 
     def __init__(self, wsgi_iterator, check_start_response):
             v = self.iterator.next()
         if self.check_start_response is not None:
             assert self.check_start_response, (
-                "The application returns and we started iterating over its body, but start_response has not yet been called")
+                "The application returns and we started iterating over its"
+                " body, but start_response has not yet been called")
             self.check_start_response = None
         assert isinstance(v, str), (
             "Iterator %r returned a non-str object: %r"
         assert self.closed, (
             "Iterator garbage collected without being closed")
 
+
 def check_environ(environ):
     assert type(environ) is dict, (
         "Environment is not of the right type: %r (environment: %r)"
 
     # @@: these need filling out:
     if environ['REQUEST_METHOD'] not in (
-        'GET', 'HEAD', 'POST', 'OPTIONS','PUT','DELETE','TRACE'):
+        'GET', 'HEAD', 'POST', 'OPTIONS', 'PUT', 'DELETE', 'TRACE'):
         warnings.warn(
             "Unknown REQUEST_METHOD: %r" % environ['REQUEST_METHOD'],
             WSGIWarning)
         "SCRIPT_NAME cannot be '/'; it should instead be '', and "
         "PATH_INFO should be '/'")
 
+
 def check_input(wsgi_input):
     for attr in ['read', 'readline', 'readlines', '__iter__']:
         assert hasattr(wsgi_input, attr), (
             "wsgi.input (%r) doesn't have the attribute %s"
             % (wsgi_input, attr))
 
+
 def check_errors(wsgi_errors):
     for attr in ['flush', 'write', 'writelines']:
         assert hasattr(wsgi_errors, attr), (
             "wsgi.errors (%r) doesn't have the attribute %s"
             % (wsgi_errors, attr))
 
+
 def check_status(status):
     assert type(status) is str, (
         "Status must be a string (not %r)" % status)
             "followed by a single space and a status explanation"
             % status, WSGIWarning)
 
+
 def check_headers(headers):
     assert type(headers) is list, (
         "Headers (%r) must be of type list: %r"
             "Bad header value: %r (bad char: %r)"
             % (value, bad_header_value_re.search(value).group(0)))
 
+
 def check_content_type(status, headers):
     code = int(status.split(None, 1)[0])
     # @@: need one more person to verify this interpretation of RFC 2616
     if code not in NO_MESSAGE_BODY:
         assert 0, "No Content-Type header found in headers (%s)" % headers
 
+
 def check_exc_info(exc_info):
     assert exc_info is None or type(exc_info) is type(()), (
         "exc_info (%r) is not a tuple: %r" % (exc_info, type(exc_info)))
     # More exc_info checks?
 
+
 def check_iterator(iterator):
     # Technically a string is legal, which is why it's a really bad
     # idea, because it may cause the response to be returned
         "You should not return a string as your application iterator, "
         "instead return a single-item list containing that string.")
 
+
 def make_middleware(application, global_conf):
     # @@: global_conf should be taken out of the middleware function,
     # and isolated here
-# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
-# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
-# Also licenced under the Apache License, 2.0: http://opensource.org/licenses/apache2.0.php
-# Licensed to PSF under a Contributor Agreement
+# (c) 2005 Ian Bicking and contributors; written for Paste
+# (http://pythonpaste.org)
+# Licensed under the MIT license:
+# http://www.opensource.org/licenses/mit-license.php Also licenced under the
+# Apache License, 2.0: http://opensource.org/licenses/apache2.0.php Licensed to
+# PSF under a Contributor Agreement
 """
 Middleware to check for obedience to the WSGI specification.
 
 
 METADATA_TYPE = (str, bytes)
 
+
 class WSGIWarning(Warning):
     """
     Raised in response to WSGI-spec-related warnings
     """
 
+
 def middleware(application, global_conf=None):
 
     """
 
     return lint_app
 
+
 class InputWrapper(object):
 
     def __init__(self, wsgi_input):
     def close(self):
         assert 0, "input.close() must not be called"
 
+
 class ErrorWrapper(object):
 
     def __init__(self, wsgi_errors):
     def close(self):
         assert 0, "errors.close() must not be called"
 
+
 class WriteWrapper(object):
 
     def __init__(self, wsgi_writer):
         assert type(s) is bytes
         self.writer(s)
 
+
 class PartialIteratorWrapper(object):
 
     def __init__(self, wsgi_iterator):
         # We want to make sure __iter__ is called
         return IteratorWrapper(self.iterator)
 
+
 class IteratorWrapper(object):
 
     def __init__(self, wsgi_iterator, check_start_response):
             v = self.iterator.next()
         if self.check_start_response is not None:
             assert self.check_start_response, (
-                "The application returns and we started iterating over its body, but start_response has not yet been called")
+                "The application returns and we started iterating over its"
+                " body, but start_response has not yet been called")
             self.check_start_response = None
         assert isinstance(v, bytes), (
             "Iterator %r returned a non-%r object: %r"
         assert self.closed, (
             "Iterator garbage collected without being closed")
 
+
 def check_environ(environ):
     assert type(environ) is dict, (
         "Environment is not of the right type: %r (environment: %r)"
 
     # @@: these need filling out:
     if environ['REQUEST_METHOD'] not in (
-        'GET', 'HEAD', 'POST', 'OPTIONS','PUT','DELETE','TRACE'):
+        'GET', 'HEAD', 'POST', 'OPTIONS', 'PUT', 'DELETE', 'TRACE'):
         warnings.warn(
             "Unknown REQUEST_METHOD: %r" % environ['REQUEST_METHOD'],
             WSGIWarning)
         "SCRIPT_NAME cannot be '/'; it should instead be '', and "
         "PATH_INFO should be '/'")
 
+
 def check_input(wsgi_input):
     for attr in ['read', 'readline', 'readlines', '__iter__']:
         assert hasattr(wsgi_input, attr), (
             "wsgi.input (%r) doesn't have the attribute %s"
             % (wsgi_input, attr))
 
+
 def check_errors(wsgi_errors):
     for attr in ['flush', 'write', 'writelines']:
         assert hasattr(wsgi_errors, attr), (
             "wsgi.errors (%r) doesn't have the attribute %s"
             % (wsgi_errors, attr))
 
+
 def check_status(status):
-    assert type(status) in METADATA_TYPE , (
+    assert type(status) in METADATA_TYPE, (
         "Status must be a %s (not %r)" % (METADATA_TYPE, status))
     # Implicitly check that we can turn it into an integer:
     status_code = status.split(None, 1)[0]
             "followed by a single space and a status explanation"
             % status, WSGIWarning)
 
+
 def check_headers(headers):
     assert type(headers) is list, (
         "Headers (%r) must be of type list: %r"
             "Bad header value: %r (bad char: %r)"
             % (str_value, bad_header_value_re.search(str_value).group(0)))
 
+
 def check_content_type(status, headers):
     code = int(status.split(None, 1)[0])
     # @@: need one more person to verify this interpretation of RFC 2616
     if code not in NO_MESSAGE_BODY:
         assert 0, "No Content-Type header found in headers (%s)" % headers
 
+
 def check_exc_info(exc_info):
     assert exc_info is None or type(exc_info) is tuple, (
         "exc_info (%r) is not a tuple: %r" % (exc_info, type(exc_info)))
     # More exc_info checks?
 
+
 def check_iterator(iterator):
     # Technically a bytes is legal, which is why it's a really bad
     # idea, because it may cause the response to be returned
         "You should not return a string as your application iterator, "
         "instead return a single-item list containing bytes.")
 
+
 def make_middleware(application, global_conf):
     # @@: global_conf should be taken out of the middleware function,
     # and isolated here
 
     """
 
-
     def __init__(self):
         self.host = os.environ.get('SELENIUM_HOST', '127.0.0.1')
         self.port = int(os.environ.get('SELENIUM_POST', 4444))
 
     def __getattr__(self, attr):
         cmd = _get_command(attr)
+
         def wrapped(*args):
             args = [cmd] + [str(a) for a in args]
             return self.execute(*args)
+
         wrapped.__name__ = attr
         return wrapped
 
 
-
 ##############
 # Webtest API
 ##############
 
     def __getattr__(self, attr):
         cmd = _get_command(attr)
+
         def wrapped(*args):
             args = [cmd, self.locator] + [str(a) for a in args]
             return self.browser.execute(*args)
         wrapped.__name__ = attr
+
         return wrapped
 
     def wait(self, timeout=3000):
 # Misc
 ###############
 
+
 def _get_value(s):
     if json:
         return json.dumps(s)
                     return True
             return False
     return True
-