from typing import Sequence


def parse_sequence(
    raw_value: str, delimiter: str = ",", bounds: str = "", values_can_be_quoted=True
) -> Sequence[str]:
    """Parse a single string into a sequence of strings.
    This is similar to ast.parse_literal but is meant to support non-python reprs and more types

    raw_value: the string to parse
    delimiter: the token to separate values by. This token is not kept
    bounds: zero, one, or two tokens that signify the start and end of the sequence. These tokens are not kept
        if the empty sting, the start and end are assumed to be the beginning and end of raw_value
        if a single character, it will be looked for to both start and end the sequence
        if two characters, the first one will start the sequence and the second one will end it
    values_can_be_quoted: if True values between delimiters can be surrounded in single or double quotes. These quotes are not kept
        if False any quotes are assumed to be part of the value

    whitespace is assumed to be insignificant and is removed
        unless the delimiter is whitespace, then it is significant but not kept
        unless values_can_be_quoted is True in which case whitespace within quotes are significant and kept
    raw_value is assumed to contain one (to be parsed) sequence
    """
    if not delimiter:
        raise ValueError("Delimiter cannot be empty")
    if len(bounds) < 2:
        bound_start = raw_value.find(bounds[0:1])
        bound_end = raw_value.rfind(bounds[0:1])
    else:
        bound_start = raw_value.find(bounds[0]) + 1
        bound_end = raw_value.find(bounds[1])
    if bound_start < 0 or bound_end < 0 or bound_start > bound_end:
        raise ValueError(f"raw_value does not contain both bounds {bounds}")
    working_value = raw_value[bound_start:bound_end]
    working_value = working_value.strip()

    seq = []
    for item in working_value.split(delimiter):
        item = item.strip()
        if values_can_be_quoted and len(item) > 1 and item[0] == item[-1] and item[0] in ("'", '"'):
            item = item[1:-1]
        if item:
            seq.append(item)
    return seq