Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
conlin-huang committed Mar 22, 2023
1 parent 69c520a commit 9d15081
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions aioscrapy/core/downloader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,38 +180,37 @@ async def _process_queue(self, slot: Slot) -> None:
break

async def _download(self, slot: Slot, request: Request) -> None:
response = None
result = None
try:
if self.dupefilter and not request.dont_filter and await self.dupefilter.exist_fingerprint(request):
self.dupefilter.log(request, self.spider)
return
slot.lastseen = time()
response = await self.middleware.process_request(self.spider, request)
if response is None:
request = response or request
result = await self.middleware.process_request(self.spider, request)
if result is None:
self.proxy and await self.proxy.add_proxy(request)
response = await self.handler.download_request(request, self.spider)
result = await self.handler.download_request(request, self.spider)
except BaseException as exc:
self.proxy and self.proxy.check(request, exception=exc)
response = await self.middleware.process_exception(self.spider, request, exc)
result = await self.middleware.process_exception(self.spider, request, exc)
else:
if isinstance(response, Response):
if isinstance(result, Response):
try:
self.proxy and self.proxy.check(request, response=response)
response = await self.middleware.process_response(self.spider, request, response)
self.proxy and self.proxy.check(request, response=result)
result = await self.middleware.process_response(self.spider, request, result)
except BaseException as exc:
response = exc
result = exc
finally:
slot.transferring.remove(request)
slot.active.remove(request)
self.active.remove(request)
if isinstance(response, Response):
if isinstance(result, Response):
self.dupefilter and not request.dont_filter and await self.dupefilter.add_fingerprint(request)
await self.signals.send_catch_log(signal=signals.response_downloaded,
response=response,
response=result,
request=request,
spider=self.spider)
await self._call_engine(response, request)
await self._call_engine(result, request)
await self._process_queue(slot)

async def close(self) -> None:
Expand Down

0 comments on commit 9d15081

Please sign in to comment.