from typing import Dict
from typing import Optional
from typing import Iterable


def get_attrib_value(attribs: Dict[str, str],
                     name: str,
                     ns: str,
                     value_prefixes: Optional[Iterable[str]] = None) -> Optional[str]:
    """
    Retrieves the value of an attribute from a dict of `etree.Element` attributes based on its name
    and namespace. The value could be prefixed by any string so it has to be provided in order to
    not be considered in the returned value.

    :param attribs:
    :param name:
    :param ns: namespace
    :param value_prefixes:
    :return:
    """
    value_prefixes = value_prefixes or []
    result = attribs.get(f'{{{ns}}}{name}')

    if result is None:
        return

    for value_prefix in value_prefixes:
        if result.startswith(value_prefix):
            result = result[len(value_prefix):]
            break

    return result