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


Python http.quote_etag函数代码示例

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


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

示例1: test_etags

 def test_etags(self):
     assert http.quote_etag("foo") == '"foo"'
     assert http.quote_etag("foo", True) == 'w/"foo"'
     assert http.unquote_etag('"foo"') == ("foo", False)
     assert http.unquote_etag('w/"foo"') == ("foo", True)
     es = http.parse_etags('"foo", "bar", w/"baz", blar')
     assert sorted(es) == ["bar", "blar", "foo"]
     assert "foo" in es
     assert "baz" not in es
     assert es.contains_weak("baz")
     assert "blar" in es
     assert es.contains_raw('w/"baz"')
     assert es.contains_raw('"foo"')
     assert sorted(es.to_header().split(", ")) == ['"bar"', '"blar"', '"foo"', 'w/"baz"']
开发者ID:homeworkprod,项目名称:werkzeug,代码行数:14,代码来源:http.py

示例2: test_exception_header_forwarded

    def test_exception_header_forwarded(self):
        '''Ensure that HTTPException's headers are extended properly'''
        self.app.config['DEBUG'] = True
        api = restplus.Api(self.app)

        class NotModified(HTTPException):
            code = 304

            def __init__(self, etag, *args, **kwargs):
                super(NotModified, self).__init__(*args, **kwargs)
                self.etag = quote_etag(etag)

            def get_headers(self, *args, **kwargs):
                return [('ETag', self.etag)]

        @api.route('/foo')
        class Foo1(restplus.Resource):
            def get(self):
                abort(304, etag='myETag')

        abort.mapping.update({304: NotModified})

        with self.app.test_client() as client:
            foo = client.get('/foo')
            self.assertEquals(foo.get_etag(),
                              unquote_etag(quote_etag('myETag')))
开发者ID:Dlotan,项目名称:flask-restplus,代码行数:26,代码来源:test_errors.py

示例3: test_exception_header_forwarded

    def test_exception_header_forwarded(self):
        """Test that HTTPException's headers are extended properly"""
        app = Flask(__name__)
        app.config['DEBUG'] = True
        api = flask_restful.Api(app)

        class NotModified(HTTPException):
            code = 304

            def __init__(self, etag, *args, **kwargs):
                super(NotModified, self).__init__(*args, **kwargs)
                self.etag = quote_etag(etag)

            def get_headers(self, *args, **kwargs):
                """Get a list of headers."""
                return [('ETag', self.etag)]

        class Foo1(flask_restful.Resource):
            def get(self):
                flask_abort(304, etag='myETag')

        api.add_resource(Foo1, '/foo')
        _aborter.mapping.update({304: NotModified})

        with app.test_client() as client:
            foo = client.get('/foo')
            self.assertEquals(foo.get_etag(),
                              unquote_etag(quote_etag('myETag')))
开发者ID:aferber,项目名称:flask-restful,代码行数:28,代码来源:test_api.py

示例4: build_etag

    def build_etag(self, response, include_etag=True, **kwargs):
        """
        Add an etag to the response body.

        Uses spooky where possible because it is empirically fast and well-regarded.

        See: http://blog.reverberate.org/2012/01/state-of-hash-functions-2012.html

        """
        if not include_etag:
            return

        if not spooky:
            # use built-in md5
            response.add_etag()
            return

        # use spooky
        response.headers["ETag"] = quote_etag(
            hexlify(
                spooky.hash128(
                    response.get_data(),
                ).to_bytes(16, "little"),
            ).decode("utf-8"),
        )
开发者ID:globality-corp,项目名称:microcosm-flask,代码行数:25,代码来源:base.py

示例5: response

    def response(self, request, data, etag=None, cache_policy=None):
        """Renders `data` to a JSON response.

        An ETag may be specified. When it is not specified one will be generated
        based on the data.

        The caching policy can be optionally configured. By default it takes the
        policy from the controller object: `cache_policy`.
        """
        if etag is None and data is not None:
            etag = self.etag(data)
        # FIXME: Check content-type headers
        if data is None:
            if etag is None:
                raise TypeError('response requires an etag when '
                                'the response body is None')
            resp = Response(status=304, content_type='application/json')
        else:
            # Avoid sending the resource when an ETag matches
            request_etags = parse_etags(
                request.environ.get('HTTP_IF_NONE_MATCH'))
            if request_etags.contains(etag):
                 resp = Response(status=304, content_type='application/json')
            # Render the given data to a response object
            else:
                resp = Response(self.data_encoder.encode(data), content_type='application/json')
        resp.headers['ETag'] = quote_etag(etag)
        if cache_policy is None:
            cache_policy = self.cache_policy
        return cache_policy(resp)
开发者ID:DerRechner,项目名称:Hanabi,代码行数:30,代码来源:rest.py

示例6: check_normal_response

 def check_normal_response(res, method):
     if method != client.head:
         parsed = json.loads(res.get_data(as_text=True))
         expected = {'id': 1, 'method': parsed['method']}
         assert parsed == expected
         # check that the right method was called
         assert method_names[parsed['method']] == method
         assert res.content_type == 'application/json'
     assert res.status_code == 200
     # check that the ETag is correct
     assert unquote_etag(res.headers['ETag']) == \
         unquote_etag(quote_etag('abc'))
开发者ID:tiborsimko,项目名称:invenio-rest,代码行数:12,代码来源:test_invenio_rest.py

示例7: serve_file

def serve_file(path):
    headers = {}

    st = os.stat(path)

    etag = 'clay-{0}-{1}-{2}'.format(
        os.path.getmtime(path),
        os.path.getsize(path),
        adler32(path.encode('utf-8')) & 0xffffffff
    )
    headers['ETag'] = quote_etag(etag)

    # Set the Last-Modified response header, so that
    # modified-since validation code can work.
    headers['Last-Modified'] = httputil.HTTPDate(st.st_mtime)

    _, ext = os.path.splitext(path)
    content_type = mimetypes.types_map.get(ext, None)
    headers['Content-Type'] = content_type or 'text/plain'

    fileobj = open(path, 'rb')
    return serve_fileobj(fileobj, headers, st.st_size)
开发者ID:PavloKapyshin,项目名称:Clay,代码行数:22,代码来源:static.py

示例8: test_exception_header_forwarded

    def test_exception_header_forwarded(self, app, client):
        '''Ensure that HTTPException's headers are extended properly'''
        api = restplus.Api(app)

        class NotModified(HTTPException):
            code = 304

            def __init__(self, etag, *args, **kwargs):
                super(NotModified, self).__init__(*args, **kwargs)
                self.etag = quote_etag(etag)

            def get_headers(self, *args, **kwargs):
                return [('ETag', self.etag)]

        custom_abort = Aborter(mapping={304: NotModified})

        @api.route('/foo')
        class Foo1(restplus.Resource):
            def get(self):
                custom_abort(304, etag='myETag')

        foo = client.get('/foo')
        assert foo.get_etag() == unquote_etag(quote_etag('myETag'))
开发者ID:bedge,项目名称:flask-restplus,代码行数:23,代码来源:test_errors.py

示例9: __init__

 def __init__(self, etag, *args, **kwargs):
     super(NotModified, self).__init__(*args, **kwargs)
     self.etag = quote_etag(etag)
开发者ID:Dlotan,项目名称:flask-restplus,代码行数:3,代码来源:test_errors.py

示例10: set_etag

 def set_etag(self, etag, weak=False):
     """Set the etag, and override the old one if there was one."""
     self.headers['ETag'] = quote_etag(etag, weak)
开发者ID:danaspiegel,项目名称:softball_stat_manager,代码行数:3,代码来源:wrappers.py

示例11: check_304_response

 def check_304_response(res):
     assert res.status_code == 304
     # check that the ETag is correct
     assert unquote_etag(res.headers['ETag']) == \
         unquote_etag(quote_etag('abc'))
开发者ID:tiborsimko,项目名称:invenio-rest,代码行数:5,代码来源:test_invenio_rest.py

示例12: set_etag

 def set_etag(self, etag, weak = False):
     self.headers['ETag'] = quote_etag(etag, weak)
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:2,代码来源:wrappers.py


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