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.""" """A fast micro-framework for building cloud APIs."""
version_tuple = (0, 0, 1, '-dev') version_tuple = (0, 0, 1, '-dev')
def get_version_string(): def get_version_string():
if isinstance(version_tuple[-1], basestring): if isinstance(version_tuple[-1], basestring):
return '.'.join(map(str, version_tuple[:-1])) + version_tuple[-1] return '.'.join(map(str, version_tuple[:-1])) + version_tuple[-1]

View File

@@ -9,6 +9,7 @@ from falcon.status_codes import *
# TODO: __slots__ # TODO: __slots__
# TODO: log exceptions, trace execution, etc. # TODO: log exceptions, trace execution, etc.
class Api: class Api:
"""Provides routing and such for building a web service application""" """Provides routing and such for building a web service application"""
@@ -54,7 +55,6 @@ class Api:
# Ignore body based on status code # Ignore body based on status code
return [] return []
def add_route(self, uri_template, handler): def add_route(self, uri_template, handler):
if not hasattr(handler, '__call__'): if not hasattr(handler, '__call__'):
raise TypeError('handler is not callable') 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 = re.sub(r'{([a-zA-Z][a-zA-Z_]*)}', r'(?P<\1>[^/]+)', template)
pattern = r'\A' + pattern + r'\Z' pattern = r'\A' + pattern + r'\Z'
return re.compile(pattern, re.IGNORECASE) return re.compile(pattern, re.IGNORECASE)

View File

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

View File

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

View File

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

View File

@@ -6,6 +6,7 @@ import testtools
import falcon import falcon
class RandChars: class RandChars:
_chars = 'abcdefghijklqmnopqrstuvwxyz0123456789 \n\t!@#$%^&*()-_=+`~<>,.?/' _chars = 'abcdefghijklqmnopqrstuvwxyz0123456789 \n\t!@#$%^&*()-_=+`~<>,.?/'
@@ -19,13 +20,15 @@ class RandChars:
def next(self): def next(self):
if self.counter < self.target: if self.counter < self.target:
self.counter += 1 self.counter += 1
return self._chars[random.randint(0, len(self._chars)-1)] return self._chars[random.randint(0, len(self._chars) - 1)]
else: else:
raise StopIteration raise StopIteration
def rand_string(min, max): def rand_string(min, max):
return ''.join([c for c in RandChars(min, max)]) return ''.join([c for c in RandChars(min, max)])
class StartResponseMock: class StartResponseMock:
def __init__(self): def __init__(self):
self._called = 0 self._called = 0
@@ -41,6 +44,7 @@ class StartResponseMock:
def call_count(self): def call_count(self):
return self._called return self._called
class RequestHandler: class RequestHandler:
sample_status = "200 OK" sample_status = "200 OK"
sample_body = rand_string(0, 128 * 1024) sample_body = rand_string(0, 128 * 1024)
@@ -62,6 +66,7 @@ class RequestHandler:
resp.body = self.sample_body resp.body = self.sample_body
resp.set_headers(self.resp_headers) resp.set_headers(self.resp_headers)
class TestSuite(testtools.TestCase): class TestSuite(testtools.TestCase):
def setUp(self): def setUp(self):
@@ -81,6 +86,7 @@ class TestSuite(testtools.TestCase):
return self.api(create_environ(path=path, **kwargs), return self.api(create_environ(path=path, **kwargs),
self.srmock) self.srmock)
def create_environ(path='/', query_string='', protocol='HTTP/1.1', port='80', def create_environ(path='/', query_string='', protocol='HTTP/1.1', port='80',
headers=None, script='', body=''): headers=None, script='', body=''):
@@ -92,7 +98,8 @@ def create_environ(path='/', query_string='', protocol='HTTP/1.1', port='80',
'PATH_INFO': path, 'PATH_INFO': path,
'QUERY_STRING': query_string, 'QUERY_STRING': query_string,
'HTTP_ACCEPT': '*/*', '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', 'REMOTE_PORT': '65133',
'RAW_URI': '/', 'RAW_URI': '/',
'REMOTE_ADDR': '127.0.0.1', 'REMOTE_ADDR': '127.0.0.1',

View File

@@ -4,6 +4,7 @@ from testtools.matchers import Equals, MatchesRegex, Contains, Not
import falcon import falcon
import test.helpers as helpers import test.helpers as helpers
class RequestHandlerTestStatus: class RequestHandlerTestStatus:
sample_body = helpers.rand_string(0, 128 * 1024) sample_body = helpers.rand_string(0, 128 * 1024)

View File

@@ -4,6 +4,7 @@ from testtools.matchers import Equals, MatchesRegex
import falcon import falcon
import helpers import helpers
class HelloRequestHandler: class HelloRequestHandler:
sample_status = "200 OK" sample_status = "200 OK"
sample_body = "Hello World!" sample_body = "Hello World!"

View File

@@ -2,6 +2,7 @@ import testtools
import test.helpers as helpers import test.helpers as helpers
class TestQueryParams(helpers.TestSuite): class TestQueryParams(helpers.TestSuite):
def prepare(self): def prepare(self):
@@ -40,4 +41,3 @@ class TestQueryParams(helpers.TestSuite):
self.assertEquals(req.get_param('colors'), ['red', 'green', '']) self.assertEquals(req.get_param('colors'), ['red', 'green', ''])
self.assertEquals(req.get_param('limit'), '1') self.assertEquals(req.get_param('limit'), '1')
self.assertEquals(req.get_param('pickle'), None) 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 from falcon.request import Request
import test.helpers as helpers import test.helpers as helpers
class TestReqVars(helpers.TestSuite): class TestReqVars(helpers.TestSuite):
def prepare(self): def prepare(self):
@@ -45,5 +46,3 @@ class TestReqVars(helpers.TestSuite):
def test_http_request_method(self): 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 import helpers
class TestRequestBody(helpers.TestSuite): class TestRequestBody(helpers.TestSuite):
def prepare(self): def prepare(self):
@@ -29,7 +30,7 @@ class TestRequestBody(helpers.TestSuite):
def test_read_body(self): def test_read_body(self):
expected_body = helpers.rand_string(2, 1 * 1024 * 1024) expected_body = helpers.rand_string(2, 1 * 1024 * 1024)
expected_len = len(expected_body) 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) 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)
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 import test.helpers as helpers
class TestUriTemplates(helpers.TestSuite): class TestUriTemplates(helpers.TestSuite):
def prepare(self): def prepare(self):

View File

@@ -4,6 +4,7 @@ from testtools.matchers import Equals, MatchesRegex
import falcon import falcon
import test.helpers as helpers import test.helpers as helpers
def _is_iterable(thing): def _is_iterable(thing):
try: try:
for i in thing: for i in thing:
@@ -13,6 +14,7 @@ def _is_iterable(thing):
except: except:
return False return False
class TestWsgi(testtools.TestCase): class TestWsgi(testtools.TestCase):
def test_pep333(self): def test_pep333(self):