Parse a header containing one or more ETags or a wildcard ('*').

    Returns the string '*' or a list of ETags as (weak, etag) tuples.
    `weak` is the prefix designating a weak ETag, or the empty string.
    `etag` is the ETag (including quotes) with the weak prefix stripped
    off. Returns an empty list if the header could not be parsed.

    Example:

    >>> parse_etag_header('*')
    '*'
    >>> parse_etag_header('"foo"  ')
    [('', '"foo"')]
    >>> parse_etag_header('"foo", w/"bar", W/"baz"')
    [('', '"foo"'), ('w/', '"bar"'), ('W/', '"baz"')]
    >>> parse_etag_header('invalid')
    []

def parse_etag_header(header):
    """Parse a header containing one or more ETags or a wildcard ('*').

    Returns the string '*' or a list of ETags as (weak, etag) tuples.
    `weak` is the prefix designating a weak ETag, or the empty string.
    `etag` is the ETag (including quotes) with the weak prefix stripped
    off. Returns an empty list if the header could not be parsed.

    Example:

    >>> parse_etag_header('*')
    '*'
    >>> parse_etag_header('"foo"  ')
    [('', '"foo"')]
    >>> parse_etag_header('"foo", w/"bar", W/"baz"')
    [('', '"foo"'), ('w/', '"bar"'), ('W/', '"baz"')]
    >>> parse_etag_header('invalid')
    []

    """
    m = etag_header_re.match(header.strip())
    if not m:
        return []
    if m.group(1):  # star
        return m.group(1)
    else:  # list of entity tags
        return etag_re.findall(header)