Python xml.sax 模块,make_parser() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用xml.sax.make_parser()

项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def scan(self):
        """Parse the *.qrc* files"""
        if not has_xml:
            Logs.error('no xml support was found, the rcc dependencies will be incomplete!')
            return ([], [])

        parser = make_parser()
        curHandler = XMLHandler()
        parser.setContentHandler(curHandler)
        fi = open(self.inputs[0].abspath(), 'r')
        try:
            parser.parse(fi)
        finally:
            fi.close()

        nodes = []
        names = []
        root = self.inputs[0].parent
        for x in curHandler.files:
            nd = root.find_resource(x)
            if nd: nodes.append(nd)
            else: names.append(x)
        return (nodes, names)
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def scan(self):
        """Parse the *.qrc* files"""
        if not has_xml:
            Logs.error('no xml support was found, the rcc dependencies will be incomplete!')
            return ([], [])

        parser = make_parser()
        curHandler = XMLHandler()
        parser.setContentHandler(curHandler)
        fi = open(self.inputs[0].abspath(), 'r')
        try:
            parser.parse(fi)
        finally:
            fi.close()

        nodes = []
        names = []
        root = self.inputs[0].parent
        for x in curHandler.files:
            nd = root.find_resource(x)
            if nd: nodes.append(nd)
            else: names.append(x)
        return (nodes, names)
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def scan(self):
        """Parse the *.qrc* files"""
        if not has_xml:
            Logs.error('no xml support was found, the rcc dependencies will be incomplete!')
            return ([], [])

        parser = make_parser()
        curHandler = XMLHandler()
        parser.setContentHandler(curHandler)
        fi = open(self.inputs[0].abspath(), 'r')
        try:
            parser.parse(fi)
        finally:
            fi.close()

        nodes = []
        names = []
        root = self.inputs[0].parent
        for x in curHandler.files:
            nd = root.find_resource(x)
            if nd: nodes.append(nd)
            else: names.append(x)
        return (nodes, names)
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def scan(self):
        """Parse the *.qrc* files"""
        if not has_xml:
            Logs.error('no xml support was found, the rcc dependencies will be incomplete!')
            return ([], [])

        parser = make_parser()
        curHandler = XMLHandler()
        parser.setContentHandler(curHandler)
        fi = open(self.inputs[0].abspath(), 'r')
        try:
            parser.parse(fi)
        finally:
            fi.close()

        nodes = []
        names = []
        root = self.inputs[0].parent
        for x in curHandler.files:
            nd = root.find_resource(x)
            if nd: nodes.append(nd)
            else: names.append(x)
        return (nodes, names)
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def scan(self):
        """Parse the *.qrc* files"""
        if not has_xml:
            Logs.error('no xml support was found, the rcc dependencies will be incomplete!')
            return ([], [])

        parser = make_parser()
        curHandler = XMLHandler()
        parser.setContentHandler(curHandler)
        fi = open(self.inputs[0].abspath(), 'r')
        try:
            parser.parse(fi)
        finally:
            fi.close()

        nodes = []
        names = []
        root = self.inputs[0].parent
        for x in curHandler.files:
            nd = root.find_resource(x)
            if nd: nodes.append(nd)
            else: names.append(x)
        return (nodes, names)
项目:gprime    作者:GenealogyCollective    | 项目源码 | 文件源码
def parse(self):
        """
        Loads the StyleSheets from the associated file, if it exists.
        """
        try:
            if os.path.isfile(self.__file):
                parser = make_parser()
                parser.setContentHandler(SheetParser(self))
                with open(self.__file) as the_file:
                    parser.parse(the_file)
        except (IOError, OSError, SAXParseException):
            pass

#------------------------------------------------------------------------
#
# StyleSheet
#
#------------------------------------------------------------------------
项目:gprime    作者:GenealogyCollective    | 项目源码 | 文件源码
def parse(self):
        """
        Loads the OptionList from the associated file, if it exists.
        """
        try:
            if os.path.isfile(self.filename):
                parser = make_parser()
                parser.setContentHandler(OptionParser(self))
                parser.parse(self.filename)
        except (IOError, OSError, SAXParseException):
            pass

#-------------------------------------------------------------------------
#
# OptionParser
#
#-------------------------------------------------------------------------
项目:gprime    作者:GenealogyCollective    | 项目源码 | 文件源码
def parse(self):
        """
        Loads the :class:`OptionList` from the associated file, if it exists.
        """
        try:
            if os.path.isfile(self.filename):
                parser = make_parser()
                parser.setContentHandler(OptionParser(self))
                with open(self.filename, encoding="utf-8") as the_file:
                    parser.parse(the_file)
        except (IOError, OSError, SAXParseException):
            pass

#-------------------------------------------------------------------------
#
# OptionParser
#
#-------------------------------------------------------------------------
项目:gprime    作者:GenealogyCollective    | 项目源码 | 文件源码
def parse(self):
        """
        Loads the :class:`OptionList` from the associated file, if it exists.
        """
        try:
            if os.path.isfile(self.filename):
                parser = make_parser()
                parser.setContentHandler(DocOptionParser(self))
                with open(self.filename, encoding="utf-8") as the_file:
                    parser.parse(the_file)
        except (IOError, OSError, SAXParseException):
            pass

#------------------------------------------------------------------------
#
# DocOptionParser class
#
#------------------------------------------------------------------------
项目:gprime    作者:GenealogyCollective    | 项目源码 | 文件源码
def parse(self):
        """
        Loads the BookList from the associated file, if it exists.
        """
        try:
            parser = make_parser()
            parser.setContentHandler(BookParser(self, self.dbase))
            with open(self.file) as the_file:
                parser.parse(the_file)
        except (IOError, OSError, ValueError, SAXParseException, KeyError,
                AttributeError):
            LOG.debug("Failed to parse book list", exc_info=True)


#-------------------------------------------------------------------------
#
# BookParser
#
#-------------------------------------------------------------------------
项目:VIA4CVE    作者:cve-search    | 项目源码 | 文件源码
def __init__(self):
    self.name = SOURCE_NAME
    parser    = make_parser()
    handler = SaintHandler()
    _file, r = conf.getFeedData(SOURCE_NAME, SOURCE_FILE)
    parser.setContentHandler(handler)
    parser.parse(BytesIO(_file))
    self.cves   = defaultdict(list)
    self.bids   = defaultdict(list)
    self.osvdbs = defaultdict(list)
    for exploit in handler.exploits:
      data = copy.copy(exploit)
      if data.get('cve'): data.pop('cve')
      if exploit.get('cve'):   self.cves[  exploit['cve']  ].append(data)
      if exploit.get('bid'):   self.bids[  exploit['bid']  ].append(data)
      if exploit.get('osvdb'): self.osvdbs[exploit['osvdb']].append(data)
项目:VIA4CVE    作者:cve-search    | 项目源码 | 文件源码
def __init__(self):
    self.name = "redhat"
    handlers  = [{'handler': RPMHandler(),  'source': 'rpm' },
                 {'handler': RHSAHandler(), 'source': 'rhsa'} ]
    parser    = make_parser()
    self.cves = defaultdict(dict)

    for handler in handlers:
      _file, r = conf.getFeedData(handler['source'],
                                  SOURCES[handler['source']])
      parser.setContentHandler(handler['handler'])
      if type(_file) is bytes:
        _file = BytesIO(_file)
      parser.parse(_file)
      for cve, data in handler['handler'].CVEs.items():
        self.cves[cve].update(data)
项目:VIA4CVE    作者:cve-search    | 项目源码 | 文件源码
def __init__(self):
    self.name = SOURCE_NAME
    parser    = make_parser()
    handler = D2secHandler()
    _file, r = conf.getFeedData(SOURCE_NAME, SOURCE_FILE)
    parser.setContentHandler(handler)
    parser.parse(BytesIO(_file))
    self.cves     = defaultdict(list)
    self.exploits = defaultdict(dict)
    for exploit in handler.exploits:
      _exploit = copy.copy(exploit) # clean exploit to add to the list
      _exploit.pop('refs')
      for ref in exploit.get('refs', []):
        if ref['type'] == 'cve': self.cves[ref['key']].append(_exploit)
        else:
          if ref['key'] not in self.exploits[ref['type']]:
            self.exploits[ref['type']][ref['key']] = []
          self.exploits[ref['type']][ref['key']].append(_exploit)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_make_parser2(self):
        # Creating parsers several times in a row should succeed.
        # Testing this because there have been failures of this kind
        # before.
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()


# ===========================================================================
#
#   saxutils tests
#
# ===========================================================================
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_5027_1(self):
        # The xml prefix (as in xml:lang below) is reserved and bound by
        # definition to http://www.w3.org/XML/1998/namespace.  XMLGenerator had
        # a bug whereby a KeyError is thrown because this namespace is missing
        # from a dictionary.
        #
        # This test demonstrates the bug by parsing a document.
        test_xml = StringIO(
            '<?xml version="1.0"?>'
            '<a:g1 xmlns:a="http://example.com/ns">'
             '<a:g2 xml:lang="en">Hello</a:g2>'
            '</a:g1>')

        parser = make_parser()
        parser.setFeature(feature_namespaces, True)
        result = StringIO()
        gen = XMLGenerator(result)
        parser.setContentHandler(gen)
        parser.parse(test_xml)

        self.assertEqual(result.getvalue(),
                         start + (
                         '<a:g1 xmlns:a="http://example.com/ns">'
                          '<a:g2 xml:lang="en">Hello</a:g2>'
                         '</a:g1>'))
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_make_parser2(self):
        # Creating parsers several times in a row should succeed.
        # Testing this because there have been failures of this kind
        # before.
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()


# ===========================================================================
#
#   saxutils tests
#
# ===========================================================================
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_5027_1(self):
        # The xml prefix (as in xml:lang below) is reserved and bound by
        # definition to http://www.w3.org/XML/1998/namespace.  XMLGenerator had
        # a bug whereby a KeyError is raised because this namespace is missing
        # from a dictionary.
        #
        # This test demonstrates the bug by parsing a document.
        test_xml = StringIO(
            '<?xml version="1.0"?>'
            '<a:g1 xmlns:a="http://example.com/ns">'
             '<a:g2 xml:lang="en">Hello</a:g2>'
            '</a:g1>')

        parser = make_parser()
        parser.setFeature(feature_namespaces, True)
        result = self.ioclass()
        gen = XMLGenerator(result)
        parser.setContentHandler(gen)
        parser.parse(test_xml)

        self.assertEqual(result.getvalue(),
                         start + (
                         '<a:g1 xmlns:a="http://example.com/ns">'
                          '<a:g2 xml:lang="en">Hello</a:g2>'
                         '</a:g1>'))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_make_parser2(self):
        # Creating parsers several times in a row should succeed.
        # Testing this because there have been failures of this kind
        # before.
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()


# ===========================================================================
#
#   saxutils tests
#
# ===========================================================================
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_5027_1(self):
        # The xml prefix (as in xml:lang below) is reserved and bound by
        # definition to http://www.w3.org/XML/1998/namespace.  XMLGenerator had
        # a bug whereby a KeyError is raised because this namespace is missing
        # from a dictionary.
        #
        # This test demonstrates the bug by parsing a document.
        test_xml = StringIO(
            '<?xml version="1.0"?>'
            '<a:g1 xmlns:a="http://example.com/ns">'
             '<a:g2 xml:lang="en">Hello</a:g2>'
            '</a:g1>')

        parser = make_parser()
        parser.setFeature(feature_namespaces, True)
        result = self.ioclass()
        gen = XMLGenerator(result)
        parser.setContentHandler(gen)
        parser.parse(test_xml)

        self.assertEqual(result.getvalue(),
                         start + (
                         '<a:g1 xmlns:a="http://example.com/ns">'
                          '<a:g2 xml:lang="en">Hello</a:g2>'
                         '</a:g1>'))
项目:bandit-ss    作者:zeroSteiner    | 项目源码 | 文件源码
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()
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_make_parser2(self):
        # Creating parsers several times in a row should succeed.
        # Testing this because there have been failures of this kind
        # before.
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()


# ===========================================================================
#
#   saxutils tests
#
# ===========================================================================
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_5027_1(self):
        # The xml prefix (as in xml:lang below) is reserved and bound by
        # definition to http://www.w3.org/XML/1998/namespace.  XMLGenerator had
        # a bug whereby a KeyError is raised because this namespace is missing
        # from a dictionary.
        #
        # This test demonstrates the bug by parsing a document.
        test_xml = StringIO(
            '<?xml version="1.0"?>'
            '<a:g1 xmlns:a="http://example.com/ns">'
             '<a:g2 xml:lang="en">Hello</a:g2>'
            '</a:g1>')

        parser = make_parser()
        parser.setFeature(feature_namespaces, True)
        result = self.ioclass()
        gen = XMLGenerator(result)
        parser.setContentHandler(gen)
        parser.parse(test_xml)

        self.assertEqual(result.getvalue(),
                         self.xml(
                         '<a:g1 xmlns:a="http://example.com/ns">'
                          '<a:g2 xml:lang="en">Hello</a:g2>'
                         '</a:g1>'))
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_make_parser2(self):
        # Creating parsers several times in a row should succeed.
        # Testing this because there have been failures of this kind
        # before.
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()


# ===========================================================================
#
#   saxutils tests
#
# ===========================================================================
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_5027_1(self):
        # The xml prefix (as in xml:lang below) is reserved and bound by
        # definition to http://www.w3.org/XML/1998/namespace.  XMLGenerator had
        # a bug whereby a KeyError is raised because this namespace is missing
        # from a dictionary.
        #
        # This test demonstrates the bug by parsing a document.
        test_xml = StringIO(
            '<?xml version="1.0"?>'
            '<a:g1 xmlns:a="http://example.com/ns">'
             '<a:g2 xml:lang="en">Hello</a:g2>'
            '</a:g1>')

        parser = make_parser()
        parser.setFeature(feature_namespaces, True)
        result = self.ioclass()
        gen = XMLGenerator(result)
        parser.setContentHandler(gen)
        parser.parse(test_xml)

        self.assertEqual(result.getvalue(),
                         start + (
                         '<a:g1 xmlns:a="http://example.com/ns">'
                          '<a:g2 xml:lang="en">Hello</a:g2>'
                         '</a:g1>'))
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_make_parser2(self):
        # Creating parsers several times in a row should succeed.
        # Testing this because there have been failures of this kind
        # before.
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()


# ===========================================================================
#
#   saxutils tests
#
# ===========================================================================
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_5027_1(self):
        # The xml prefix (as in xml:lang below) is reserved and bound by
        # definition to http://www.w3.org/XML/1998/namespace.  XMLGenerator had
        # a bug whereby a KeyError is raised because this namespace is missing
        # from a dictionary.
        #
        # This test demonstrates the bug by parsing a document.
        test_xml = StringIO(
            '<?xml version="1.0"?>'
            '<a:g1 xmlns:a="http://example.com/ns">'
             '<a:g2 xml:lang="en">Hello</a:g2>'
            '</a:g1>')

        parser = make_parser()
        parser.setFeature(feature_namespaces, True)
        result = self.ioclass()
        gen = XMLGenerator(result)
        parser.setContentHandler(gen)
        parser.parse(test_xml)

        self.assertEqual(result.getvalue(),
                         self.xml(
                         '<a:g1 xmlns:a="http://example.com/ns">'
                          '<a:g2 xml:lang="en">Hello</a:g2>'
                         '</a:g1>'))
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_make_parser2(self):
        # Creating parsers several times in a row should succeed.
        # Testing this because there have been failures of this kind
        # before.
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()


# ===========================================================================
#
#   saxutils tests
#
# ===========================================================================
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_5027_1(self):
        # The xml prefix (as in xml:lang below) is reserved and bound by
        # definition to http://www.w3.org/XML/1998/namespace.  XMLGenerator had
        # a bug whereby a KeyError is raised because this namespace is missing
        # from a dictionary.
        #
        # This test demonstrates the bug by parsing a document.
        test_xml = StringIO(
            '<?xml version="1.0"?>'
            '<a:g1 xmlns:a="http://example.com/ns">'
             '<a:g2 xml:lang="en">Hello</a:g2>'
            '</a:g1>')

        parser = make_parser()
        parser.setFeature(feature_namespaces, True)
        result = self.ioclass()
        gen = XMLGenerator(result)
        parser.setContentHandler(gen)
        parser.parse(test_xml)

        self.assertEqual(result.getvalue(),
                         start + (
                         '<a:g1 xmlns:a="http://example.com/ns">'
                          '<a:g2 xml:lang="en">Hello</a:g2>'
                         '</a:g1>'))
项目:Chromium_DepotTools    作者:p07r0457    | 项目源码 | 文件源码
def assertXMLWellFormed(self, stream, msg=None, context=2):
        """asserts the XML stream is well-formed (no DTD conformance check)

        :param context: number of context lines in standard message
                        (show all data if negative).
                        Only available with element tree
        """
        try:
            from xml.etree.ElementTree import parse
            self._assertETXMLWellFormed(stream, parse, msg)
        except ImportError:
            from xml.sax import make_parser, SAXParseException
            parser = make_parser()
            try:
                parser.parse(stream)
            except SAXParseException as ex:
                if msg is None:
                    stream.seek(0)
                    for _ in range(ex.getLineNumber()):
                        line = stream.readline()
                    pointer = ('' * (ex.getLineNumber() - 1)) + '^'
                    msg = 'XML stream not well formed: %s\n%s%s' % (ex, line, pointer)
                self.fail(msg)
项目:node-gn    作者:Shouqun    | 项目源码 | 文件源码
def assertXMLWellFormed(self, stream, msg=None, context=2):
        """asserts the XML stream is well-formed (no DTD conformance check)

        :param context: number of context lines in standard message
                        (show all data if negative).
                        Only available with element tree
        """
        try:
            from xml.etree.ElementTree import parse
            self._assertETXMLWellFormed(stream, parse, msg)
        except ImportError:
            from xml.sax import make_parser, SAXParseException
            parser = make_parser()
            try:
                parser.parse(stream)
            except SAXParseException as ex:
                if msg is None:
                    stream.seek(0)
                    for _ in range(ex.getLineNumber()):
                        line = stream.readline()
                    pointer = ('' * (ex.getLineNumber() - 1)) + '^'
                    msg = 'XML stream not well formed: %s\n%s%s' % (ex, line, pointer)
                self.fail(msg)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def _flatsaxParse(fl):
    """
    Perform a SAX parse of an XML document with the _ToStan class.

    @param fl: The XML document to be parsed.
    @type fl: A file object or filename.

    @return: a C{list} of Stan objects.
    """
    parser = make_parser()
    parser.setFeature(handler.feature_validation, 0)
    parser.setFeature(handler.feature_namespaces, 1)
    parser.setFeature(handler.feature_external_ges, 0)
    parser.setFeature(handler.feature_external_pes, 0)

    s = _ToStan(getattr(fl, "name", None))
    parser.setContentHandler(s)
    parser.setEntityResolver(s)
    parser.setProperty(handler.property_lexical_handler, s)

    parser.parse(fl)

    return s.document
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_make_parser2(self):
        # Creating parsers several times in a row should succeed.
        # Testing this because there have been failures of this kind
        # before.
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()
        from xml.sax import make_parser
        p = make_parser()


# ===========================================================================
#
#   saxutils tests
#
# ===========================================================================
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_5027_1(self):
        # The xml prefix (as in xml:lang below) is reserved and bound by
        # definition to http://www.w3.org/XML/1998/namespace.  XMLGenerator had
        # a bug whereby a KeyError is raised because this namespace is missing
        # from a dictionary.
        #
        # This test demonstrates the bug by parsing a document.
        test_xml = StringIO(
            '<?xml version="1.0"?>'
            '<a:g1 xmlns:a="http://example.com/ns">'
             '<a:g2 xml:lang="en">Hello</a:g2>'
            '</a:g1>')

        parser = make_parser()
        parser.setFeature(feature_namespaces, True)
        result = self.ioclass()
        gen = XMLGenerator(result)
        parser.setContentHandler(gen)
        parser.parse(test_xml)

        self.assertEqual(result.getvalue(),
                         self.xml(
                         '<a:g1 xmlns:a="http://example.com/ns">'
                          '<a:g2 xml:lang="en">Hello</a:g2>'
                         '</a:g1>'))
项目:Sentence-Simplification-ACL14    作者:shashiongithub    | 项目源码 | 文件源码
def parse_to_iterate_probabilitytable(self):
        handler = SAX_Handler("iter", self.em_io_handler)
        parser = make_parser()
        parser.setContentHandler(handler)

        for count in range(self.NUM_TRAINING_ITERATION):
            print "Starting iteration: "+str(count+1)+" ..."

            print "Resetting all counts to ZERO ..."
            self.em_io_handler.reset_count_table()

            print "Start parsing "+self.training_xmlfile+" ..."
            parser.parse(self.training_xmlfile)  
            print "Ending iteration: "+str(count+1)+" ..."

            print "Updating probability table ..."
            self.em_io_handler.update_probability_table()
项目:depot_tools    作者:webrtc-uwp    | 项目源码 | 文件源码
def assertXMLWellFormed(self, stream, msg=None, context=2):
        """asserts the XML stream is well-formed (no DTD conformance check)

        :param context: number of context lines in standard message
                        (show all data if negative).
                        Only available with element tree
        """
        try:
            from xml.etree.ElementTree import parse
            self._assertETXMLWellFormed(stream, parse, msg)
        except ImportError:
            from xml.sax import make_parser, SAXParseException
            parser = make_parser()
            try:
                parser.parse(stream)
            except SAXParseException as ex:
                if msg is None:
                    stream.seek(0)
                    for _ in range(ex.getLineNumber()):
                        line = stream.readline()
                    pointer = ('' * (ex.getLineNumber() - 1)) + '^'
                    msg = 'XML stream not well formed: %s\n%s%s' % (ex, line, pointer)
                self.fail(msg)
项目:wuye.vim    作者:zhaoyingnan911    | 项目源码 | 文件源码
def assertXMLWellFormed(self, stream, msg=None, context=2):
        """asserts the XML stream is well-formed (no DTD conformance check)

        :param context: number of context lines in standard message
                        (show all data if negative).
                        Only available with element tree
        """
        try:
            from xml.etree.ElementTree import parse
            self._assertETXMLWellFormed(stream, parse, msg)
        except ImportError:
            from xml.sax import make_parser, SAXParseException
            parser = make_parser()
            try:
                parser.parse(stream)
            except SAXParseException as ex:
                if msg is None:
                    stream.seek(0)
                    for _ in range(ex.getLineNumber()):
                        line = stream.readline()
                    pointer = ('' * (ex.getLineNumber() - 1)) + '^'
                    msg = 'XML stream not well formed: %s\n%s%s' % (ex, line, pointer)
                self.fail(msg)
项目:Meiji    作者:GiovanniBalestrieri    | 项目源码 | 文件源码
def create_parser(target, store):
    parser = make_parser()
    try:
        # Workaround for bug in expatreader.py. Needed when
        # expatreader is trying to guess a prefix.
        parser.start_namespace_decl(
            "xml", "http://www.w3.org/XML/1998/namespace")
    except AttributeError:
        pass  # Not present in Jython (at least)
    parser.setFeature(handler.feature_namespaces, 1)
    rdfxml = RDFXMLHandler(store)
    rdfxml.setDocumentLocator(target)
    # rdfxml.setDocumentLocator(_Locator(self.url, self.parser))
    parser.setContentHandler(rdfxml)
    parser.setErrorHandler(ErrorHandler())
    return parser
项目:prophet    作者:MKLab-ITI    | 项目源码 | 文件源码
def create_parser(target, store):
    parser = make_parser()
    try:
        # Workaround for bug in expatreader.py. Needed when
        # expatreader is trying to guess a prefix.
        parser.start_namespace_decl(
            "xml", "http://www.w3.org/XML/1998/namespace")
    except AttributeError:
        pass  # Not present in Jython (at least)
    parser.setFeature(handler.feature_namespaces, 1)
    rdfxml = RDFXMLHandler(store)
    rdfxml.setDocumentLocator(target)
    # rdfxml.setDocumentLocator(_Locator(self.url, self.parser))
    parser.setContentHandler(rdfxml)
    parser.setErrorHandler(ErrorHandler())
    return parser
项目:sack    作者:jofpin    | 项目源码 | 文件源码
def parse(filename):
    """
    Interprets the given string as a filename, URL or XML data string,
    parses it and returns a Python object which represents the given
    document.

    Raises ``ValueError`` if the argument is None / empty string.

    Raises ``xml.sax.SAXParseException`` if something goes wrong
    during parsing.s
    """
    if filename is None or filename.strip() == '':
        raise ValueError('parse() takes a filename, URL or XML string')
    parser = make_parser()
    sax_handler = Handler()
    parser.setContentHandler(sax_handler)
    if os.path.exists(filename) or is_url(filename):
        parser.parse(filename)
    else:
        parser.parse(StringIO(filename))

    return sax_handler.root
项目:health-mosconi    作者:GNUHealth-Mosconi    | 项目源码 | 文件源码
def __init__(self, pool, module, module_state):
        "Register known taghandlers, and managed tags."
        sax.handler.ContentHandler.__init__(self)

        self.pool = pool
        self.module = module
        self.ModelData = pool.get('ir.model.data')
        self.fs2db = Fs2bdAccessor(self.ModelData, pool)
        self.to_delete = self.populate_to_delete()
        self.noupdate = None
        self.module_state = module_state
        self.grouped = None
        self.grouped_creations = defaultdict(dict)
        self.grouped_write = defaultdict(list)
        self.grouped_model_data = []
        self.skip_data = False
        Module = pool.get('ir.module')
        self.installed_modules = [m.name for m in Module.search([
                    ('state', 'in', ['installed', 'to upgrade']),
                    ])]

        # Tag handlders are used to delegate the processing
        self.taghandlerlist = {
            'record': RecordTagHandler(self),
            'menuitem': MenuitemTagHandler(self),
            }
        self.taghandler = None

        # Managed tags are handled by the current class
        self.managedtags = ["data", "tryton"]

        # Connect to the sax api:
        self.sax_parser = sax.make_parser()
        # Tell the parser we are not interested in XML namespaces
        self.sax_parser.setFeature(sax.handler.feature_namespaces, 0)
        self.sax_parser.setContentHandler(self)
项目:lagendacommun    作者:ecreall    | 项目源码 | 文件源码
def load(self, source, content_types):
        """Return Json dic. 'source' is a source XML file source,
           'content_type' is the content type to load"""
        parser = sax.make_parser()
        parser.setContentHandler(DictBuilder(content_types))
        parser.setFeature(sax.handler.feature_namespaces, 1)
        inpsrc = urllib.request.urlopen(source)
        parser.parse(inpsrc)
        return parser.getContentHandler().jsonable()
项目:Taigabot    作者:FrozenPigs    | 项目源码 | 文件源码
def __init__(self, fh, **kwargs):
        """
        Constructor.

        fh - a valid, open file handle to XML based record data.
        """
        super(XMLRecordParser, self).__init__()

        self.xmlparser = make_parser()
        self.xmlparser.setContentHandler(SaxRecordParser(self.consume_record))

        self.fh = fh

        self.__dict__.update(kwargs)
项目:VIA4CVE    作者:cve-search    | 项目源码 | 文件源码
def __init__(self):
    self.name = SOURCE_NAME
    parser    = make_parser()
    handler = VendorStatementsHandler()
    _file, r = conf.getFeedData(SOURCE_NAME, SOURCE_FILE)
    parser.setContentHandler(handler)
    parser.parse(_file)
    self.cves = handler.statements
项目:VIA4CVE    作者:cve-search    | 项目源码 | 文件源码
def __init__(self):
    self.name = SOURCE_NAME
    parser    = make_parser()
    handler = OVALHandler()
    _file, r = conf.getFeedData(SOURCE_NAME, SOURCE_FILE)
    parser.setContentHandler(handler)
    parser.parse(_file)
    self.cves = {}
    self.oval = handler.ovals
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_make_parser(self):
        # Creating a parser should succeed - it should fall back
        # to the expatreader
        p = make_parser(['xml.parsers.no_such_parser'])


# ===== XMLGenerator
项目:cidr-tools    作者:silverwind    | 项目源码 | 文件源码
def __init__(self, fh, **kwargs):
        """
        Constructor.

        fh - a valid, open file handle to XML based record data.
        """
        super(XMLRecordParser, self).__init__()

        self.xmlparser = make_parser()
        self.xmlparser.setContentHandler(SaxRecordParser(self.consume_record))

        self.fh = fh

        self.__dict__.update(kwargs)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_make_parser(self):
        # Creating a parser should succeed - it should fall back
        # to the expatreader
        p = make_parser(['xml.parsers.no_such_parser'])
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_sf_1513611(self):
        # Bug report: http://www.python.org/sf/1513611
        sio = StringIO("invalid")
        parser = make_parser()
        from xml.sax import SAXParseException
        self.assertRaises(SAXParseException, parser.parse, sio)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_make_parser(self):
        # Creating a parser should succeed - it should fall back
        # to the expatreader
        p = make_parser(['xml.parsers.no_such_parser'])
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_sf_1513611(self):
        # Bug report: http://www.python.org/sf/1513611
        sio = StringIO("invalid")
        parser = make_parser()
        from xml.sax import SAXParseException
        self.assertRaises(SAXParseException, parser.parse, sio)