Ejemplo n.º 1
0
Archivo: tests.py Proyecto: logan/praw
 def test_timeout(self):
     # pylint: disable-msg=W0212
     from socket import timeout
     try:
         helpers._request(self.r, self.r.config['comments'], timeout=0.001)
     except URLError as error:
         self.assertEqual(text_type(error.reason), 'timed out')
     except timeout:
         pass
     else:
         self.fail('Timeout did not raise the proper exception.')
Ejemplo n.º 2
0
    def _request(self, page_url, params=None, url_data=None, timeout=None):
        """
        Given a page url and a dict of params, open and return the page.

        :param page_url: the url to grab content from.
        :param params: a dictionary containing the extra url data to submit
        :param url_data: a dictionary containing the GET data to put in the url
        :returns: the open page
        """
        # pylint: disable-msg=W0212
        timeout = self.config.timeout if timeout is None else timeout
        remaining_attempts = 3
        while True:
            try:
                return helpers._request(self, page_url, params, url_data,
                                        timeout)
            except HTTPError as error:
                remaining_attempts -= 1
                if (error.code not in self.RETRY_CODES
                        or remaining_attempts == 0):
                    raise
            except http_client.IncompleteRead:
                remaining_attempts -= 1
                if remaining_attempts == 0:
                    raise
Ejemplo n.º 3
0
    def _request(self, page_url, params=None, url_data=None, timeout=None,
                 raw=False):
        """
        Given a page url and a dict of params, open and return the page.

        :param page_url: the url to grab content from.
        :param params: a dictionary containing the extra data to submit
        :param url_data: a dictionary containing the GET data to put in the url
        :param raw: return the response object rather than the response body
        :returns: either the response body or the response object
        """
        # pylint: disable-msg=W0212
        timeout = self.config.timeout if timeout is None else timeout
        remaining_attempts = 3
        while True:
            try:
                return helpers._request(self, page_url, url_data, params,
                                        timeout, raw=raw)
            except requests.exceptions.HTTPError as error:
                remaining_attempts -= 1
                if (error.response.status_code not in self.RETRY_CODES or
                    remaining_attempts == 0):
                    raise
            except requests.exceptions.RequestException:
                remaining_attempts -= 1
                if remaining_attempts == 0:
                    raise
Ejemplo n.º 4
0
    def _request(self, page_url, params=None, url_data=None, timeout=None):
        """
        Given a page url and a dict of params, open and return the page.

        :param page_url: the url to grab content from.
        :param params: a dictionary containing the extra url data to submit
        :param url_data: a dictionary containing the GET data to put in the url
        :returns: the open page
        """
        # pylint: disable-msg=W0212
        timeout = self.config.timeout if timeout is None else timeout
        remaining_attempts = 3
        while True:
            try:
                return helpers._request(self, page_url, params,
                                        url_data, timeout)
            except HTTPError as error:
                remaining_attempts -= 1
                if (error.code not in self.RETRY_CODES or
                    remaining_attempts == 0):
                    raise
            except http_client.IncompleteRead:
                remaining_attempts -= 1
                if remaining_attempts == 0:
                    raise