From 930b262fb01b6a83d764499739aaa255df43bda6 Mon Sep 17 00:00:00 2001 From: Alejandro Cabrera Date: Sat, 5 Jan 2013 15:38:02 -0500 Subject: [PATCH 1/2] pep8 fixes. --- falcon/__init__.py | 1 + falcon/api.py | 3 +-- falcon/default_request_handlers.py | 1 + falcon/request.py | 1 - test/dump_wsgi.py | 1 + test/helpers.py | 18 +++++++++++++----- test/test_headers.py | 2 ++ test/test_hello.py | 1 + test/test_wsgi.py | 2 ++ 9 files changed, 22 insertions(+), 8 deletions(-) diff --git a/falcon/__init__.py b/falcon/__init__.py index ede7a7c..d6fc6af 100644 --- a/falcon/__init__.py +++ b/falcon/__init__.py @@ -1,6 +1,7 @@ """A fast micro-framework for building cloud APIs.""" version_tuple = (0, 0, 1, '-dev') + def get_version_string(): if isinstance(version_tuple[-1], basestring): return '.'.join(map(str, version_tuple[:-1])) + version_tuple[-1] diff --git a/falcon/api.py b/falcon/api.py index d7ba10b..0bdca43 100644 --- a/falcon/api.py +++ b/falcon/api.py @@ -7,6 +7,7 @@ from falcon.status_codes import * # TODO: __slots__ # TODO: log exceptions, trace execution, etc. + class Api: """Provides routing and such for building a web service application""" @@ -51,7 +52,6 @@ class Api: # Ignore body based on status code return [] - def add_route(self, uri_template, handler): self.routes[uri_template] = handler pass @@ -74,4 +74,3 @@ class Api: resp.set_header('Content-Length', resp.stream_len) else: resp.set_header('Content-Length', 0) - diff --git a/falcon/default_request_handlers.py b/falcon/default_request_handlers.py index 7d3510c..5017e1f 100644 --- a/falcon/default_request_handlers.py +++ b/falcon/default_request_handlers.py @@ -1,4 +1,5 @@ from status_codes import * + def path_not_found_handler(ctx, req, resp): resp.status = HTTP_404 diff --git a/falcon/request.py b/falcon/request.py index 1c7c1f5..6b5f2c9 100644 --- a/falcon/request.py +++ b/falcon/request.py @@ -25,4 +25,3 @@ class Request: return headers[name.upper()] except KeyError as e: return default - diff --git a/test/dump_wsgi.py b/test/dump_wsgi.py index e384b84..f5404f0 100644 --- a/test/dump_wsgi.py +++ b/test/dump_wsgi.py @@ -1,4 +1,5 @@ + def application(environ, start_response): start_response("200 OK", [ ('Content-Type', 'text/plain')]) diff --git a/test/helpers.py b/test/helpers.py index a2faefa..472e4a6 100644 --- a/test/helpers.py +++ b/test/helpers.py @@ -5,6 +5,7 @@ import testtools import falcon + class StartResponseMock: def __init__(self): self._called = 0 @@ -20,6 +21,7 @@ class StartResponseMock: def call_count(self): return self._called + class TestSuite(testtools.TestCase): def setUp(self): @@ -33,8 +35,10 @@ class TestSuite(testtools.TestCase): prepare() def _simulate_request(self, path, protocol='HTTP/1.1', headers=None): - return self.api(create_environ(path=path, protocol=protocol, headers=headers), - self.srmock) + return self.api( + create_environ(path=path, protocol=protocol, headers=headers), + self.srmock) + class RandChars: _chars = 'abcdefghijklqmnopqrstuvwxyz0123456789 \n\t!@#$%^&*()-_=+`~<>,.?/' @@ -49,14 +53,17 @@ class RandChars: def next(self): if self.counter < self.target: self.counter += 1 - return self._chars[random.randint(0, len(self._chars)-1)] + return self._chars[random.randint(0, len(self._chars) - 1)] else: raise StopIteration + def rand_string(min, max): return ''.join([c for c in RandChars(min, max)]) -def create_environ(path='/', query_string='', protocol='HTTP/1.1', headers=None): + +def create_environ(path='/', query_string='', + protocol='HTTP/1.1', headers=None): env = { "SERVER_PROTOCOL": protocol, @@ -67,7 +74,8 @@ def create_environ(path='/', query_string='', protocol='HTTP/1.1', headers=None) "PATH_INFO": path, "QUERY_STRING": query_string, "HTTP_ACCEPT": "*/*", - "HTTP_USER_AGENT": "curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5", + "HTTP_USER_AGENT": ("curl/7.24.0 (x86_64-apple-darwin12.0)" + "libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5"), "REMOTE_PORT": "65133", "RAW_URI": "/", "REMOTE_ADDR": "127.0.0.1", diff --git a/test/test_headers.py b/test/test_headers.py index 9dc521a..d819ad8 100644 --- a/test/test_headers.py +++ b/test/test_headers.py @@ -6,6 +6,7 @@ from testtools.matchers import Equals, MatchesRegex, Contains, Not import falcon import test.helpers as helpers + class RequestHandler: sample_status = "200 OK" sample_body = helpers.rand_string(0, 128 * 1024) @@ -27,6 +28,7 @@ class RequestHandler: resp.body = self.sample_body resp.set_headers(self.resp_headers) + class RequestHandlerTestStatus: sample_body = helpers.rand_string(0, 128 * 1024) diff --git a/test/test_hello.py b/test/test_hello.py index 01d0edd..1c17eed 100644 --- a/test/test_hello.py +++ b/test/test_hello.py @@ -4,6 +4,7 @@ from testtools.matchers import Equals, MatchesRegex import falcon import test.helpers as helpers + class HelloRequestHandler: sample_status = "200 OK" sample_body = "Hello World!" diff --git a/test/test_wsgi.py b/test/test_wsgi.py index a4dcc40..166e607 100644 --- a/test/test_wsgi.py +++ b/test/test_wsgi.py @@ -4,6 +4,7 @@ from testtools.matchers import Equals, MatchesRegex import falcon import test.helpers as helpers + def _is_iterable(thing): try: for i in thing: @@ -13,6 +14,7 @@ def _is_iterable(thing): except: return False + class TestWsgi(testtools.TestCase): def test_pep333(self): From 29a69fe4688f38f28f895b4ce105f9468bdb9a7e Mon Sep 17 00:00:00 2001 From: Alejandro Cabrera Date: Mon, 7 Jan 2013 13:06:50 -0500 Subject: [PATCH 2/2] Whitespace in strcat fix. --- test/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/helpers.py b/test/helpers.py index 472e4a6..1ccf508 100644 --- a/test/helpers.py +++ b/test/helpers.py @@ -74,7 +74,7 @@ def create_environ(path='/', query_string='', "PATH_INFO": path, "QUERY_STRING": query_string, "HTTP_ACCEPT": "*/*", - "HTTP_USER_AGENT": ("curl/7.24.0 (x86_64-apple-darwin12.0)" + "HTTP_USER_AGENT": ("curl/7.24.0 (x86_64-apple-darwin12.0) " "libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5"), "REMOTE_PORT": "65133", "RAW_URI": "/",