Merge pull request #1 from cabrera/pep8_fixes

Pep8 Fixes
This commit is contained in:
Kurt Griffiths
2013-01-09 06:41:01 -08:00
13 changed files with 25 additions and 15 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

@@ -9,6 +9,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"""
@@ -54,7 +55,6 @@ class Api:
# Ignore body based on status code
return []
def add_route(self, uri_template, handler):
if not hasattr(handler, '__call__'):
raise TypeError('handler is not callable')
@@ -97,5 +97,3 @@ class Api:
pattern = re.sub(r'{([a-zA-Z][a-zA-Z_]*)}', r'(?P<\1>[^/]+)', template)
pattern = r'\A' + pattern + r'\Z'
return re.compile(pattern, re.IGNORECASE)

View File

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

View File

@@ -2,6 +2,7 @@ import re
QS_PATTERN = re.compile(r'([a-zA-Z_]+)=([^&]+)')
class Request:
__slots__ = (
'app',
@@ -87,5 +88,3 @@ class Request:
return self._params[name]
return default

View File

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

View File

@@ -6,6 +6,7 @@ import testtools
import falcon
class RandChars:
_chars = 'abcdefghijklqmnopqrstuvwxyz0123456789 \n\t!@#$%^&*()-_=+`~<>,.?/'
@@ -19,13 +20,15 @@ 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)])
class StartResponseMock:
def __init__(self):
self._called = 0
@@ -41,6 +44,7 @@ class StartResponseMock:
def call_count(self):
return self._called
class RequestHandler:
sample_status = "200 OK"
sample_body = rand_string(0, 128 * 1024)
@@ -62,6 +66,7 @@ class RequestHandler:
resp.body = self.sample_body
resp.set_headers(self.resp_headers)
class TestSuite(testtools.TestCase):
def setUp(self):
@@ -79,7 +84,8 @@ class TestSuite(testtools.TestCase):
path = '/'
return self.api(create_environ(path=path, **kwargs),
self.srmock)
self.srmock)
def create_environ(path='/', query_string='', protocol='HTTP/1.1', port='80',
headers=None, script='', body=''):
@@ -92,7 +98,8 @@ def create_environ(path='/', query_string='', protocol='HTTP/1.1', port='80',
'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

@@ -4,6 +4,7 @@ from testtools.matchers import Equals, MatchesRegex, Contains, Not
import falcon
import test.helpers as helpers
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 helpers
class HelloRequestHandler:
sample_status = "200 OK"
sample_body = "Hello World!"

View File

@@ -2,6 +2,7 @@ import testtools
import test.helpers as helpers
class TestQueryParams(helpers.TestSuite):
def prepare(self):
@@ -40,4 +41,3 @@ class TestQueryParams(helpers.TestSuite):
self.assertEquals(req.get_param('colors'), ['red', 'green', ''])
self.assertEquals(req.get_param('limit'), '1')
self.assertEquals(req.get_param('pickle'), None)

View File

@@ -4,6 +4,7 @@ from testtools.matchers import Equals, MatchesRegex, Contains, Not
from falcon.request import Request
import test.helpers as helpers
class TestReqVars(helpers.TestSuite):
def prepare(self):
@@ -44,6 +45,4 @@ class TestReqVars(helpers.TestSuite):
Equals('4829'))
def test_http_request_method(self):
self.assertThat(self.req.method, Equals('GET'))
self.assertThat(self.req.method, Equals('GET'))

View File

@@ -2,6 +2,7 @@ import testtools
import helpers
class TestRequestBody(helpers.TestSuite):
def prepare(self):
@@ -29,7 +30,7 @@ class TestRequestBody(helpers.TestSuite):
def test_read_body(self):
expected_body = helpers.rand_string(2, 1 * 1024 * 1024)
expected_len = len(expected_body)
headers = {'Content-Length': str(expected_len) }
headers = {'Content-Length': str(expected_len)}
self._simulate_request('', body=expected_body, headers=headers)
@@ -45,5 +46,3 @@ class TestRequestBody(helpers.TestSuite):
self.assertEquals(stream.tell(), expected_len)
self.assertEquals(stream.tell(), expected_len)

View File

@@ -3,6 +3,7 @@ from testtools.matchers import Equals, Contains, Not
import test.helpers as helpers
class TestUriTemplates(helpers.TestSuite):
def prepare(self):

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