import re


def _check_if_item_allowed(item_name, allow_patterns, disallow_patterns):
    """
    Check if an item with ``item_name`` is allowed based on ``allow_patterns``
    and ``disallow_patterns``.

    Parameters
    ----------
    item_name: str
        Name of the item.
    allow_patterns: list(str)
        Selected item should match at least one of the re patterns. If the value is ``[None]``
        then all items are selected. If ``[]``, then no items are selected.
    disallow_patterns: list(str)
        Items are deselected based on re patterns in the list: if an item matches at least one
        of the patterns, it is deselected. If the value is ``[None]`` or ``[]`` then no items
        are deselected.

    Returns
    -------
    boolean
        Indicates if the item is permitted based on ``allow_patterns`` and ``disallow_patterns``.
    """
    item_is_allowed = False

    if allow_patterns:
        if allow_patterns[0] is None:
            item_is_allowed = True
        else:
            for pattern in allow_patterns:
                if re.search(pattern, item_name):
                    item_is_allowed = True
                    break

    if item_is_allowed:
        if disallow_patterns and (disallow_patterns[0] is not None):
            for pattern in disallow_patterns:
                if re.search(pattern, item_name):
                    item_is_allowed = False
                    break

    return item_is_allowed