(header)
Verifies that header value is a string which doesn't contain
    leading whitespace or return characters. This prevents unintended
    header injection.

    :param header: tuple, in the format (name, value).
Verifies that header value is a string which doesn't contain
    leading whitespace or return characters. This prevents unintended
    header injection.
Verifies that header value is a string which doesn t contain leading whitespace or return characters . This prevents unintended header injection .
def check_header_validity(header):
    """Verifies that header value is a string which doesn't contain
    leading whitespace or return characters. This prevents unintended
    header injection.

    :param header: tuple, in the format (name, value).
    """
    name, value = header

    if isinstance(value, bytes):
        pat = _CLEAN_HEADER_REGEX_BYTE
    else:
        pat = _CLEAN_HEADER_REGEX_STR
    try:
        if not pat.match(value):
            raise InvalidHeader("Invalid return character or leading space in header: %s" % name)
    except TypeError:
        raise InvalidHeader("Value for header {%s: %s} must be of type str or "
                            "bytes, not %s" % (name, value, type(value)))
def check_header_validity ( header ) : name , value = header if isinstance ( value , bytes ) : pat = _CLEAN_HEADER_REGEX_BYTE else : pat = _CLEAN_HEADER_REGEX_STR try : if not pat . match ( value ) : raise InvalidHeader ( "Invalid return character or leading space in header: %s" % name ) except TypeError : raise InvalidHeader ( "Value for header {%s: %s} must be of type str or " "bytes, not %s" % ( name , value , type ( value ) ) )