""" diagram of one route, showing the last few measurements """ from __future__ import division import time from nevow import tags as T, flat import numpy from numpy import array from freeway.lib.memoize import lru_cache from freeway.db import logTime path = T.Proto('path') line = T.Proto('line') #fix flaky graph, add server-rendered rsvg mode def smoothSequence(x, kernelWidth=5): """returned sequence is shorter""" kernel = numpy.bartlett(kernelWidth) kernel /= kernel.sum() return numpy.convolve(x, kernel, mode='valid') class Diagram(object): def __init__(self, db, shadows=False, **kw): """kwargs go to plotPoints""" self.db = db self.shadows = shadows
def render(self, info, format="html", fragment=False, template=None): """Renders the template to a string using the provided info. info: dict of variables to pass into template format: can only be "html" at this point template: path to template """ self.__superTemplate = None filename = self.find_template(template) pretty = False if info.has_key('tidy'): pretty = info['tidy'] ns = {} if format == 'html': ns.update(__import__('nevow.tags', ns, ns, ['__all__']).__dict__) ns.update( __import__('nevow.entities', ns, ns, ['__all__']).__dict__) else: # import user-defined Stan tags ns.update( __import__('%s.tags' % format, ns, ns, ['__all__']).__dict__) protected = [ 'vars', 'render', 'inherits', 'replace', 'include', 'formerror', ] ns['vars'] = DataVars(info) # if self.get_extra_vars: # ns['std'] = self.get_extra_vars ( ) [ 'std' ] ns['render'] = rend ns['inherits'] = lambda template: self._inherits_tag(template, ns, ns) ns['replace'] = ns['override'] = self._replace_tag ns['include'] = lambda template: self._include_tag(template, ns, ns) ns['formerror'] = T.Proto('form:error') for renderer in self.renderers: funcs = renderer.get_renderers() for key in funcs.keys(): if key in protected: del funcs[key] continue ns.update(funcs) continue try: self.__template = eval(file(filename, 'rU').read(), ns, ns) except: print "ERROR IN TEMPLATE", filename raise if self.__superTemplate: parts = dict([(c.attributes['slot'], flatten(c.children)) for c in self.__template.children]) for slot, fragment in parts.items(): self.__superTemplate.fillSlots(slot, fragment) output = flatten(self.__superTemplate) else: output = flatten(self.__template) if pretty and tidy: options = dict(input_xml=True, output_xhtml=True, add_xml_decl=False, doctype='omit', indent='auto', tidy_mark=False) return str(tidy.parseString(output, **options)) return output
class NonXHTMLFragment(athena.LiveFragment): circle = tags.Proto("circle") docFactory = loaders.stan( circle(xmlns="http://www.w3.org/2000/svg", render=tags.directive("liveFragment")))
def test_nosingleton(self): for x in ('div', 'span', 'script', 'iframe'): self.assertEquals(self.render(tags.Proto(x)()), '<%(tag)s></%(tag)s>' % {'tag': x})
def test_singletons(self): for x in ('img', 'br', 'hr', 'base', 'meta', 'link', 'param', 'area', 'input', 'col', 'basefont', 'isindex', 'frame'): self.assertEquals(self.render(tags.Proto(x)()), '<%s />' % x)
"""Really Simple Syndication. Provides a Page subclass which renders an RSS 2.0 feed for a given channel. """ from nevow import inevow, loaders, rend, tags from zope.interface import implements _RSS_TAGS = ('rss', 'channel', 'link', 'title', 'copyright', 'description', 'item', 'author', 'pubDate', 'guid', 'language', 'lastBuildDate') RSS = type('RSS', (object, ), dict([(k, tags.Proto(k)) for k in _RSS_TAGS])) class Feed(rend.Page): implements(inevow.IResource) """ @type original: A L{hyperbola.hyperblurb.Blurb}. @ivar original: The item whose children are to be rendered. @type title: C{unicode} @ivar title: This channel's title @type link: C{str} @ivar link: The URL associated with this channel @type description: C{str} @ivar description: A summary of the purpose of this channel @type copyright: C{str} @ivar copyright: An implement of the power structure employed towards the oppression of the working class.