# -*- coding: utf-8 # -*- Mode: Python; py-indent-offset: 4 -*- # $Id: __init__.py 33 2006-06-02 06:49:13Z vahur $ # # Copyright (c) 2007, Vahur Rebas # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ Space page """ import Globals from Globals import Acquisition, Persistent from Acquisition import aq_base, aq_inner, aq_parent, Explicit from AccessControl import ClassSecurityInfo from OFS.SimpleItem import SimpleItem from Feeds import Feeds import fetcher import RSSformatter, XHTMLformatter import time VALID_KEYS = ['feed', 'filter', 'order', 'limit'] class Page(SimpleItem, Persistent, Explicit): """ Page """ meta_type = "Page" security = ClassSecurityInfo() security.declareObjectPublic() manage_options = SimpleItem.manage_options def __init__(self, id, view_token, edit_token, title='untitled'): self.id = id self._view_token = view_token self._edit_token = edit_token self.title = title self._pipes_changed = time.time() self._cache_generated = 0 security.declarePrivate('manage_afterAdd') def manage_afterAdd(self, item, container): pass def getTitle(self): return self.title def setTitle(self, title): self.title = title return {'errno':0, 'errstr':''} def _getEditToken(self): return self._edit_token def _getViewToken(self): return self._view_token def index_html(self, REQUEST, token=''): """ index html """ return self._feed(REQUEST, token) def _setPipeline(self, pipeline): # validate pipeline print "pipelin:", pipeline tmp = pipeline.split('\n') for x in tmp: parts = x.split(' ') print parts if len(parts) == 1 and parts[0] == '': continue if len(parts) > 2: return {'errno': 7, 'errstr':'Invalid pipeline. too many spaces on one line'} if len(parts) == 1 and parts[0] != '': return {'errno': 6, 'errstr':'Invalid pipeline. too less spaces on one line'} if parts[0].lower() not in VALID_KEYS: return {'errno': 5, 'errstr':'Invalid pipeline. Invalid keyword'} self.pipeline = pipeline self._pipes_changed = time.time() return {} def _getPipeline(self): try: return {'errno': 0, 'resp': {'pipeline': self.pipeline}} except AttributeError: return {'errno':0, 'resp': {'pipeline': ''}} def _feed(self, REQUEST, token=''): """ get aggregated feed """ t = '' if token: t = token else: t = REQUEST.get('token') # FIXME: uncomment below if t != self._view_token and t != self._edit_token: return "" print "pipes:", self._getPipeline() REQUEST.RESPONSE.setHeader('Content-Type', 'text/xml') if self._cache_generated < self._pipes_changed or self._cache_generated < time.time() - 1500: print "generating again...", self._cache_generated < self._pipes_changed, self._cache_generated > time.time() - 1500 output = fetcher.pipelines(getattr(self, 'feeds'), self.pipeline) _rss = RSSformatter.RSS(output) self._cache = _rss self._cache_generated = time.time() return self._cache rss = _feed def xhtml(self, REQUEST): """ return xhtml """ output = fetcher.pipelines(getattr(self, 'feeds'), self.pipeline) REQUEST.RESPONSE.setHeader('Content-Type', 'text/html; charset=utf-8') return XHTMLformatter.xhtml(output) Globals.InitializeClass(Page)