本文整理匯總了Python中webob.cachecontrol.CacheControl類的典型用法代碼示例。如果您正苦於以下問題:Python CacheControl類的具體用法?Python CacheControl怎麽用?Python CacheControl使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CacheControl類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _cache_control__get
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
示例2: test_parse_valueerror_int
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'
示例3: test_parse_updates_to
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
示例4: _cache_control__get
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
示例5: _cache_control__get
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
示例6: _cache_control__set
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)
示例7: test_cache_control_object_max_age_None
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)
示例8: test_parse_valueerror_int
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')
示例9: test_parse_updates_to
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)
示例10: test_parse
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)
示例11: test_copy_cc
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
示例12: test_parse
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