Try to match an ETag against a header value.

    If `weak` is True, uses the weak comparison function.

def match_etag(etag, header, weak=False):
    """Try to match an ETag against a header value.

    If `weak` is True, uses the weak comparison function.
    """
    if etag is None:
        return False
    m = etag_re.match(etag)
    if not m:
        raise ValueError("Not a well-formed ETag: '%s'" % etag)
    (is_weak, etag) = m.groups()
    parsed_header = parse_etag_header(header)
    if parsed_header == '*':
        return True
    if is_weak and not weak:
        return False
    if weak:
        return etag in [t[1] for t in parsed_header]
    else:
        return etag in [t[1] for t in parsed_header if not t[0]]