#!/usr/bin/env python2.4
# -*- coding: utf-8 -*-
"""
WWW-sovellukset (TJTA270) Viikkotehtävän ratkaisu
Copyright (c) Esa-Matti Suuronen
This file is part of Sokkeli web framework.
Sokkeli is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Sokkeli is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Sokkeli. If not, see .
"""
import cgi
import sapluuna
import config
def html(filename, **vars):
"""
Simple web page response with correct headers. Depends on user config.
"""
template = sapluuna.read_template_from_file(filename,
config.template_dir)
return sapluuna.Sapluuna(template, vars)
def render(filename, **vars):
"""
Simple web page response with correct headers. Depends on user config.
"""
template = sapluuna.read_template_from_file(filename,
config.template_dir)
return sapluuna.Sapluuna(template, vars).render()
def wrap_with(filename, *wrapper_args, **wrapper_kwargs):
"""
Simple decorator for wrapping content to a exterior shell.
e.g. xhtml doctypes etc. Input file must contain %(content)s
"""
def func_wrapper(input_func):
def content_wrapper(*input_args, **input_kwargs):
return html(filename, content=input_func(*input_args,
**input_kwargs),
**wrapper_kwargs)
return content_wrapper
return func_wrapper
def escape(quote=None):
"""
Decorator version of cgi.escape
"""
def func_wrapper(input_func):
def content_wrapper(*input_args, **input_kwargs):
return cgi.escape(input_func(*input_args, **input_kwargs), quote)
return content_wrapper
return func_wrapper