file generation for catalog signing nonbinary contents def cansignfile return file isfile and file stat stsize public def writecatalogtarget files with target openw encodingutf8 as cat cat writecatalogtemplate formattargettarget cat writelineshashn formatn f for n f in files if cansignf catalogheader name target stem cat resultdir target parent publicversion 1 catalogversion 2 hashalgorithms sha256 pagehashes false encodingtype catalogfiles
__author__ = "Steve Dower <steve.dower@python.org>"
__version__ = "3.8"


__all__ = ["PYTHON_CAT_NAME", "PYTHON_CDF_NAME"]


def public(f):
    __all__.append(f.__name__)
    return f


PYTHON_CAT_NAME = "python.cat"
PYTHON_CDF_NAME = "python.cdf"


CATALOG_TEMPLATE = r


def can_sign(file):
    return file.is_file() and file.stat().st_size


@public
def write_catalog(target, files):
    with target.open("w", encoding="utf-8") as cat:
        cat.write(CATALOG_TEMPLATE.format(target=target))
        cat.writelines("<HASH>{}={}\n".format(n, f) for n, f in files if can_sign(f))