Example #1
0
    def startElementNS(self, name, qname, attrs):
        parent_handler = self._handler_stack[-1]
        if not parent_handler._checkElementAllowed(name):
            # we're not allowed and ignoring the element and all subelements
            self.__mapping_stack.pushOverridesAll(IgnoringHandler)
            self._handler_stack.append(IgnoringHandler(
                parent_handler.result(),
                parent_handler,
                self._options,
                self._extra))
            self._depth_stack.append(self._depth)
            self._depth += 1
            return
        # check whether we have a special handler
        factory = self.__mapping_stack.getHandler(name)
        if factory is None:
            # no handler, use parent's handler
            handler = parent_handler
        else:
            # create new subhandler
            handler = factory(
                parent_handler.result(),
                parent_handler,
                self._options,
                self._extra)
            handler.setDocumentLocator(self._locator)
            self.__mapping_stack.pushOverrides(handler.getOverrides())
            self._handler_stack.append(handler)
            self._depth_stack.append(self._depth)

        handler.startElementNS(name, qname, attrs)
        self._depth += 1
Example #2
0
 def setContentHandler(self, handler):
     old = self.getContentHandler()
     if old:
         old.setDocumentLocator(None)
     if handler:
         handler.setDocumentLocator(self._locator)
     xml.sax.xmlreader.XMLReader.setContentHandler(self, handler)
Example #3
0
 def setContentHandler(self, handler):
     old = self.getContentHandler()
     if old:
         old.setDocumentLocator(None)
     if handler:
         handler.setDocumentLocator(self._locator)
     xml.sax.xmlreader.XMLReader.setContentHandler(self, handler)
Example #4
0
    def importFromStream(self, stream, result=None, options=None, extra=None):
        """Import from file object.

        sream - file object
        settings - import settings object that can be inspected
                   by handlers (optional)
        result - initial result object to attach everything to (optional)

        Applies an import filter if one is specified in the settings.

        returns top result object
        """
        handler = self.importHandler(result, options, extra)
        parser = xml.sax.make_parser()
        parser.setFeature(xml.sax.handler.feature_namespaces, 1)
        parser.setContentHandler(handler)
        handler.setDocumentLocator(parser)
        parser.parse(stream)
        return handler.result()
Example #5
0
    def get_strings(self, source):
        """
        Extracts translatable strings from the //desc[@lang='en-US'] attributes
        in Evergreen's ils_events.xml file.
        """
        self.pothead()

        locator = xml.sax.xmlreader.Locator()
        parser = xml.sax.make_parser()
        handler = ILSEventHandler()
        handler.setDocumentLocator(locator)
        parser.setContentHandler(handler)
        parser.parse(source)

        for entry in handler.events:
            poe = polib.POEntry()
            poe.occurrences = handler.events[entry]
            poe.msgid = entry
            self.pot.append(poe)
Example #6
0
    def get_strings(self, source):
        """
        Extracts translatable strings from the //desc[@lang='en-US'] attributes
        in Evergreen's ils_events.xml file.
        """
        self.pothead()

        locator = xml.sax.xmlreader.Locator()
        parser = xml.sax.make_parser()
        handler = ILSEventHandler()
        handler.setDocumentLocator(locator)
        parser.setContentHandler(handler)
        parser.parse(source)

        for entry in handler.events:
            poe = polib.POEntry()
            poe.occurrences = handler.events[entry]
            poe.msgid = entry
            self.pot.append(poe)
Example #7
0
    def get_strings(self, source):
        """
        Extracts translatable strings from the reporter:label attributes
        in Evergreen's fieldmapper IDL file.
        """
        self.pothead()

        locator = xml.sax.xmlreader.Locator()
        parser = xml.sax.make_parser()
        handler = IDLHandler()
        handler.setDocumentLocator(locator)
        parser.setContentHandler(handler)
        parser.parse(source)

        for entity in handler.entities:
            poe = polib.POEntry()
            poe.occurrences = handler.entities[entity]
            poe.msgid = entity
            self.pot.append(poe)
        self.idl = handler.entityized
Example #8
0
    def get_strings(self, source):
        """
        Extracts translatable strings from the reporter:label attributes
        in Evergreen's fieldmapper IDL file.
        """
        self.pothead()

        locator = xml.sax.xmlreader.Locator()
        parser = xml.sax.make_parser()
        handler = IDLHandler()
        handler.setDocumentLocator(locator)
        parser.setContentHandler(handler)
        parser.parse(source)

        for entity in handler.entities:
            poe = polib.POEntry()
            poe.occurrences = handler.entities[entity]
            poe.msgid = entity
            self.pot.append(poe)
        self.idl = handler.entityized