Given a namespace, replaces 'namespace__' with %%%NAMESPACE%%% for all
        files and ___NAMESPACE___ in all filenames in the zip

def zip_tokenize_namespace(zip_src, namespace, logger=None):
    """ Given a namespace, replaces 'namespace__' with %%%NAMESPACE%%% for all
        files and ___NAMESPACE___ in all filenames in the zip
    """
    if not namespace:
        return zip_src

    namespace_prefix = "{}__".format(namespace)
    lightning_namespace = "{}:".format(namespace)
    zip_dest = zipfile.ZipFile(io.BytesIO(), "w", zipfile.ZIP_DEFLATED)
    for name in zip_src.namelist():
        content = zip_src.read(name)
        try:
            content = content.decode("utf-8")
        except UnicodeDecodeError:
            # Probably a binary file; leave it untouched
            pass
        else:
            content = content.replace(namespace_prefix, "%%%NAMESPACE%%%")
            content = content.replace(lightning_namespace, "%%%NAMESPACE_OR_C%%%")
            content = content.encode("utf-8")
            name = name.replace(namespace_prefix, "___NAMESPACE___")
        zip_dest.writestr(name, content)
    return zip_dest