当前位置: 首页>>代码示例>>Python>>正文


Python http.parse_cache_control_header函数代码示例

本文整理汇总了Python中werkzeug.http.parse_cache_control_header函数的典型用法代码示例。如果您正苦于以下问题:Python parse_cache_control_header函数的具体用法?Python parse_cache_control_header怎么用?Python parse_cache_control_header使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse_cache_control_header函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_static_file

 def test_static_file(self):
     app = flask.Flask(__name__)
     # default cache timeout is 12 hours
     with app.test_request_context():
         rv = app.send_static_file('index.html')
         cc = parse_cache_control_header(rv.headers['Cache-Control'])
         self.assert_equal(cc.max_age, 12 * 60 * 60)
     app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600
     with app.test_request_context():
         rv = app.send_static_file('index.html')
         cc = parse_cache_control_header(rv.headers['Cache-Control'])
         self.assert_equal(cc.max_age, 3600)
     # override get_send_file_options with some new values and check them
     class StaticFileApp(flask.Flask):
         def get_send_file_options(self, filename):
             opts = super(StaticFileApp, self).get_send_file_options(filename)
             opts['cache_timeout'] = 10
             # this test catches explicit inclusion of the conditional
             # keyword arg in the guts
             opts['conditional'] = True
             return opts
     app = StaticFileApp(__name__)
     with app.test_request_context():
         rv = app.send_static_file('index.html')
         cc = parse_cache_control_header(rv.headers['Cache-Control'])
         self.assert_equal(cc.max_age, 10)
开发者ID:SimonSapin,项目名称:flask,代码行数:26,代码来源:helpers.py

示例2: test_static_file

    def test_static_file(self):
        app = flask.Flask(__name__)
        # default cache timeout is 12 hours (hard-coded)
        with app.test_request_context():
            rv = app.send_static_file("index.html")
            cc = parse_cache_control_header(rv.headers["Cache-Control"])
            self.assert_equal(cc.max_age, 12 * 60 * 60)
        # override get_static_file_options with some new values and check them
        class StaticFileApp(flask.Flask):
            def __init__(self):
                super(StaticFileApp, self).__init__(__name__)

            def get_static_file_options(self, filename):
                opts = super(StaticFileApp, self).get_static_file_options(filename)
                opts["cache_timeout"] = 10
                # this test catches explicit inclusion of the conditional
                # keyword arg in the guts
                opts["conditional"] = True
                return opts

        app = StaticFileApp()
        with app.test_request_context():
            rv = app.send_static_file("index.html")
            cc = parse_cache_control_header(rv.headers["Cache-Control"])
            self.assert_equal(cc.max_age, 10)
开发者ID:dave-shawley,项目名称:flask,代码行数:25,代码来源:helpers.py

示例3: fix_headers

    def fix_headers(self, environ, headers, status=None):
        if self.fix_vary:
            header = headers.get("content-type", "")
            mimetype, options = parse_options_header(header)
            if mimetype not in ("text/html", "text/plain", "text/sgml"):
                headers.pop("vary", None)

        if self.fix_attach and "content-disposition" in headers:
            pragma = parse_set_header(headers.get("pragma", ""))
            pragma.discard("no-cache")
            header = pragma.to_header()
            if not header:
                headers.pop("pragma", "")
            else:
                headers["Pragma"] = header
            header = headers.get("cache-control", "")
            if header:
                cc = parse_cache_control_header(header, cls=ResponseCacheControl)
                cc.no_cache = None
                cc.no_store = False
                header = cc.to_header()
                if not header:
                    headers.pop("cache-control", "")
                else:
                    headers["Cache-Control"] = header
开发者ID:jrgrafton,项目名称:tweet-debate,代码行数:25,代码来源:fixers.py

示例4: fix_headers

    def fix_headers(self, environ, headers, status=None):
        if self.fix_vary:
            header = headers.get('content-type', '')
            mimetype, options = parse_options_header(header)
            if mimetype not in ('text/html', 'text/plain', 'text/sgml'):
                headers.pop('vary', None)

        if self.fix_attach and 'content-disposition' in headers:
            pragma = parse_set_header(headers.get('pragma', ''))
            pragma.discard('no-cache')
            header = pragma.to_header()
            if not header:
                headers.pop('pragma', '')
            else:
                headers['Pragma'] = header
            header = headers.get('cache-control', '')
            if header:
                cc = parse_cache_control_header(header,
                                                cls=ResponseCacheControl)
                cc.no_cache = None
                cc.no_store = False
                header = cc.to_header()
                if not header:
                    headers.pop('cache-control', '')
                else:
                    headers['Cache-Control'] = header
开发者ID:gaoussoucamara,项目名称:simens-cerpad,代码行数:26,代码来源:fixers.py

示例5: cache_control

    def cache_control(self):
        def on_update(cache_control):
            if not cache_control and "cache-control" in self.headers:
                del self.headers["cache-control"]
            elif cache_control:
                self.headers["Cache-Control"] = cache_control.to_header()

        return parse_cache_control_header(self.headers.get("cache-control"), on_update, ResponseCacheControl)
开发者ID:Reve,项目名称:eve,代码行数:8,代码来源:wrappers.py

示例6: get_cache_timeout

def get_cache_timeout(r):
    # Cache the weather data at a rate that the upstream service dictates, but
    # that also keeps us easily within the 1000 requests per day free limit.
    header = r.headers.get('Cache-Control')
    control = parse_cache_control_header(header, cls=ResponseCacheControl)
    try:
        return max(control.max_age, CACHE_MIN_SECONDS)
    except TypeError:
        return CACHE_MIN_SECONDS
开发者ID:genericmoniker,项目名称:mirror,代码行数:9,代码来源:weather.py

示例7: test_cache_control_header

    def test_cache_control_header(self):
        cc = http.parse_cache_control_header("max-age=0, no-cache")
        assert cc.max_age == 0
        assert cc.no_cache
        cc = http.parse_cache_control_header('private, community="UCI"', None, datastructures.ResponseCacheControl)
        assert cc.private
        assert cc["community"] == "UCI"

        c = datastructures.ResponseCacheControl()
        assert c.no_cache is None
        assert c.private is None
        c.no_cache = True
        assert c.no_cache == "*"
        c.private = True
        assert c.private == "*"
        del c.private
        assert c.private is None
        assert c.to_header() == "no-cache"
开发者ID:homeworkprod,项目名称:werkzeug,代码行数:18,代码来源:http.py

示例8: test_cache_control_header

    def test_cache_control_header(self):
        cc = http.parse_cache_control_header('max-age=0, no-cache')
        assert cc.max_age == 0
        assert cc.no_cache
        cc = http.parse_cache_control_header('private, community="UCI"', None,
                                             datastructures.ResponseCacheControl)
        assert cc.private
        assert cc['community'] == 'UCI'

        c = datastructures.ResponseCacheControl()
        assert c.no_cache is None
        assert c.private is None
        c.no_cache = True
        assert c.no_cache == '*'
        c.private = True
        assert c.private == '*'
        del c.private
        assert c.private is None
        assert c.to_header() == 'no-cache'
开发者ID:211sandiego,项目名称:calllog211,代码行数:19,代码来源:http.py

示例9: get_ff_cache

def get_ff_cache(profile_dir, store_body=False):
    cache_dir = os.path.join(profile_dir, "Cache")
    if not os.path.isdir(cache_dir):
        return []  # Firefox updated the cache dir structure since our study
    cache_map = os.path.join(cache_dir, "_CACHE_MAP_")
    cache_dump = os.path.join(BASE_TMP_DIR, append_timestamp("cache") +
                              rand_str())
    create_dir(cache_dump)
    subprocess.call([PERL_PATH, CACHE_PERL_SCRIPT, cache_map, "--recover=" +
                     cache_dump])
    cache_items = []
    db_items = ("Etag", "Request String", "Expires", "Cache-Control")
    for fname in glob(os.path.join(cache_dump, "*_metadata")):
        item = {}
        try:
            with open(fname) as f:
                metadata = f.read()
                item = parse_metadata(metadata)
                for db_item in db_items:
                    if db_item not in item:
                        item[db_item] = ""

                # If a response includes both an Expires header and a max-age
                # directive, the max-age directive overrides the Expires header
                # (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)
                expiry_delta_sec = 0
                if "Expires" in item:
                    # parse expiry date
                    expiry = parse_date(item["Expires"])
                    if expiry:
                        expiry_delta = expiry - datetime.now()
                        expiry_delta_sec = expiry_delta.total_seconds()
                if "Cache-Control:" in item:
                    # parse max-age directive
                    cache_directives =\
                        parse_cache_control_header(item["Cache-Control"],
                                                   cls=ResponseCacheControl)
                    if "max-age" in cache_directives:
                        expiry_delta_sec = cache_directives["max-age"]
                if expiry_delta_sec < DELTA_MONTH:
                    continue
                item["Expiry-Delta"] = expiry_delta_sec

            with open(fname[:-9]) as f:
                data = f.read()
                item["Body"] = data if store_body else ""  # store as BLOB
                item["Hash"] = hash_text(base64.b64encode(data))
        except IOError as exc:
            print "Error processing cache: %s: %s" % (exc,
                                                      traceback.format_exc())

        cache_items.append(item)
    if os.path.isdir(cache_dump):
        shutil.rmtree(cache_dump)
    return cache_items
开发者ID:4sp1r3,项目名称:TheWebNeverForgets,代码行数:55,代码来源:cache.py

示例10: cache_control

 def cache_control(self):
     """The Cache-Control general-header field is used to specify
     directives that MUST be obeyed by all caching mechanisms along the
     request/response chain.
     """
     def on_update(cache_control):
         if not cache_control and 'cache-control' in self.headers:
             del self.headers['cache-control']
         elif cache_control:
             self.headers['Cache-Control'] = cache_control.to_header()
     return parse_cache_control_header(self.headers.get('cache-control'),
                                       on_update)
开发者ID:danaspiegel,项目名称:softball_stat_manager,代码行数:12,代码来源:wrappers.py

示例11: testStaticFile

    def testStaticFile(self):
        ConfigManager.removeConfig('development')
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)
        app.setStaticFolder('static')
        with app.testRequestContext():
            rv = app.sendStaticFile('index.html')
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assertEqual(cc.max_age, 12 * 60 * 60)
            rv = shimehari.sendFile(os.path.join(app.rootPath, 'static/index.html'))
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assertEqual(cc.max_age, 12 * 60 * 60)
        app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600
        with app.testRequestContext():
            rv = app.sendStaticFile('index.html')
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assertEqual(cc.max_age, 3600)
            rv = shimehari.sendFile(os.path.join(app.rootPath, 'static/index.html'))
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assertEqual(cc.max_age, 3600)

        class StaticFileApp(shimehari.Shimehari):
            def getSendFileMaxAge(self, filename):
                return 10
        app = StaticFileApp(__name__)
        app.setStaticFolder('static')
        with app.testRequestContext():
            rv = app.sendStaticFile('index.html')
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assertEqual(cc.max_age, 10)
            rv = shimehari.sendFile(os.path.join(app.rootPath, 'static/index.html'))
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assertEqual(cc.max_age, 10)
开发者ID:glassesfactory,项目名称:Shimehari,代码行数:33,代码来源:test_helpers.py

示例12: test_static_file

 def test_static_file(self):
     app = flask.Flask(__name__)
     # default cache timeout is 12 hours
     with app.test_request_context():
         # Test with static file handler.
         rv = app.send_static_file('index.html')
         cc = parse_cache_control_header(rv.headers['Cache-Control'])
         self.assert_equal(cc.max_age, 12 * 60 * 60)
         # Test again with direct use of send_file utility.
         rv = flask.send_file('static/index.html')
         cc = parse_cache_control_header(rv.headers['Cache-Control'])
         self.assert_equal(cc.max_age, 12 * 60 * 60)
     app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600
     with app.test_request_context():
         # Test with static file handler.
         rv = app.send_static_file('index.html')
         cc = parse_cache_control_header(rv.headers['Cache-Control'])
         self.assert_equal(cc.max_age, 3600)
         # Test again with direct use of send_file utility.
         rv = flask.send_file('static/index.html')
         cc = parse_cache_control_header(rv.headers['Cache-Control'])
         self.assert_equal(cc.max_age, 3600)
     class StaticFileApp(flask.Flask):
         def get_send_file_max_age(self, filename):
             return 10
     app = StaticFileApp(__name__)
     with app.test_request_context():
         # Test with static file handler.
         rv = app.send_static_file('index.html')
         cc = parse_cache_control_header(rv.headers['Cache-Control'])
         self.assert_equal(cc.max_age, 10)
         # Test again with direct use of send_file utility.
         rv = flask.send_file('static/index.html')
         cc = parse_cache_control_header(rv.headers['Cache-Control'])
         self.assert_equal(cc.max_age, 10)
开发者ID:JeffSpies,项目名称:flask,代码行数:35,代码来源:helpers.py

示例13: _get_cache_control_directive

 def _get_cache_control_directive(self, name):
     success, the_values = self._enumerate_header("cache-control")
     if success:
         cc = parse_cache_control_header(the_values,
                                         cls=ResponseCacheControl)
         if name == "max-age" and cc.max_age is not None:
             return True, timedelta(seconds=int(cc.max_age))
         elif name == "stale-while-revalidate" and \
                 cc.stale_while_revalidate is not None:
             return True, timedelta(seconds=int(cc.stale_while_revalidate))
         else:
             return False, None
     else:
         return False, None
开发者ID:ahlfors,项目名称:http_cache_control_analyser,代码行数:14,代码来源:http_response_headers.py

示例14: test_templates_and_static

    def test_templates_and_static(self):
        from blueprintapp import app

        c = app.test_client()

        rv = c.get('/')
        self.assert_equal(rv.data, b'Hello from the Frontend')
        rv = c.get('/admin/')
        self.assert_equal(rv.data, b'Hello from the Admin')
        rv = c.get('/admin/index2')
        self.assert_equal(rv.data, b'Hello from the Admin')
        rv = c.get('/admin/static/test.txt')
        self.assert_equal(rv.data.strip(), b'Admin File')
        rv.close()
        rv = c.get('/admin/static/css/test.css')
        self.assert_equal(rv.data.strip(), b'/* nested file */')
        rv.close()

        # try/finally, in case other tests use this app for Blueprint tests.
        max_age_default = app.config['SEND_FILE_MAX_AGE_DEFAULT']
        try:
            expected_max_age = 3600
            if app.config['SEND_FILE_MAX_AGE_DEFAULT'] == expected_max_age:
                expected_max_age = 7200
            app.config['SEND_FILE_MAX_AGE_DEFAULT'] = expected_max_age
            rv = c.get('/admin/static/css/test.css')
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assert_equal(cc.max_age, expected_max_age)
            rv.close()
        finally:
            app.config['SEND_FILE_MAX_AGE_DEFAULT'] = max_age_default

        with app.test_request_context():
            self.assert_equal(flask.url_for('admin.static', filename='test.txt'),
                              '/admin/static/test.txt')

        with app.test_request_context():
            try:
                flask.render_template('missing.html')
            except TemplateNotFound as e:
                self.assert_equal(e.name, 'missing.html')
            else:
                self.assert_true(0, 'expected exception')

        with flask.Flask(__name__).test_request_context():
            self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')
开发者ID:dvska,项目名称:flask,代码行数:46,代码来源:blueprints.py

示例15: surrogate_control

 def surrogate_control(self):
     """
     The Cache-Control general-header field is used to specify
     directives that MUST be obeyed by all caching mechanisms along the
     request/response chain.
     """
     def on_update(surrogate_control):
         if not surrogate_control and "surrogate-control" in self.headers:
             del self.headers["surrogate-control"]
         elif surrogate_control:  # pragma: no cover
             self.headers["Surrogate-Control"] = \
                 surrogate_control.to_header()
     return parse_cache_control_header(
         self.headers.get("surrogate-control"),
         on_update,
         ResponseCacheControl,
     )
开发者ID:AaronLaw,项目名称:warehouse,代码行数:17,代码来源:http.py


注:本文中的werkzeug.http.parse_cache_control_header函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。