import re


def read_cpr(path):
    """Read and parse a CPR file. Return masks, which are (id, RLE data).

    Note: Python 3.6.4 docs say its XML module is not secure, se we use regexp.
    """
    # Example: <Mask id="123">[12 34 56]</Mask>
    mask_pattern = r'<Mask\s.*?id="(.*?)".*?>.*?\[(.*?)\].*?</Mask>'
    text = path.read_text()
    matches = re.finditer(mask_pattern, text, flags=re.DOTALL)

    def parse_match(m):
        number, mask = m.groups()
        number = int(number)
        mask = [int(x) for x in mask.split()]
        return number, mask

    masks = [parse_match(x) for x in matches]
    return masks