All pastes #498067 Raw Edit

Something

public python v1 · immutable
·published 2007-05-20 05:29 UTC
rendered paste body
from markdown import markdownfrom smartypants import smartyPants as smartypants###### Decorators ######def template(t):    """ Wraps the decorator function's output with a        template engine like Markdown or SmartyPants """    def wrap(func):        def d(*a, **k): return t(func(*a, **k))        return d    return wrapclass Nervous(object):    def __init__(self):        self.data = {}    def add(self, id):        """ Does not modify the function but does place            it in our `data` dict for happiness' sake """        def tally(func):            if id in self.data: self.data[id] += [func]            else: self.data[id] = [func]            return func        return tally            def fire(self, id, *args):        """ Iterate over the dict, applying each function            and storing the results, passing a cumulative            results `r` string each time """        r = ('',)        for f in self.data[id]: r = f(*(args+r))        return rnervous = Nervous()###### Logic ######chdire = ''def index(req):    import os    global chdire    chdire = os.path.dirname(req.filename)        art = nervous.fire('find_art', req.args[4:])    template = nervous.fire('find_template')    return template % {        'site': 'http://localhost:8080/baker',        'content': art,    }@nervous.add('find_art')@template(markdown)@template(smartypants)def folder_search(file, result):    if not file: file = 'HomePage'    file = '/art/' + file    try:        return open(chdire + file, 'r').read()    except IOError:        return "Cannot find %s" % file@nervous.add('find_template')def header_footer(result):    file = chdire + '/templates/header_footer.html'    return open(file).read()