Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
__init__.py68 linesDownload Raw Back to defusedxml
1# defusedxml2#3# Copyright (c) 2013 by Christian Heimes <christian@python.org>4# Licensed to PSF under a Contributor Agreement.5# See https://www.python.org/psf/license for licensing details.6"""Defuse XML bomb denial of service vulnerabilities7"""8from __future__ import print_function, absolute_import9 10import warnings11 12from .common import (13    DefusedXmlException,14    DTDForbidden,15    EntitiesForbidden,16    ExternalReferenceForbidden,17    NotSupportedError,18    _apply_defusing,19)20 21 22def defuse_stdlib():23    """Monkey patch and defuse all stdlib packages24 25    :warning: The monkey patch is an EXPERIMETNAL feature.26    """27    defused = {}28 29    with warnings.catch_warnings():30        from . import cElementTree31    from . import ElementTree32    from . import minidom33    from . import pulldom34    from . import sax35    from . import expatbuilder36    from . import expatreader37    from . import xmlrpc38 39    xmlrpc.monkey_patch()40    defused[xmlrpc] = None41 42    defused_mods = [43        cElementTree,44        ElementTree,45        minidom,46        pulldom,47        sax,48        expatbuilder,49        expatreader,50    ]51 52    for defused_mod in defused_mods:53        stdlib_mod = _apply_defusing(defused_mod)54        defused[defused_mod] = stdlib_mod55 56    return defused57 58 59__version__ = "0.7.1"60 61__all__ = [62    "DefusedXmlException",63    "DTDForbidden",64    "EntitiesForbidden",65    "ExternalReferenceForbidden",66    "NotSupportedError",67]68 
codekingpro/portable-devtools · Team Ai