def add(self, channel, listoftxt): """ add listoftxt to channel's output. """ channel = unicode(channel).lower() data = get("outcache-" + channel) if not data: data = [] data.extend(listoftxt) set(u"outcache-" + channel, data, 3600)
def get(self, channel): """ return 1 item popped from outcache. """ channel = unicode(channel).lower() global get data = get(u"outcache-" + channel) if not data: txt = None else: try: txt = data.pop(0) ; set(u"outcache-" + channel, data, 3600) except (KeyError, IndexError): txt = None if data: size = len(data) else: size = 0 return (txt, size)
def get(self, channel): """ return 1 item popped from outcache. """ channel = unicode(channel).lower() global get data = get(u"outcache-" + channel) if not data: txt = None else: try: txt = data.pop(0) set(u"outcache-" + channel, data, 3600) except (KeyError, IndexError): txt = None if data: size = len(data) else: size = 0 return (txt, size)
def get_tinyurl(url): """ grab a tinyurl. """ res = get(url, namespace='tinyurl') logging.debug('tinyurl - cache - %s' % unicode(res)) if res and res[0] == '[': return json.loads(res) postarray = [ ('submit', 'submit'), ('url', url), ] postdata = urllib.urlencode(postarray) req = urllib2.Request(url=plugcfg.url, data=postdata) req.add_header('User-agent', useragent()) try: res = urllib2.urlopen(req).readlines() except urllib2.URLError, e: logging.warn('tinyurl - %s - URLError: %s' % (url, str(e))) return
def get_tinyurl(url): """ grab a tinyurl. """ res = get(url, namespace='tinyurl') ; logging.debug('tinyurl - cache - %s' % unicode(res)) if res and res[0] == '[': return json.loads(res) postarray = [ ('submit', 'submit'), ('url', url), ] postdata = urllib.urlencode(postarray) req = urllib2.Request(url=plugcfg.url, data=postdata) req.add_header('User-agent', useragent()) try: res = urllib2.urlopen(req).readlines() except urllib2.URLError, e: logging.warn('tinyurl - %s - URLError: %s' % (url, str(e))) ; return except urllib2.HTTPError, e: logging.warn('tinyurl - %s - HTTP error: %s' % (url, str(e))) ; return except Exception, ex: if "DownloadError" in str(ex): logging.warn('tinyurl - %s - DownloadError: %s' % (url, str(e))) else: handle_exception() return
def copy(self, channel): """ return 1 item popped from outcache. """ channel = unicode(channel).lower() global get return get(u"outcache-" + channel)