Пример #1
0
def create_handler(request, name):
    path = os.path.join(request.store.root, 'templates')    
    target_path = os.path.join(path, name)
    if os.path.exists(target_path + '.py'):
        f = open(target_path, 'U')
        try:
            target = imp.load_source('singleshotstatic%s' % name, target_path, f)
        finally:
            f.close()
        return path_act(target.act)
    elif os.path.exists(target_path + '.html'):
        return pages.template_handler(target_path + '.html')
    else:
        return pages.template_handler(request.store.find_template('404.html'))
Пример #2
0
def page_handlers(path):
    if not os.path.exists(path):
        return
    for item in os.listdir(path):
        name, ext = os.path.splitext(item)
        target_path = os.path.join(path, item)
        if ext == '.py':
            f = open(target_path, 'U')
            try:
                target = imp.load_source('singleshotstatic%s' % name, target_path, f)
            finally:
                f.close()
            yield r'/%s(/(?P<path>.*))?' % name
            yield path_act(target.act)
        elif ext == '.html':
            yield r'/%s(/(?P<path>.*))?' % name
            yield pages.template_handler(target_path)