Python xml.sax.parseString() Examples

The following are 7 code examples of xml.sax.parseString(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module xml.sax , or try the search function .
Example #1
Source File: xml_sax.py    From flake8-bandit with MIT License 6 votes vote down vote up
def main():
    xmlString = "<note>\n<to>Tove</to>\n<from>Jani</from>\n<heading>Reminder</heading>\n<body>Don't forget me this weekend!</body>\n</note>"
    # bad
    xml.sax.parseString(xmlString, ExampleContentHandler())
    xml.sax.parse('notaxmlfilethatexists.xml', ExampleContentHandler())
    sax.parseString(xmlString, ExampleContentHandler())
    sax.parse('notaxmlfilethatexists.xml', ExampleContentHandler)

    # good
    defusedxml.sax.parseString(xmlString, ExampleContentHandler())

    # bad
    xml.sax.make_parser()
    sax.make_parser()
    print('nothing')
    # good
    defusedxml.sax.make_parser() 
Example #2
Source File: upnp.py    From p2ptv-pi with MIT License 5 votes vote down vote up
def parse(self, desc):
        sax.parseString(desc, self) 
Example #3
Source File: upnp.py    From p2ptv-pi with MIT License 5 votes vote down vote up
def parse(self, resp):
        sax.parseString(resp, self) 
Example #4
Source File: xml_sax.py    From bandit with Apache License 2.0 5 votes vote down vote up
def main():
    xmlString = "<note>\n<to>Tove</to>\n<from>Jani</from>\n<heading>Reminder</heading>\n<body>Don't forget me this weekend!</body>\n</note>"
    # bad
    xml.sax.parseString(xmlString, ExampleContentHandler())
    xml.sax.parse('notaxmlfilethatexists.xml', ExampleContentHandler())
    sax.parseString(xmlString, ExampleContentHandler())
    sax.parse('notaxmlfilethatexists.xml', ExampleContentHandler)

    # good
    defusedxml.sax.parseString(xmlString, ExampleContentHandler())

    # bad
    xml.sax.make_parser()
    sax.make_parser()
    print('nothing')
    # good
    defusedxml.sax.make_parser() 
Example #5
Source File: get_pypi_packages_metadata.py    From depsy with MIT License 5 votes vote down vote up
def fetch_index():
    """Return an iterable of every project name on PyPI."""

    r = requests.get('https://pypi.python.org/simple/')
    sax_handler = PyPIIndexHandler()
    sax.parseString(r.text, sax_handler)
    return sax_handler.projects 
Example #6
Source File: topology.py    From BioBlender with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __init__(self, topologyFile):
		""" Initialize with the topology file reference ready for reading """
		handler = TopologyHandler()
		sax.make_parser()
		sax.parseString(topologyFile.read(), handler)
		self.residues = handler.residues 
Example #7
Source File: definitions.py    From BioBlender with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def __init__(self):
        """
            Create a new Definition Object
        """
        self.map = {}
        self.patches = {}

        handler = DefinitionHandler()
        sax.make_parser()

        for path in [AAPATH, NAPATH]:
            defpath = getDatFile(path)
            if defpath == "":
                raise ValueError, "%s not found!" % path

            file = open(defpath)
            sax.parseString(file.read(), handler)
            file.close()

            self.map.update(handler.map)
    
        # Now handle patches

        defpath = getDatFile(PATCHPATH)
        if defpath == "":
            raise ValueError, "%s not found!" % PATCHPATH
     
        handler.map = {}
        file = open(defpath)
        sax.parseString(file.read(), handler)
        file.close()

        # Apply specific patches to the reference object, allowing users
        #  to specify protonation states in the PDB file
        
        for patch in handler.patches:
            if patch.newname != "":

                # Find all residues matching applyto

                resnames = self.map.keys()
                for name in resnames:
                    regexp = re.compile(patch.applyto).match(name)
                    if not regexp: continue
                    newname = patch.newname.replace("*", name)
                    self.addPatch(patch, name, newname)
                  

            # Either way, make sure the main patch name is available
            
            self.addPatch(patch, patch.applyto, patch.name)