Skip to content

Commit

Permalink
update methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jadbin committed Nov 14, 2016
1 parent 90fddee commit 2df0bdf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
9 changes: 3 additions & 6 deletions xpaw/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ async def _handle():
finally:
self._clients.release()

@staticmethod
async def _handle_request(request, middleware):
async def _handle_request(self, request, middleware):
for method in middleware.request_handlers:
res = await method(request)
if not (res is None or isinstance(res, (HttpRequest, HttpResponse))):
Expand All @@ -86,17 +85,15 @@ async def _handle_request(request, middleware):
if res:
return res

@staticmethod
async def _handle_response(request, response, middleware):
async def _handle_response(self, request, response, middleware):
for method in middleware.response_handlers:
res = await method(request, response)
if not (res is None or isinstance(res, HttpRequest)):
raise TypeError("Response handler must return None or HttpRequest, got {0}".format(type(res)))
if res:
return res

@staticmethod
async def _handle_error(request, error, middleware):
async def _handle_error(self, request, error, middleware):
for method in middleware.error_handlers:
res = await method(request, error)
if not (res is None or isinstance(res, HttpRequest)):
Expand Down
16 changes: 6 additions & 10 deletions xpaw/spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,29 @@ def start_requests(self, *, middleware=None):
except Exception as e:
yield e

@staticmethod
def _handle_input(response, middleware):
def _handle_input(self, response, middleware):
for method in middleware.input_handlers:
res = method(response)
if res is not None:
raise TypeError("Input handler must return None, got {0}".format(type(res)))

@classmethod
def _handle_output(cls, response, result, middleware):
def _handle_output(self, response, result, middleware):
for method in middleware.output_handlers:
result = method(response, result)
if not cls._isiterable(result):
if not self._isiterable(result):
raise TypeError("Response handler must return an iterable object, got {0}".format(type(result)))
return result

@staticmethod
def _handle_error(response, error, middleware):
def _handle_error(self, response, error, middleware):
for method in middleware.error_handlers:
res = method(response, error)
if res is not None:
raise TypeError("Exception handler must return None, got {0}".format(type(res)))

@classmethod
def _handle_start_requests(cls, result, middleware):
def _handle_start_requests(self, result, middleware):
for method in middleware.start_requests_handlers:
result = method(result)
if not cls._isiterable(result):
if not self._isiterable(result):
raise TypeError("Start requests handler must return an iterable object, got {0}".format(type(result)))
return result

Expand Down
2 changes: 1 addition & 1 deletion xpaw/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# coding=utf-8

__version__ = "0.5.5a4"
__version__ = "0.5.5a5"

0 comments on commit 2df0bdf

Please sign in to comment.