Exemplo n.º 1
0
 def _on_obj_ready(self, parent, cls, response):
     body = response.read()
     if response.status == 200 and body:
         obj = cls(parent)
         h = XmlHandler(obj, parent)
         sax_parse(body, h)
         return obj
     else:
         raise self._for_status(response, body)
Exemplo n.º 2
0
 def _on_status_ready(self, parent, response):
     body = response.read()
     if response.status == 200 and body:
         rs = ResultSet()
         h = XmlHandler(rs, parent)
         sax_parse(body, h)
         return rs.status
     else:
         raise self._for_status(response, body)
Exemplo n.º 3
0
 def _on_obj_ready(self, parent, cls, response):
     body = response.read()
     if response.status == 200 and body:
         obj = cls(parent)
         h = XmlHandler(obj, parent)
         sax_parse(body, h)
         return obj
     else:
         raise self._for_status(response, body)
Exemplo n.º 4
0
 def _on_status_ready(self, parent, response):
     body = response.read()
     if response.status == 200 and body:
         rs = ResultSet()
         h = XmlHandler(rs, parent)
         sax_parse(body, h)
         return rs.status
     else:
         raise self._for_status(response, body)
Exemplo n.º 5
0
def parse(xml, schema, tmp_dict):
    """
    xml should be a filename or a file-like object containing xml data.

    schema should be a Tag object defining the structure of the xml document.

    tmp_dict is used by parser functions in Tag objects to share data. It can
    be pre-populated with values.
    """
    sax_parse(xml, SaxHandler(schema, tmp_dict))
Exemplo n.º 6
0
Arquivo: parser.py Projeto: sk/gnumed
def parse(xml, schema, tmp_dict):
    """
    xml should be a filename or a file-like object containing xml data.

    schema should be a Tag object defining the structure of the xml document.

    tmp_dict is used by parser functions in Tag objects to share data. It can
    be pre-populated with values.
    """
    if isinstance(xml, unicode):
        # Workaround for "Sax parser crashes if given unicode file name" bug:
        # http://bugs.python.org/issue11159
        xml = xml.encode(sys.getfilesystemencoding())
    sax_parse(xml, SaxHandler(schema, tmp_dict))
Exemplo n.º 7
0
def parse(xml, schema, tmp_dict):
    """
    xml should be a filename or a file-like object containing xml data.

    schema should be a Tag object defining the structure of the xml document.

    tmp_dict is used by parser functions in Tag objects to share data. It can
    be pre-populated with values.
    """
    if isinstance(xml, unicode):
        # Workaround for "Sax parser crashes if given unicode file name" bug:
        # http://bugs.python.org/issue11159
        xml = xml.encode(sys.getfilesystemencoding())
    sax_parse(xml, SaxHandler(schema, tmp_dict))
Exemplo n.º 8
0
#!/usr/bin/env python
# encoding: utf-8

from xml.etree.ElementTree import parse
from xml.sax import parse as sax_parse

# <?xml version="1.0"?>
# <!DOCTYPE lolz [
#         <!ENTITY lol "lol">
#         <!ELEMENT lolz (#PCDATA)>
#         <!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
#         <!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;">
#         <!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
#         <!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">
#         <!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">
#         <!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">
#         <!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">
#         <!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">
#         <!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">
# ]>
# <lolz>&lol9;</lolz>
sax_parse("./poc.xml")
# root = parse("./poc.xml")
Exemplo n.º 9
0
def parse(file):
    dh = SignatureHandler()
    sax_parse(file, dh)
    return dh._root
Exemplo n.º 10
0
def parse(file):
    dh = SignatureHandler()
    sax_parse(file, dh)
    return dh._root
Exemplo n.º 11
0
def get_all_stations(file: Path = DEFAULT_GEO_PATH) -> List[OSMNode]:
    with file.open("rb") as stream:
        handler = OSMStationHandler()
        sax_parse(stream, handler)
        return handler.stations