Exemple #1
0
 def generateFeed(self):
     self.item = self.iframe or '<p><img src="%s" /></p>' % self.imgLink
     if self.itemBody and not self.itemBody.startswith('<'):
         self.itemBody = '<p>%s</p>' % self.itemBody
     self.itemBody = plagg.decode(self.itemBody)
     rss = self.RSS_TEMPLATE % self.__dict__
     rss = plagg.encode(rss)
     self.feed = feedparser.parse(rss)
Exemple #2
0
 def tidy(self, body):
     body = plagg.encode(body)
     if plagg.VERBOSE > 3:
         print 'before tidy:', body
     tidy = ['/usr/bin/tidy', '-asxhtml', '-utf8', '-f', '/dev/null']
     try:
         t = subprocess.Popen(
             tidy, stdin=subprocess.PIPE, stdout=subprocess.PIPE
         )
         r = t.communicate(body)[0]
     except OSError:
         if not Entry.TidyWarningDone:
             sys.stderr.write("Cannot execute %s\n" % ' '.join(tidy))
             Entry.TidyWarningDone = True
     else:
         if 0 <= t.returncode <= 1:    # warnings are ok
             # Keep the part between <body> and </body>
             m = _body.search(r)
             body = (m.group(1) if m else r).strip()
         elif plagg.VERBOSE > 3:
             print "tidy errors; body left as-is" % t.returncode
     if plagg.VERBOSE > 3:
         print 'after tidy:', body
     return plagg.decode(body)
Exemple #3
0
def _linktag(href, text, **attrs):
    """Returns a HTML link tag."""
    a = ''.join([' %s="%s"' % (k, _escape(v)) for k, v in attrs.items() if v])
    return u'<a href="%s"%s>%s</a>' % (href, a, plagg.decode(text))