def test_copy_cc(): from webob.cachecontrol import CacheControl cc = CacheControl({"header": "%", "msg": "arewerichyet?"}, "request") cc2 = cc.copy() assert cc.properties is not cc2.properties assert cc.type is cc2.type
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 _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(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__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 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_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") 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__set(self, value): env = self.environ value = value or '' if isinstance(value, dict): value = CacheControl(value, type='request') if isinstance(value, CacheControl): str_value = str(value) env['HTTP_CACHE_CONTROL'] = str_value env['webob._cache_control'] = (str_value, value) else: env['HTTP_CACHE_CONTROL'] = str(value) env['webob._cache_control'] = (None, None)
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 (`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__set(self, value): env = self.environ if not value: value = "" if isinstance(value, dict): value = CacheControl(value, type='request') if isinstance(value, CacheControl): str_value = str(value) env['HTTP_CACHE_CONTROL'] = str_value env['webob._cache_control'] = (str_value, value) else: env['HTTP_CACHE_CONTROL'] = str(value) if 'webob._cache_control' in env: del env['webob._cache_control']
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 _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 make_one(self, props, typ): from webob.cachecontrol import CacheControl return CacheControl(props, typ)
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_serialize_cache_control_value_is_None(): from webob.cachecontrol import serialize_cache_control, CacheControl result = serialize_cache_control(CacheControl({'header': None}, 'request')) assert result == 'header'
def test_serialize_cache_control_value_needs_quote(): from webob.cachecontrol import serialize_cache_control, CacheControl result = serialize_cache_control(CacheControl({'header': '""'}, 'request')) assert result == 'header=""""'
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_serialize_cache_control_object_with_headers(): from webob.cachecontrol import serialize_cache_control, CacheControl result = serialize_cache_control(CacheControl({'header': 'a'}, 'request')) assert result == 'header=a'
def test_serialize_cache_control_value_is_None(): from webob.cachecontrol import CacheControl, serialize_cache_control result = serialize_cache_control(CacheControl({"header": None}, "request")) assert result == "header"
def test_cache_control_object_max_age_None(): from webob.cachecontrol import CacheControl cc = CacheControl({}, 'a') cc.properties['max-age'] = None eq_(cc.max_age, -1)
def test_cache_control_object_max_age_None(): from webob.cachecontrol import CacheControl cc = CacheControl({}, "a") cc.properties["max-age"] = None assert cc.max_age == -1
def test_serialize_cache_control_value_needs_quote(): from webob.cachecontrol import CacheControl, serialize_cache_control result = serialize_cache_control(CacheControl({"header": '""'}, "request")) assert result == 'header=""""'
def test_copy_cc(): from webob.cachecontrol import CacheControl cc = CacheControl({'header':'%', "msg":'arewerichyet?'}, 'request') cc2 = cc.copy() assert cc.properties is not cc2.properties assert cc.type is cc2.type
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_serialize_cache_control_object_with_headers(): from webob.cachecontrol import CacheControl, serialize_cache_control result = serialize_cache_control(CacheControl({"header": "a"}, "request")) assert result == "header=a"
def test_copy_cc(): from webob.cachecontrol import CacheControl cc = CacheControl({'header': '%', "msg": 'arewerichyet?'}, 'request') cc2 = cc.copy() assert cc.properties is not cc2.properties assert cc.type is cc2.type
def test_serialize_cache_control_cache_control_object(): from webob.cachecontrol import CacheControl, serialize_cache_control result = serialize_cache_control(CacheControl({}, "request")) assert result == ""
def test_serialize_cache_control_cache_control_object(): from webob.cachecontrol import serialize_cache_control, CacheControl result = serialize_cache_control(CacheControl({}, 'request')) assert result == ''
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)