def setup(self):
     self.sess = Session()
     self.cached_sess = CacheControl(self.sess, heuristic=OneDayCache())
Пример #2
0
    def _test_head_cachecontrol(self):
        # cache polluted by HEAD
        url = "http://gpodder.org/"

        class MoreCodesCacheController(CacheController):
            def __init__(self, *args, **kwargs):
                kwargs["status_codes"] = (200, 203, 300, 301, 302, 404)
                super(MoreCodesCacheController, self).__init__(*args, **kwargs)

        cache = DictCache()
        s = CacheControl(
            requests.Session(),
            cache=cache,
            heuristic=OneDayCache(),
            cacheable_methods=["GET", "HEAD"],
            controller_class=MoreCodesCacheController,
        )
        r = s.head(url, timeout=Timeout(15))
        self.assertEqual(r.status_code, 302)
        self.assertEqual(r.url, url)
        self.assertEqual(r.headers["location"], "https://gpodder.github.io")
        self.assertFalse(r.content)
        self.assertFalse(r.from_cache)

        r = s.get(url, timeout=Timeout(15), allow_redirects=False)
        self.assertEqual(r.status_code, 302)
        self.assertEqual(r.url, url)
        self.assertEqual(r.headers["location"], "https://gpodder.github.io")
        self.assertTrue(r.content)
        self.assertIn(b"302 Found", r.content)
        self.assertFalse(r.from_cache)

        # Re-fetch the redirect from the cache
        r = s.get(url, timeout=Timeout(15), allow_redirects=False)
        self.assertEqual(r.status_code, 302)
        self.assertEqual(r.url, url)
        self.assertEqual(r.headers["location"], "https://gpodder.github.io")
        self.assertTrue(r.content)
        self.assertIn(b"302 Found", r.content)

        self.assertTrue(r.from_cache)

        # Now allow redirects

        r = s.get(url, timeout=Timeout(15))
        self.assertEqual(r.status_code, 200)
        self.assertNotEqual(r.url, url)
        self.assertTrue(r.content)
        self.assertFalse(r.from_cache)

        # Re-fetch the redirect from the cache
        r = s.get(url, timeout=Timeout(15), allow_redirects=False)
        self.assertEqual(r.status_code, 302)
        self.assertEqual(r.url, url)
        self.assertEqual(r.headers["location"], "https://gpodder.github.io")
        self.assertTrue(r.content)
        self.assertIn(b"302 Found", r.content)

        self.assertTrue(r.from_cache)

        # Re-fetch the head from the cache
        r = s.head(url, timeout=Timeout(15))
        self.assertEqual(r.status_code, 302)
        self.assertEqual(r.url, url)
        self.assertEqual(r.headers["location"], "https://gpodder.github.io")
        self.assertTrue(r.content)
        self.assertIn(b"302 Found", r.content)
        self.assertTrue(r.from_cache)
Пример #3
0
                              copyright_holder='PraDigi').as_dict()
PRADIGI_WEBSITE_LANGUAGES = ['Hindi']
PRADIGI_DESCRIPTION = 'Developed by Pratham, these educational games, videos, ' \
                      'and ebooks are designed to teach language learning, math, science, English, ' \
                      'health, and vocational training in Hindi, Marathi, Odia, Bengali, Urdu, ' \
                      'Punjabi, Kannada, Tamil, Telugu, Gujarati and Assamese. Materials are ' \
                      'designed for learners of all ages, including those outside the formal classroom setting.'

# In debug mode, only one topic is downloaded.
LOGGER.setLevel(logging.DEBUG)
DEBUG_MODE = True  # source_urls in content desriptions

# WebCache logic (downloaded web resources cached for one day -- good for dev)
cache = FileCache('.webcache')
basic_adapter = CacheControlAdapter(cache=cache)
develop_adapter = CacheControlAdapter(heuristic=OneDayCache(), cache=cache)
session = requests.Session()
session.mount('http://www.' + PRADIGI_DOMAIN, develop_adapter)
session.mount('https://www.' + PRADIGI_DOMAIN, develop_adapter)

CHEF_DIR = os.path.dirname(os.path.realpath(__file__))
print(CHEF_DIR)

# LOCALIZATION AND TRANSLATION STRINGS
################################################################################
PRADIGI_STRINGS = {
    'hi': {
        'language_en': 'Hindi',
        'website_lang': 'hn',
        'gamesrepo_suffixes': ['_KKS', '_HI', '_Hi'],
    },