예제 #1
0
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
예제 #2
0
 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
예제 #3
0
 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
예제 #4
0
    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
예제 #5
0
 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'
예제 #6
0
 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
예제 #7
0
 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)
예제 #8
0
    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')
예제 #9
0
    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)
예제 #10
0
    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"
예제 #11
0
    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
예제 #12
0
 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
예제 #14
0
 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
예제 #15
0
 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
예제 #16
0
 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']
예제 #17
0
파일: response.py 프로젝트: nkunal/webob
 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)
예제 #18
0
    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
예제 #19
0
 def make_one(self, props, typ):
     from webob.cachecontrol import CacheControl
     return CacheControl(props, typ)
예제 #20
0
 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)
예제 #21
0
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'
예제 #22
0
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=""""'
예제 #23
0
 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')
예제 #24
0
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'
예제 #25
0
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"
예제 #26
0
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)
예제 #27
0
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
예제 #28
0
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=""""'
예제 #29
0
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
예제 #30
0
 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)
예제 #31
0
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)
예제 #32
0
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"
예제 #33
0
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
예제 #34
0
def test_serialize_cache_control_cache_control_object():
    from webob.cachecontrol import CacheControl, serialize_cache_control

    result = serialize_cache_control(CacheControl({}, "request"))
    assert result == ""
예제 #35
0
def test_serialize_cache_control_cache_control_object():
    from webob.cachecontrol import serialize_cache_control, CacheControl
    result = serialize_cache_control(CacheControl({}, 'request'))
    assert result == ''
예제 #36
0
 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)
예제 #37
0
 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