pep8 fixes.

This commit is contained in:
Alejandro Cabrera
2013-01-05 15:38:02 -05:00
parent fa0a5decd3
commit 930b262fb0
9 changed files with 22 additions and 8 deletions

View File

@@ -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]

View File

@@ -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)

View File

@@ -1,4 +1,5 @@
from status_codes import *
def path_not_found_handler(ctx, req, resp):
resp.status = HTTP_404

View File

@@ -25,4 +25,3 @@ class Request:
return headers[name.upper()]
except KeyError as e:
return default

View File

@@ -1,4 +1,5 @@
def application(environ, start_response):
start_response("200 OK", [
('Content-Type', 'text/plain')])

View File

@@ -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",

View File

@@ -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)

View File

@@ -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!"

View File

@@ -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):