def fetch(self, uri):
        """
        Executes the fetch action toward a specified URI. This will also
        try to avoid unnecessary calls to the Internet by setting the flag
        `__last_fetched`. If it can not fetch again, it will simply return
        the `raw` data that was previously created by a previous fetch.

        Arguments:

            * uri: the path to be fetched
        """
        # check if we can fetch again
        if self.__last_fetched and not self.raw and \
                time.time() - self.__last_fetched < \
                constants.Settings.FETCH_INTERVAL_SECONDS:
            return self.raw

        headers = {'User-Agent': "%s/%s" % (constants.App.NAME,
                                            constants.App.VERSION)}
        # separate possible querystring data from plain URL
        temp = uri.split('?')
        url = temp[0]
        if len(temp) > 1:  # old style condition for old python compatibility
            data = temp[1]
        else:
            data = None

        self.log(_("Connecting to %s ... (this could take a while)") % uri)

        # execute URL fetch
        req = Request(url, data, headers)
        resp = None
        try:
            resp = urlopen(req)
        except __HOLE__, e:
            raise exception.UrlException(uri,
                _("Fetched URL returned error %d.") % e.code)
        except URLError, e:
            raise exception.UrlException(uri,
                _("Could not fetch URL, because %s") % e.reason)
        else:
            self.__last_fetched = time.time()

            self.raw = resp.read()

            # make sure the content is not binary (eg. image)
            if self.__is_response_binary(self.raw):
                raise exception.UrlException(uri, _("Fetched data is binary."))
        finally:
            if resp:
                resp.close()

        return self.raw
dataset/ETHPy150Open brunobraga/termsaver/termsaverlib/screen/helper/urlfetcher.py/URLFetcherHelperBase.fetch