コード例 #1
0
ファイル: htmlutils.py プロジェクト: lcrees/psilib
 def startElement(self, tag, attrs):
     sbuf = StringIO()
     output = _outputwrapper(sbuf, self._encoding)
     output.write(''.join(['<', tag]))
     attributes = attrs.items()
     attributes.sort()
     for (name, value) in attributes:
         output.write(' %s=' % name)
         writeattr(output, value)
     if tag in self.empty:
         output.write(' />')
         if tag in self.head:
             self.heads.append(sbuf.getvalue())
             return None
     else: output.write('>')
     if tag in self.head: self.firsttag.append(sbuf.getvalue())
     elif self.doinline and tag in self.inline:
         self.content.append(sbuf.getvalue())
     else: self.tags.append(sbuf.getvalue())
コード例 #2
0
ファイル: htmlutils.py プロジェクト: lcrees/psilib
 def endElement(self, tag):
     if tag not in self.empty:
         sbuf = StringIO()
         output = _outputwrapper(sbuf, self._encoding)
         output.write('</%s>' % tag)
         if tag in self.head:
             if len(self.content):
                 self.firsttag.append(str(''.join(self.content)))
                 self.content = []
             self.firsttag.append(sbuf.getvalue())
             if tag == 'title': self.title.extend(self.firsttag)
             elif tag == 'script':
                 if '</head>' in self.heads:
                     self.tags.extend(self.firsttag)
                 else: self.scripts.extend(self.firsttag)
             else: self.heads.append(''.join(self.firsttag))
             self.firsttag = []
         elif self.doinline and tag in self.inline:
             self.content.append(sbuf.getvalue())
         else:
             if len(self.content):
                 self.tags.append(str(''.join(self.content)))
                 self.content = []
             self.tags.append(sbuf.getvalue())