Index: channels/__init__.py ================================================================== --- channels/__init__.py +++ channels/__init__.py @@ -33,19 +33,19 @@ from config import * import ahttp import action import favicon import os.path -import xml.sax.saxutils +import xml.sax.saxutils, htmlentitydefs import re import copy import inspect # Only export plugin classes __all__ = [ - "GenericChannel", "ChannelPlugin" + "GenericChannel", "ChannelPlugin", "use_rx" ] # generic channel module --------------------------------------- @@ -575,12 +575,20 @@ s = "audio/" + s # return s # remove SGML/XML entities - def entity_decode(self, s): - return xml.sax.saxutils.unescape(s).replace(" ", " ") + def entity_decode(self, str): + return re.sub('&(#?(x?))(\w+);', self._entity, str) + def _entity(self, sym): + num, hex, name = sym.groups() + if hex: + return unichr(int(name, base=16)) + elif num: + return unichr(int(name)) + else: + return unichr(htmlentitydefs.name2codepoint[name]) # convert special characters to &xx; escapes def xmlentities(self, s): return xml.sax.saxutils.escape(s) @@ -648,11 +656,14 @@ icon = gtk.image_new_from_pixbuf(pixbuf) else: icon = gtk.image_new_from_stock(gtk.STOCK_DIRECTORY, size=1) label = gtk.HBox() label.pack_start(icon, expand=False, fill=True) - label.pack_start(gtk.Label(self.meta.get("title", self.module)), expand=True, fill=True) + l = gtk.Label(self.meta.get("title", self.module)) + if self.meta.get("color"): + l = uikit.bg(l, self.meta["color"]) + label.pack_start(l, expand=True, fill=True) # pack it into an event container to catch double-clicks ev_label = gtk.EventBox() ev_label.add(label) ev_label.connect('event', parent.on_homepage_channel_clicked) @@ -686,6 +697,21 @@ pass def __getattr__(self, name): return lambda *x: None def status(self, *x): pass + + +# Decorator +def use_rx(func): + def try_both(*args, **kwargs): + for method, use_rx in [("RX", not conf.pyquery), ("PQ", conf.pyquery)]: + try: + log.STAT(method) + return func(*args, use_rx=not conf.pyquery, **kwargs) + except Exception as e: + log.ERR("{} extraction failed:".format(method), e) + continue + return [] + return try_both +