# Path: app.py



import os
import sys
import functools
import hashlib
import flask
import werkzeug
from app import app
    def wrapper(*args, **kwargs):
        flask.g.condtnl_etags_start = True
        return func(*args, **kwargs)
    return wrapper


_old_set_etag = werkzeug.ETagResponseMixin.set_etag
@functools.wraps(werkzeug.ETagResponseMixin.set_etag)
def _new_set_etag(self, etag, weak=False):
    # only check the first time through; when called twice
    # we're modifying
    if (hasattr(flask.g, 'condtnl_etags_start') and
                                flask.g.condtnl_etags_start):
        if flask.request.method in ('PUT', 'DELETE', 'PATCH'):
            if not flask.request.if_match:
                raise PreconditionRequired
            if etag not in flask.request.if_match:
                flask.abort(412)
        elif (flask.request.method == 'GET' and
              flask.request.if_none_match and
              etag in flask.request.if_none_match):
            raise NotModified
        flask.g.condtnl_etags_start = False
    _old_set_etag(self, etag, weak)
werkzeug.ETagResponseMixin.set_etag = _new_set_etag


d = {'a': 'This is "a".\n', 'b': 'This is "b".\n'}



# Path: app.py



# Path: decorators/conditional_requests_with_etags.py
import os
import sys
import functools
import hashlib
import flask
import werkzeug
from app import app

    def wrapper(*args, **kwargs):
        flask.g.condtnl_etags_start = True
        return func(*args, **kwargs)
    return wrapper


_old_set_etag = werkzeug.ETagResponseMixin.set_etag
@functools.wraps(werkzeug.ETagResponseMixin.set_etag)
def _new_set_etag(self, etag, weak=False):
    # only check the first time through; when called twice
    # we're modifying
    if (hasattr(flask.g, 'condtnl_etags_start') and
                                flask.g.condtnl_etags_start):
        if flask.request.method in ('PUT', 'DELETE', 'PATCH'):
            if not flask.request.if_match:
                raise PreconditionRequired
            if etag not in flask.request.if_match:
                flask.abort(412)
        elif (flask.request.method == 'GET' and
              flask.request.if_none_match and
              etag in flask.request.if_none_match):
            raise NotModified
        flask.g.condtnl_etags_start = False
    _old_set_etag(self, etag, weak)
werkzeug.ETagResponseMixin.set_etag = _new_set_etag


d = {'a': 'This is "a".\n', 'b': 'This is "b".\n'}



@app.route('/<path>', methods=['GET', 'PUT', 'DELETE', 'PATCH'])