Beispiel #1
0
 def __init__(self, stream_handler, content_handler):
     # create stream processor
     self.parser = sax_make_parser(['xml.sax.expatreader'])
     self.processor = XMPPContentHandler(
                             stream_handler,
                             content_handler)
     self.parser.setContentHandler(self.processor)
Beispiel #2
0
 def __load(self, downstream=None):
     parser = sax_make_parser()
     parser.setFeature(sax_feature_namespaces, 0)
     self.__handler = IBusComponentXML(parser, downstream, self.__iso639)
     parser.setContentHandler(self.__handler)
     f = codecs.open(self.__path, 'r', encoding='utf-8')
     try:
         parser.parse(f)
     except SAXParseException:
         print('Error: Invalid file format: %s' % path)
     finally:
         f.close()
Beispiel #3
0
def parse_iso639(path):
    f = codecs.open(path, 'r', encoding='utf-8')
    parser = sax_make_parser()
    parser.setFeature(sax_feature_namespaces, 0)
    handler = ISO639XML(parser)
    parser.setContentHandler(handler)
    try:
        parser.parse(f)
    except SAXParseException:
        print('Error: Invalid file format: %s' % path)
    finally:
        f.close()
    return handler
Beispiel #4
0
def make_parser(validating):
    """
    Function to generate an XML parser.
    
    First it will be tried to generate a validating parser. If
    this attempt fails, a non validating parser is tried next.
    
    @param validating flag indicating a validating parser is requested
    @return XML parser object
    """
    if validating:
        # see if we have a working validating parser available
        try:
            import _xmlplus
        except ImportError:
            validating = False
        else:
            try:
                v = _xmlplus.version_info
            except AttributeError:
                validating = False
            else:
                if v < (0, 8, 3):
                    validating = False

    if validating:
        try:
            from xml.sax.sax2exts import XMLValParserFactory

            return XMLValParserFactory.make_parser()
        except ImportError:
            from xml.sax import make_parser as sax_make_parser

            return sax_make_parser()
    else:
        from xml.sax import make_parser as sax_make_parser

        return sax_make_parser()
Beispiel #5
0
 def __init__(self, stream_handler, content_handler):
     # create stream processor
     self.parser = sax_make_parser(['xml.sax.expatreader'])
     self.processor = XMPPContentHandler(stream_handler, content_handler)
     self.parser.setContentHandler(self.processor)