Skip to content

Commit

Permalink
changes recommended by pylint and pypi. Added include files. Moved te…
Browse files Browse the repository at this point in the history
…st directory
  • Loading branch information
Tim Parkin committed Jan 6, 2009
1 parent da1c4b2 commit 329a94f
Show file tree
Hide file tree
Showing 25 changed files with 427 additions and 31 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Tim Parkin
Matt Goodall
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
==========
Changlelog
==========


0.5 (2009-01-05)
----------------

NOTE: First External Release
4 changes: 4 additions & 0 deletions FAQ
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
***
FAQ
***

29 changes: 29 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
==========
Installing
==========

Requirements
------------

You will need:

* python 2.4 or later.

* decorator module
http://pypi.python.org/pypi/decorator/3.0.0

* webob module
http://pythonpaste.org/webob/

Installation
------------

If you have easy_install, you can run the following

easy_install restish

This will also bring in all of the requirements.




5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
====
NEWS
====

2009-01-05 - Project website launched at http://ish.io
3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
See docs/html/index.html

For installation information, see INSTALL
3 changes: 3 additions & 0 deletions restish/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Restish module
"""
11 changes: 8 additions & 3 deletions restish/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Core wsgi application
"""
from restish import error, http


Expand All @@ -21,9 +24,11 @@ def __call__(self, environ, start_response):
return response.app_iter

def locate_resource(self, request):
# Calculate the path segments relative to the application,
# special-casing requests for the the root segment (because we already
# have a reference to the root resource).
"""
Calculate the path segments relative to the application,
special-casing requests for the the root segment (because we already
have a reference to the root resource).
"""
segments = request.path_url.path_segments[len(request.application_url.path_segments):]
if segments == ['']:
segments = []
Expand Down
1 change: 1 addition & 0 deletions restish/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ def __init__(self, *args, **kwargs):
self.kwargs = kwargs

def make_response(self):
""" generate http exception """
return self.response_factory(*self.args, **self.kwargs)

19 changes: 16 additions & 3 deletions restish/guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def guard(*checkers, **kwargs):
raise TypeError('guard() got unexpected keyword arguments %r' % ('.'.join(kwargs),))

def call(func, obj, request, *a, **k):
""" Iterate checkers accumulating errors """
errors = _run_guard_checkers(checkers, request, obj, error_handler)
if errors:
return error_handler(request, obj, errors)
Expand All @@ -67,25 +68,34 @@ def __init__(self, resource, *checkers, **kwargs):
# args so we'll have to handle it ourselves for now.
error_handler = kwargs.pop('error_handler', _default_error_handler)
if kwargs:
raise TypeError('guard() got unexpected keyword arguments %r' % ('.'.join(kwargs),))
raise TypeError('guard() got unexpected' \
' keyword arguments %r' % ('.'.join(kwargs),))
self.resource = resource
self.checkers = checkers
self.error_handler = error_handler

def resource_child(self, request, segments):
errors = _run_guard_checkers(self.checkers, request, self.resource, self.error_handler)
"""
Check the guard methods and raise error handler if errors
"""
errors = _run_guard_checkers(self.checkers, request, \
self.resource, self.error_handler)
if errors:
return self.error_handler(request, self.resource, errors)
return self.resource.resource_child(request, segments)

def __call__(self, request):
errors = _run_guard_checkers(self.checkers, request, self.resource, self.error_handler)
errors = _run_guard_checkers(self.checkers, request, \
self.resource, self.error_handler)
if errors:
return self.error_handler(request, self.resource, errors)
return self.resource(request)


def _run_guard_checkers(checkers, request, obj, error_handler):
"""
Iterate through the checks, accumulating errors
"""
errors = []
for checker in checkers:
try:
Expand All @@ -96,6 +106,9 @@ def _run_guard_checkers(checkers, request, obj, error_handler):


def _default_error_handler(request, obj, errors):
"""
Standard error handler produced unauthorized http response
"""
errors_text = '\n'.join(errors)
raise http.UnauthorizedError(
[('Content-Type', 'text/plain')],
Expand Down
Loading

0 comments on commit 329a94f

Please sign in to comment.