def _cache_control__get(self): """ Get/set/modify the Cache-Control header (section `14.9 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9>`_) """ value = self.headers.get('cache-control', '') if self._cache_control_obj is None: self._cache_control_obj = CacheControl.parse(value, updates_to=self._update_cache_control, type='response') self._cache_control_obj.header_value = value if self._cache_control_obj.header_value != value: new_obj = CacheControl.parse(value, type='response') self._cache_control_obj.properties.clear() self._cache_control_obj.properties.update(new_obj.properties) self._cache_control_obj.header_value = value return self._cache_control_obj
def test_parse(self): from webob.cachecontrol import CacheControl cc = CacheControl.parse("public, max-age=315360000") assert type(cc) == CacheControl assert cc.max_age == 315360000 assert cc.public is True
def test_parse_valueerror_int(self): from webob.cachecontrol import CacheControl def foo(arg): return {'a': 1} cc = CacheControl.parse("public, max-age=abc") assert type(cc) == CacheControl assert cc.max_age == 'abc'
def test_parse_updates_to(self): from webob.cachecontrol import CacheControl def foo(arg): return {'a': 1} cc = CacheControl.parse("public, max-age=315360000", updates_to=foo) assert type(cc) == CacheControl assert cc.max_age == 315360000
def _cache_control__get(self): """ Get/set/modify the Cache-Control header (`HTTP spec section 14.9 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9>`_) """ value = self.headers.get('cache-control', '') if self._cache_control_obj is None: self._cache_control_obj = CacheControl.parse( value, updates_to=self._update_cache_control, type='response') self._cache_control_obj.header_value = value if self._cache_control_obj.header_value != value: new_obj = CacheControl.parse(value, type='response') self._cache_control_obj.properties.clear() self._cache_control_obj.properties.update(new_obj.properties) self._cache_control_obj.header_value = value return self._cache_control_obj
def test_parse_updates_to(self): from webob.cachecontrol import CacheControl def foo(arg): return {'a': 1} cc = CacheControl.parse("public, max-age=315360000", updates_to=foo) self.assertEqual(type(cc), CacheControl) self.assertEqual(cc.max_age, 315360000)
def test_parse_valueerror_int(self): from webob.cachecontrol import CacheControl def foo(arg): return {'a': 1} cc = CacheControl.parse("public, max-age=abc") self.assertEqual(type(cc), CacheControl) self.assertEqual(cc.max_age, 'abc')
def test_parse_valueerror_int(self): from webob.cachecontrol import CacheControl def foo(arg): return {"a": 1} cc = CacheControl.parse("public, max-age=abc") assert type(cc) == CacheControl assert cc.max_age == "abc"
def test_parse_updates_to(self): from webob.cachecontrol import CacheControl def foo(arg): return {"a": 1} cc = CacheControl.parse("public, max-age=315360000", updates_to=foo) assert type(cc) == CacheControl assert cc.max_age == 315360000
def _cache_control__get(self): """ Get/set/modify the Cache-Control header (`HTTP spec section 14.9 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9>`_) """ env = self.environ value = env.get("HTTP_CACHE_CONTROL", "") cache_header, cache_obj = env.get("webob._cache_control", (None, None)) if cache_obj is not None and cache_header == value: return cache_obj cache_obj = CacheControl.parse(value, updates_to=self._update_cache_control, type="request") env["webob._cache_control"] = (value, cache_obj) return cache_obj
def _cache_control__get(self): """ Get/set/modify the Cache-Control header (section `14.9 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9>`_) """ env = self.environ value = env.get('HTTP_CACHE_CONTROL', '') cache_header, cache_obj = env.get('webob._cache_control', (None, None)) if cache_obj is not None and cache_header == value: return cache_obj cache_obj = CacheControl.parse(value, type='request') env['webob._cache_control'] = (value, cache_obj) return cache_obj
def _cache_control__get(self): """ Get/set/modify the Cache-Control header (section `14.9 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9>`_) """ env = self.environ value = env.get('HTTP_CACHE_CONTROL', '') cache_header, cache_obj = env.get('webob._cache_control', (None, None)) if cache_obj is not None and cache_header == value: return cache_obj cache_obj = CacheControl.parse(value, type='request') env['webob._cache_control'] = (value, cache_obj) return cache_obj
def _cache_control__set(self, value): # This actually becomes a copy if not value: value = "" if isinstance(value, dict): value = CacheControl(value, 'response') if isinstance(value, text_type): value = str(value) if isinstance(value, str): if self._cache_control_obj is None: self.headers['Cache-Control'] = value return value = CacheControl.parse(value, 'response') cache = self.cache_control cache.properties.clear() cache.properties.update(value.properties)
def _cache_control__set(self, value): # This actually becomes a copy if not value: value = "" if isinstance(value, dict): value = CacheControl(value, 'response') if isinstance(value, six.text_type): value = str(value) if isinstance(value, str): if self._cache_control_obj is None: self.headers['Cache-Control'] = value return value = CacheControl.parse(value, 'response') cache = self.cache_control cache.properties.clear() cache.properties.update(value.properties)
def _fetch_and_cache(url): keys = memcache.get(url) if keys: return keys response = urlfetch.fetch(url) cache = CacheControl.parse(response.headers['cache-control']) if response.status_code / 400: logging.error("Could not fetch {}".format(url)) logging.error("Response: {} {}".format(response.status_code, response.content)) raise FirebaseTokenError("Cound not fetch {}".format(url)) response = json.loads(response.content) memcache.set(url, response, cache.max_age) return response
def test_parse_valueerror_int(self): from webob.cachecontrol import CacheControl def foo(arg): return { 'a' : 1 } cc = CacheControl.parse("public, max-age=abc") self.assertEquals(type(cc), CacheControl) self.assertEquals(cc.max_age, 'abc')
def test_parse(self): from webob.cachecontrol import CacheControl cc = CacheControl.parse("public, max-age=315360000") self.assertEquals(type(cc), CacheControl) self.assertEquals(cc.max_age, 315360000) self.assertEquals(cc.public, True)
def test_parse(self): from webob.cachecontrol import CacheControl cc = CacheControl.parse("public, max-age=315360000") self.assertEqual(type(cc), CacheControl) self.assertEqual(cc.max_age, 315360000) self.assertEqual(cc.public, True)
def test_parse_updates_to(self): from webob.cachecontrol import CacheControl def foo(arg): return { 'a' : 1 } cc = CacheControl.parse("public, max-age=315360000", updates_to=foo) self.assertEquals(type(cc), CacheControl) self.assertEquals(cc.max_age, 315360000)
def test_parse(self): from webob.cachecontrol import CacheControl cc = CacheControl.parse("public, max-age=315360000") assert type(cc) == CacheControl assert cc.max_age == 315360000 assert cc.public is True