import htmlentitydefs
from xml.sax.saxutils import escape
def valueOrExec(value):
if hasattr(value, 'im_func'):
return value()
return value
def convert_to_ents(txt):
buf = ''
for c in txt:
mat = ''
for x in htmlentitydefs.entitydefs:
a = htmlentitydefs.entitydefs[x].decode('iso-8859-1')
if c == a:
mat = x
continue
if mat: buf += '&%s;' % mat
else: buf += c
return escape(buf)
def xhtml(entries, conf={}):
""" package results as RSS """
formatted = u"""
"""
for x in entries:
#title = x.get('title').encode('utf-8')
title = x.get('title')
#link = x.get('link').encode('utf-8')
link = x.get('link')
#updated = x.get('updated').encode('utf-8')
updated = x.get('updated')
comments = ''
guid = ''
if x.has_key('guid'): guid = x.get('guid')
elif x.has_key('id'): guid = x.get('id')
elif x.has_key('link'): guid = x.get('link')
#guid.encode('utf-8')
summary = ''
if x.has_key('summary'):
summary = x.get('summary')
content = ''
if x.has_key('content'):
#content = x.get('content')[0].get('value').encode('utf-8')
content = x.get('content')[0].get('value')
author = ''
if x.has_key('author'):
#author = x.get('author').encode('utf-8')
author = x.get('author')
cat = ''
if x.has_key('category'):
cat = x.get('category')
formatted += "\t- \n"
formatted += "\t\t
\n"
formatted += '\t\t\t
%s\n' % (link, title)
formatted += '\t\t\t
%s
\n' % x.get('updated')
formatted += "\t\t
\n"
formatted += "\t \n"
formatted += '
'
return formatted.encode('utf-8')