예제 #1
0
 def handle_data(self,data):
     if self.stack:
         if '#PCDATA' not in HTML_DTD.get(self.stack[-1],[]) and not strip(data):
             # this is probably ignorable whitespace
             self._cont_handler.ignorableWhitespace(data)
         else:
             self._cont_handler.characters(to_xml_string(data,self._encoding))
예제 #2
0
 def handle_data(self, data):
     if self.stack:
         if '#PCDATA' not in HTML_DTD.get(self.stack[-1],
                                          []) and not strip(data):
             # this is probably ignorable whitespace
             self._cont_handler.ignorableWhitespace(data)
         else:
             self._cont_handler.characters(
                 to_xml_string(data, self._encoding))
예제 #3
0
    def finish_starttag(self, tag, attrs):
        """uses the HTML DTD to automatically generate events
        for missing tags"""

        # guess omitted close tags
        while self.stack and \
              upper(self.stack[-1]) in HTML_OPT_END and \
              tag not in HTML_DTD.get(self.stack[-1],[]):
            self.unknown_endtag(self.stack[-1])
            del self.stack[-1]

        if self.stack and tag not in HTML_DTD.get(self.stack[-1],[]) and self.verbose:
            print 'Warning : trying to add %s as a child of %s'%\
                  (tag,self.stack[-1])

        self.unknown_starttag(tag,attrs)
        if upper(tag) in HTML_FORBIDDEN_END:
            # close immediately tags for which we won't get an end
            self.unknown_endtag(tag)
            return 0
        else:
            self.stack.append(tag)
        return 1
예제 #4
0
    def finish_starttag(self, tag, attrs):
        """uses the HTML DTD to automatically generate events
        for missing tags"""

        # guess omitted close tags
        while self.stack and \
              upper(self.stack[-1]) in HTML_OPT_END and \
              tag not in HTML_DTD.get(self.stack[-1],[]):
            self.unknown_endtag(self.stack[-1])
            del self.stack[-1]

        if self.stack and tag not in HTML_DTD.get(self.stack[-1],
                                                  []) and self.verbose:
            print 'Warning : trying to add %s as a child of %s'%\
                  (tag,self.stack[-1])

        self.unknown_starttag(tag, attrs)
        if upper(tag) in HTML_FORBIDDEN_END:
            # close immediately tags for which we won't get an end
            self.unknown_endtag(tag)
            return 0
        else:
            self.stack.append(tag)
        return 1