<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def id_matches(unique_id, target_name, target_package, nodetypes, model):
 """Return True if the unique ID matches the given name, package, and type. If package is None, any package is allowed. nodetypes should be a container of NodeTypes that implements the 'in' operator. """

    node_type = model.get('resource_type', 'node')
    node_parts = unique_id.split('.', 2)
    if len(node_parts) != 3:
        msg = "unique_id {} is malformed".format(unique_id)
        dbt.exceptions.raise_compiler_error(msg, model)

    resource_type, package_name, node_name = node_parts
    if node_type == NodeType.Source:
        if node_name.count('.') != 1:
            msg = "{} names must contain exactly 1 '.' character"\
                .format(node_type)
            dbt.exceptions.raise_compiler_error(msg, model)
    else:
        if '.' in node_name:
            msg = "{} names cannot contain '.' characters".format(node_type)
            dbt.exceptions.raise_compiler_error(msg, model)

    if resource_type not in nodetypes:
        return False

    if target_name != node_name:
        return False

    return target_package is None or target_package == package_name