def reg_copy(reg, keys=None):
    """
    Make a copy of a subset of a registry.

    :param reg: source registry
    :param keys: keys of registry items to copy
    :return: copied registry subset
    """
    if keys is None:
        keys = reg.keys()
    reg_cls = type(reg)
    new_reg = reg_cls()
    mk = {}  # empty dictionary for meta keys
    # loop over registry meta names
    for m in reg_cls.meta_names:
        mstar = getattr(reg, m, None)  # current value of metakey in registry
        if not mstar:
            # if there is no value, the value is empty or None, set it to None
            # it's never false or zero, should be dictionary of reg items
            mk[m] = None
            continue
        mk[m] = {}  # emtpy dictionary of registry meta
        # loop over keys to copy and set values of meta keys for each reg item
        for k in keys:
            kstar = mstar.get(k)
            # if key exists in registry meta and is not None, then copy it
            if kstar is not None:
                mk[m][k] = kstar
    new_reg.register({k: reg[k] for k in keys}, **mk)
    return new_reg
def reg_copy ( reg , keys = None ) : if keys is None : keys = reg . keys ( ) reg_cls = type ( reg ) new_reg = reg_cls ( ) mk = { } for m in reg_cls . meta_names : mstar = getattr ( reg , m , None ) if not mstar : mk [ m ] = None continue mk [ m ] = { } for k in keys : kstar = mstar . get ( k ) if kstar is not None : mk [ m ] [ k ] = kstar new_reg . register ( { k : reg [ k ] for k in keys } , ** mk ) return new_reg
Make a copy of a subset of a registry.

    :param reg: source registry
    :param keys: keys of registry items to copy
    :return: copied registry subset