예제 #1
0
    def handle_pre_response(self, item_session: ItemSession) -> Actions:
        '''Process a response that is starting.'''
        action = self.consult_pre_response_hook(item_session)

        if action == Actions.RETRY:
            item_session.set_status(Status.skipped)
        elif action == Actions.FINISH:
            item_session.set_status(Status.done)
        elif action == Actions.STOP:
            raise HookStop('Script requested immediate stop.')

        return action
예제 #2
0
파일: rule.py 프로젝트: Super-Rad/wpull
    def handle_pre_response(self, item_session: ItemSession) -> Actions:
        '''Process a response that is starting.'''
        action = self.consult_pre_response_hook(item_session)

        if action == Actions.RETRY:
            item_session.set_status(Status.skipped)
        elif action == Actions.FINISH:
            item_session.set_status(Status.done)
        elif action == Actions.STOP:
            raise HookStop('Script requested immediate stop.')

        return action
예제 #3
0
파일: rule.py 프로젝트: Super-Rad/wpull
    def handle_no_document(self, item_session: ItemSession) -> Actions:
        '''Callback for successful responses containing no useful document.

        Returns:
            A value from :class:`.hook.Actions`.
        '''
        self._waiter.reset()

        action = self.handle_response(item_session)

        if action == Actions.NORMAL:
            item_session.set_status(Status.skipped)

        return action
예제 #4
0
    def handle_no_document(self, item_session: ItemSession) -> Actions:
        '''Callback for successful responses containing no useful document.

        Returns:
            A value from :class:`.hook.Actions`.
        '''
        self._waiter.reset()

        action = self.handle_response(item_session)

        if action == Actions.NORMAL:
            item_session.set_status(Status.skipped)

        return action
예제 #5
0
파일: rule.py 프로젝트: Super-Rad/wpull
    def handle_document(self, item_session: ItemSession, filename: str) -> Actions:
        '''Process a successful document response.

        Returns:
            A value from :class:`.hook.Actions`.
        '''
        self._waiter.reset()

        action = self.handle_response(item_session)

        if action == Actions.NORMAL:
            self._statistics.increment(item_session.response.body.size())
            item_session.set_status(Status.done, filename=filename)

        return action
예제 #6
0
파일: rule.py 프로젝트: Super-Rad/wpull
    def handle_response(self, item_session: ItemSession) -> Actions:
        '''Generic handler for a response.

        Returns:
            A value from :class:`.hook.Actions`.
        '''
        action = self.consult_response_hook(item_session)

        if action == Actions.RETRY:
            item_session.set_status(Status.error)
        elif action == Actions.FINISH:
            item_session.set_status(Status.done)
        elif action == Actions.STOP:
            raise HookStop('Script requested immediate stop.')

        return action
예제 #7
0
파일: rule.py 프로젝트: Super-Rad/wpull
    def handle_document_error(self, item_session: ItemSession) -> Actions:
        '''Callback for when the document only describes an server error.

        Returns:
            A value from :class:`.hook.Actions`.
        '''
        self._waiter.increment()

        self._statistics.errors[ServerError] += 1

        action = self.handle_response(item_session)

        if action == Actions.NORMAL:
            item_session.set_status(Status.error)

        return action
예제 #8
0
    def handle_response(self, item_session: ItemSession) -> Actions:
        '''Generic handler for a response.

        Returns:
            A value from :class:`.hook.Actions`.
        '''
        action = self.consult_response_hook(item_session)

        if action == Actions.RETRY:
            item_session.set_status(Status.error)
        elif action == Actions.FINISH:
            item_session.set_status(Status.done)
        elif action == Actions.STOP:
            raise HookStop('Script requested immediate stop.')

        return action
예제 #9
0
    def handle_document_error(self, item_session: ItemSession) -> Actions:
        '''Callback for when the document only describes an server error.

        Returns:
            A value from :class:`.hook.Actions`.
        '''
        self._waiter.increment()

        self._statistics.errors[ServerError] += 1

        action = self.handle_response(item_session)

        if action == Actions.NORMAL:
            item_session.set_status(Status.error)

        return action
예제 #10
0
    def handle_document(self, item_session: ItemSession,
                        filename: str) -> Actions:
        '''Process a successful document response.

        Returns:
            A value from :class:`.hook.Actions`.
        '''
        self._waiter.reset()

        action = self.handle_response(item_session)

        if action == Actions.NORMAL:
            self._statistics.increment(item_session.response.body.size())
            item_session.set_status(Status.done, filename=filename)

        return action
예제 #11
0
    def handle_error(self, item_session: ItemSession,
                     error: BaseException) -> Actions:
        '''Process an error.

        Returns:
            A value from :class:`.hook.Actions`.
        '''
        if not self._ssl_verification and \
                isinstance(error, SSLVerificationError):
            # Change it into a different error since the user doesn't care
            # about verifying certificates
            self._statistics.increment_error(ProtocolError())
        else:
            self._statistics.increment_error(error)

        self._waiter.increment()

        action = self.consult_error_hook(item_session, error)

        if action == Actions.RETRY:
            item_session.set_status(Status.error)
        elif action == Actions.FINISH:
            item_session.set_status(Status.done)
        elif action == Actions.STOP:
            raise HookStop('Script requested immediate stop.')
        elif self._ssl_verification and isinstance(error,
                                                   SSLVerificationError):
            raise
        elif isinstance(error, ConnectionRefused) and \
                not self.retry_connrefused:
            item_session.set_status(Status.skipped)
        elif isinstance(error, DNSNotFound) and \
                not self.retry_dns_error:
            item_session.set_status(Status.skipped)
        else:
            item_session.set_status(Status.error)

        return action
예제 #12
0
파일: rule.py 프로젝트: Super-Rad/wpull
    def handle_error(self, item_session: ItemSession, error: BaseException) -> Actions:
        '''Process an error.

        Returns:
            A value from :class:`.hook.Actions`.
        '''
        if not self._ssl_verification and \
                isinstance(error, SSLVerificationError):
            # Change it into a different error since the user doesn't care
            # about verifying certificates
            self._statistics.increment_error(ProtocolError())
        else:
            self._statistics.increment_error(error)

        self._waiter.increment()

        action = self.consult_error_hook(item_session, error)

        if action == Actions.RETRY:
            item_session.set_status(Status.error)
        elif action == Actions.FINISH:
            item_session.set_status(Status.done)
        elif action == Actions.STOP:
            raise HookStop('Script requested immediate stop.')
        elif self._ssl_verification and isinstance(error, SSLVerificationError):
            raise
        elif isinstance(error, ConnectionRefused) and \
                not self.retry_connrefused:
            item_session.set_status(Status.skipped)
        elif isinstance(error, DNSNotFound) and \
                not self.retry_dns_error:
            item_session.set_status(Status.skipped)
        else:
            item_session.set_status(Status.error)

        return action