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 RSS(self, sessID, results, conf):
""" package results as RSS """
sess = self._getSession(sessID)
formatted = """
\t%s
\t%s
\t%s
\t%s
\t%s\n""" % ( conf.get('channel_title', 'SQICore default channel'),
conf.get('channel_link', ''),
conf.get('channel_desc', ''),
conf.get('channel_generator', 'SQICore formatter'),
conf.get('channel_lang', '')
)
#u = self.acl_users.getUser(sess.username).__of__(self)
#from AccessControl.SecurityManagement import newSecurityManager, getSecurityManager
import time
#newSecurityManager(None, u)
#print getSecurityManager().getUser()
size = sess._getResultsSetSize()
if size == 0:
size = None
for x in results[:size]:
#obj = x.getObject()
obj = x
cat = ''
abs_url = valueOrExec(getattr(obj, 'absolute_url'))
if 'webtop' in abs_url:
tmp_u = abs_url.split('/')
i = tmp_u.index('webtop')
try:
ccid = tmp_u[i+1][1:]
except IndexError:
pass
try:
cat = self.courses.get_child(ccid).get_name()
except KeyError:
pass
#timetime = obj.getTime()
timetime = valueOrExec(getattr(obj, conf.get('timestamp', '_dumdym'), ''))
try:
if obj.hasBeenChanged():
timetime = obj.getChangeTime()
except AttributeError:
pass
# 2006-03-22 10:39:14
#time_formatted = time.strftime("%a %b %Y-%m-%d %H:%M:%S +0000",time.localtime(timetime))
#time_formatted = time.strftime("%a, %d %b %Y %H:%M:%S +0000",time.localtime(timetime))
if not isinstance(timetime, type(float(0))):
try:
timetime = float(timetime)
except ValueError:
pass
time_formatted = ''
try:
time_formatted = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(timetime))
except TypeError:
time_formatted = timetime
#intro = unicode(x.getIntro, 'utf-8')
intro = unicode(valueOrExec(getattr(x, conf.get('intro', '_dumdym'), '')), 'utf-8')
#body = unicode(x.getContent, 'utf-8')
body = unicode(valueOrExec(getattr(x, conf.get('content', '_dumdym'), '')), 'utf-8')
#title = unicode(x.getTitle, 'utf-8')
title = unicode(valueOrExec(getattr(x, conf.get('title', '_dumdym'), '')), 'utf-8')
title = convert_to_ents(title)
uname = unicode(valueOrExec(getattr(x, 'get_author')), 'utf-8')
formatted += '\t- \n'
formatted += '\t\t%s\n' % title
formatted += '\t\t%s\n' % abs_url
formatted += '\t\t%s\n' % abs_url
formatted += '\t\t%s\n' % time_formatted
formatted += '\t\t%s\n' % uname
if cat:
formatted += '\t\t%s\n' % unicode(cat, 'utf-8')
formatted += '\t\t%s\n' % abs_url
formatted += '\t\t\n' % intro
formatted += '\t\t%s
%s
]]>\n' % ( intro, body)
#formatted += '\t\t%s\n' % cat
formatted += '\t\n'
formatted += '\n'
return formatted
def Objecti(self, sessID, results, conf):
""" package results as Object list """
import time
sess = self._getSession(sessID)
formatted = '\n'
formatted += ''
print "--------------------- ===================================== -------------------------"
size = sess._getResultsSetSize()
if size == 0:
size = None
for x in results[:size]:
#obj = x.getObject()
obj = x
title = valueOrExec(getattr(x, conf.get('title', '_dumdym'), ''))
if title:
title = unicode(title, 'utf-8')
print "title:", title
abs_url = valueOrExec(getattr(obj, 'absolute_url'))
timetime = valueOrExec(getattr(obj, conf.get('timestamp', '_dumdym'), ''))
if not isinstance(timetime, type(float(0))):
try:
timetime = float(timetime)
except ValueError:
pass
try:
time_formatted = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(timetime))
except TypeError:
time_formatted = timetime
formatted += '\t- \n'
formatted += '\t\t%s\n' % title
formatted += '\t\t%s\n' % abs_url
formatted += '\t\t%s\n' % time_formatted
formatted += '\t\t%s\n' % valueOrExec(getattr(obj, conf.get('modified', 'modified')))
try:
formatted += '\t\t%s\n' % obj.UID()
except AttributeError:
formatted += '\t\t%s\n' % abs_url
formatted += '\t
\n'
formatted += ''
return formatted
def SingleObject(self, sessID, result, conf):
""" package single object """
sess = self._getSession(sessID)
formatted = '\n'
formatted += ''
try:
a = result.view()
except AttributeError:
print "==================================================================="
print result
a = result.index_html()
print "======================================================="
formatted += a
print "======================================================="
formatted += ']]>'
return formatted