Module src.jsonid.registry_matchers

Functions to support processing of the registry.

Functions

def at_goto(marker: dict, data: dict) ‑> dict
Expand source code
def at_goto(marker: dict, data: dict) -> dict:
    """Match data against a regular expression."""
    k = marker[MARKER_GOTO]
    try:
        return data[k]
    except KeyError:
        return data

Match data against a regular expression.

def at_index(marker: dict, data: dict) ‑> dict
Expand source code
def at_index(marker: dict, data: dict) -> dict:
    """Provide an ability to investigate an indeex."""
    idx = marker[MARKER_INDEX]
    try:
        data = data[idx]
        return data
    except IndexError:
        return data

Provide an ability to investigate an indeex.

def contains_match(marker: dict, data: dict) ‑> bool
Expand source code
def contains_match(marker: dict, data: dict) -> bool:
    """Match data against a regular expression."""
    k = marker[MARKER_KEY]
    v = None
    try:
        v = data[k]
    except KeyError:
        return False
    if not isinstance(v, str):
        return False
    match_pattern = marker[MARKER_CONTAINS]
    return match_pattern in v

Match data against a regular expression.

def endswith_match(marker: dict, data: dict) ‑> bool
Expand source code
def endswith_match(marker: dict, data: dict) -> bool:
    """Match data against a regular expression."""
    k = marker[MARKER_KEY]
    v = None
    try:
        v = data[k]
    except KeyError:
        return False
    if not isinstance(v, str):
        return False
    match_pattern = marker[MARKER_ENDSWITH]
    return v.endswith(match_pattern)

Match data against a regular expression.

def is_match(marker: dict, data: dict) ‑> bool
Expand source code
def is_match(marker: dict, data: dict) -> bool:
    """Match data against a regular expression."""
    k = marker[MARKER_KEY]
    v = None
    try:
        v = data[k]
    except KeyError:
        return False
    match_pattern = marker[MARKER_IS]
    return v == match_pattern

Match data against a regular expression.

def is_type(marker: dict, data: dict) ‑> bool
Expand source code
def is_type(marker: dict, data: dict) -> bool:
    """Match data against type only."""
    k = marker[MARKER_KEY]
    v = None
    try:
        v = data[k]
    except KeyError:
        return False
    match_pattern = marker[MARKER_IS_TYPE]
    try:
        if isinstance(v, match_pattern):
            return True
    except TypeError:
        pass
    return False

Match data against type only.

def key_exists_match(marker: dict, data: dict) ‑> bool
Expand source code
def key_exists_match(marker: dict, data: dict) -> bool:
    """Match data against a regular expression."""
    k = marker[MARKER_KEY]
    try:
        data[k]
    except KeyError:
        return False
    return True

Match data against a regular expression.

def key_no_exist_match(marker: dict, data: dict) ‑> bool
Expand source code
def key_no_exist_match(marker: dict, data: dict) -> bool:
    """Match data against a regular expression."""
    k = marker[MARKER_KEY]
    try:
        data[k]
    except KeyError:
        return True
    return False

Match data against a regular expression.

def regex_match(marker: dict, data: dict) ‑> bool
Expand source code
def regex_match(marker: dict, data: dict) -> bool:
    """Match data against a regular expression."""
    k = marker[MARKER_KEY]
    v = None
    try:
        v = data[k]
    except KeyError:
        return False
    if not isinstance(v, str):
        return False
    match_pattern = marker[MARKER_REGEX]
    return re.search(match_pattern, v)

Match data against a regular expression.

def startswith_match(marker: dict, data: dict) ‑> bool
Expand source code
def startswith_match(marker: dict, data: dict) -> bool:
    """Match data against a regular expression."""
    k = marker[MARKER_KEY]
    v = None
    try:
        v = data[k]
    except KeyError:
        return False
    if not isinstance(v, str):
        return False
    match_pattern = marker[MARKER_STARTSWITH]
    return v.startswith(match_pattern)

Match data against a regular expression.