Example #1
0
 def log(target):
     if hasattr(target, 'im_class'):
         logger.debug('Calling `%s#%s` in a new thread',
                      target.im_class.__name__,
                      target.__name__)
     else:
         logger.debug('Initializing `%s` in a new thread', target.__name__)
Example #2
0
    def get_with_etag_cache(self, url):
        headers = {}
        cached_response = self.cache.get(url, None)

        if cached_response is not None:
            etag = self.get_etag(cached_response)
            headers['If-None-Match'] = etag

        logger.debug('Headers: %s', headers)

        response = requests.get(url, headers=headers, auth=NullAuth())

        self.log_header(response, 'x-ratelimit-limit')
        self.log_header(response, 'x-ratelimit-remaining')

        if response.status_code == 304:
            logger.info('Using cached response for {}'.format(self.url))
            response = cached_response

        response.raise_for_status()

        return response
Example #3
0
    def get_with_etag_cache(self, url):
        headers = {}
        cached_response = self.cache.get(url, None)

        if cached_response is not None:
            etag = self.get_etag(cached_response)
            headers['If-None-Match'] = etag

        logger.debug('Headers: %s', headers)

        response = requests.get(url, headers=headers, auth=NullAuth())

        self.log_header(response, 'x-ratelimit-limit')
        self.log_header(response, 'x-ratelimit-remaining')

        if response.status_code == 304:
            logger.info('Using cached response for {}'.format(self.url))
            response = cached_response

        response.raise_for_status()

        return response
Example #4
0
 def log_header(self, response, key):
     if key in response.headers:
         logger.debug('%s: %s', key, response.headers[key])
Example #5
0
 def log_header(self, response, key):
     if key in response.headers:
         logger.debug('%s: %s', key, response.headers[key])
Example #6
0
    def get(self):
        logger.debug('Requesting {}'.format(self.url))

        return self.cache_response(self.url,
                                   self.get_with_etag_cache(self.url))
Example #7
0
 def log(target):
     if hasattr(target, 'im_class'):
         logger.debug('Calling `%s#%s` in a new thread',
                      target.im_class.__name__, target.__name__)
     else:
         logger.debug('Initializing `%s` in a new thread', target.__name__)
Example #8
0
    def get(self):
        logger.debug('Requesting {}'.format(self.url))

        return self.cache_response(self.url, self.get_with_etag_cache(self.url))