Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(20)  |  Call(10)  |  Derive(0)  |  Import(10)
Factory for functions needed by etree, dependent on whether
cElementTree or ElementTree is used.

        def _generate_etree_functions(DefusedXMLParser, _TreeBuilder,
            _IterParseIterator, _parse, _iterparse):
    """Factory for functions needed by etree, dependent on whether
    cElementTree or ElementTree is used."""

    def parse(source, parser=None, forbid_dtd=False, forbid_entities=True,
              forbid_external=True):
        if parser is None:
            parser = DefusedXMLParser(target=_TreeBuilder(),
                                      forbid_dtd=forbid_dtd,
                                      forbid_entities=forbid_entities,
                                      forbid_external=forbid_external)
        return _parse(source, parser)

    if PY26 or PY31:
        def bind(xmlparser, funcname, hookname):
            func = getattr(DefusedXMLParser, funcname)
            if PY26:
                # unbound -> function
                func = func.__func__
                method = MethodType(func, xmlparser, xmlparser.__class__)
            else:
                method = MethodType(func, xmlparser)
            # set hook
            setattr(xmlparser._parser, hookname, method)

        def iterparse(source, events=None, forbid_dtd=False,
                      forbid_entities=True, forbid_external=True):
            it = _iterparse(source, events)
            xmlparser = it._parser
            if forbid_dtd:
                bind(xmlparser, "defused_start_doctype_decl",
                     "StartDoctypeDeclHandler")
            if forbid_entities:
                bind(xmlparser, "defused_entity_decl",
                     "EntityDeclHandler")
                bind(xmlparser, "defused_unparsed_entity_decl",
                     "UnparsedEntityDeclHandler")
            if forbid_external:
                bind(xmlparser, "defused_external_entity_ref_handler",
                     "ExternalEntityRefHandler")
            return it
    elif PY3:
        def iterparse(source, events=None, parser=None, forbid_dtd=False,
                      forbid_entities=True, forbid_external=True):
            close_source = False
            if not hasattr(source, "read"):
                source = open(source, "rb")
                close_source = True
            if not parser:
                parser = DefusedXMLParser(target=_TreeBuilder(),
                                          forbid_dtd=forbid_dtd,
                                          forbid_entities=forbid_entities,
                                          forbid_external=forbid_external)
            return _IterParseIterator(source, events, parser, close_source)
    else:
        # Python 2.7
        def iterparse(source, events=None, parser=None, forbid_dtd=False,
                      forbid_entities=True, forbid_external=True):
            if parser is None:
                parser = DefusedXMLParser(target=_TreeBuilder(),
                                          forbid_dtd=forbid_dtd,
                                          forbid_entities=forbid_entities,
                                          forbid_external=forbid_external)
            return _iterparse(source, events, parser)

    def fromstring(text, forbid_dtd=False, forbid_entities=True,
                   forbid_external=True):
        parser = DefusedXMLParser(target=_TreeBuilder(),
                                  forbid_dtd=forbid_dtd,
                                  forbid_entities=forbid_entities,
                                  forbid_external=forbid_external)
        parser.feed(text)
        return parser.close()


    return parse, iterparse, fromstring
        


src/s/d/sdetools-4.4.1/sdetools/extlib/defusedxml/ElementTree.py   sdetools(Download)
from xml.etree.ElementTree import tostring
 
from .common import (DTDForbidden, EntitiesForbidden,
                     ExternalReferenceForbidden, _generate_etree_functions)
 
XMLTreeBuilder = XMLParse = DefusedXMLParser
 
parse, iterparse, fromstring = _generate_etree_functions(DefusedXMLParser,
        _TreeBuilder, _IterParseIterator, _parse, _iterparse)
XML = fromstring

src/t/v/tvrenamr-3.6.0/tvrenamr/vendor/defusedxml/ElementTree.py   tvrenamr(Download)
from xml.etree.ElementTree import tostring
 
from .common import (DTDForbidden, EntitiesForbidden,
                     ExternalReferenceForbidden, _generate_etree_functions)
 
XMLTreeBuilder = XMLParse = DefusedXMLParser
 
parse, iterparse, fromstring = _generate_etree_functions(DefusedXMLParser,
        _TreeBuilder, _IterParseIterator, _parse, _iterparse)
XML = fromstring

src/t/v/tvrenamr-HEAD/tvrenamr/vendor/defusedxml/ElementTree.py   tvrenamr(Download)
from xml.etree.ElementTree import tostring
 
from .common import (DTDForbidden, EntitiesForbidden,
                     ExternalReferenceForbidden, _generate_etree_functions)
 
XMLTreeBuilder = XMLParse = DefusedXMLParser
 
parse, iterparse, fromstring = _generate_etree_functions(DefusedXMLParser,
        _TreeBuilder, _IterParseIterator, _parse, _iterparse)
XML = fromstring

src/s/d/sdetools-HEAD/sdetools/extlib/defusedxml/ElementTree.py   sdetools(Download)
from xml.etree.ElementTree import tostring
 
from .common import (DTDForbidden, EntitiesForbidden,
                     ExternalReferenceForbidden, _generate_etree_functions)
 
XMLTreeBuilder = XMLParse = DefusedXMLParser
 
parse, iterparse, fromstring = _generate_etree_functions(DefusedXMLParser,
        _TreeBuilder, _IterParseIterator, _parse, _iterparse)
XML = fromstring

src/d/e/defusedxml-0.4.1/defusedxml/ElementTree.py   defusedxml(Download)
from xml.etree.ElementTree import tostring
 
from .common import (DTDForbidden, EntitiesForbidden,
                     ExternalReferenceForbidden, _generate_etree_functions)
 
XMLTreeBuilder = XMLParse = DefusedXMLParser
 
parse, iterparse, fromstring = _generate_etree_functions(DefusedXMLParser,
        _TreeBuilder, _IterParseIterator, _parse, _iterparse)
XML = fromstring

src/s/d/sdetools-4.4.1/sdetools/extlib/defusedxml/cElementTree.py   sdetools(Download)
 
from .ElementTree import DefusedXMLParser, _IterParseIterator
from .common import _generate_etree_functions
 
__origin__ = "xml.etree.cElementTree"
 
XMLTreeBuilder = XMLParse = DefusedXMLParser
 
parse, iterparse, fromstring = _generate_etree_functions(DefusedXMLParser,

src/t/v/tvrenamr-3.6.0/tvrenamr/vendor/defusedxml/cElementTree.py   tvrenamr(Download)
 
from .ElementTree import DefusedXMLParser, _IterParseIterator
from .common import _generate_etree_functions
 
__origin__ = "xml.etree.cElementTree"
 
XMLTreeBuilder = XMLParse = DefusedXMLParser
 
parse, iterparse, fromstring = _generate_etree_functions(DefusedXMLParser,

src/t/v/tvrenamr-HEAD/tvrenamr/vendor/defusedxml/cElementTree.py   tvrenamr(Download)
 
from .ElementTree import DefusedXMLParser, _IterParseIterator
from .common import _generate_etree_functions
 
__origin__ = "xml.etree.cElementTree"
 
XMLTreeBuilder = XMLParse = DefusedXMLParser
 
parse, iterparse, fromstring = _generate_etree_functions(DefusedXMLParser,

src/s/d/sdetools-HEAD/sdetools/extlib/defusedxml/cElementTree.py   sdetools(Download)
 
from .ElementTree import DefusedXMLParser, _IterParseIterator
from .common import _generate_etree_functions
 
__origin__ = "xml.etree.cElementTree"
 
XMLTreeBuilder = XMLParse = DefusedXMLParser
 
parse, iterparse, fromstring = _generate_etree_functions(DefusedXMLParser,

src/d/e/defusedxml-0.4.1/defusedxml/cElementTree.py   defusedxml(Download)
 
from .ElementTree import DefusedXMLParser, _IterParseIterator
from .common import _generate_etree_functions
 
__origin__ = "xml.etree.cElementTree"
 
XMLTreeBuilder = XMLParse = DefusedXMLParser
 
parse, iterparse, fromstring = _generate_etree_functions(DefusedXMLParser,