PyBlosxom with Paste
Yury Yurevich <[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.user |
|---|---|
| Message-ID | <[email protected]> |
Hello. I've found in PyBlosxom's TODO-list: > PASTE/WSGI > - Also, it'd be way cool if we could do: > > paster serve myblog.ini > > and have Paste serve it. Paste and WSGI are definitely the way > forward. If we fix PyBlosxom to be friendly with Paste and > WSGI, then PyBlosxom is a lot more useful to a lot more people. So I've wrote glue-code for running PyBlosxom through Paste (and not only running, but also configurating through it). Have fun! P.S. I'm not subscribed to list, so please make a carbon copy of answers to me. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ pyblosxom-users mailing list pyblosxom-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
pasted_pyblosxom.py
(text/x-python, 1.5 KB)
#!/usr/bin/python
import sys
from paste import cgitb_catcher
from Pyblosxom import tools, pyblosxom as blog
class PyBlosxomWSGIApp(object):
"""
General WSGI app for PyBlosxom
"""
def __init__(self, config):
"""
Make WSGI app for PyBlosxom
config - dict-like config object
"""
# hack for config
# because paste's config values are always strings,
# but some PyBlosxom values are expected to be ints,
# so convert explicitly
_config = {}
for key, value in config.items():
if isinstance(value, basestring) and value.isdigit():
_config[key] = int(value)
else:
_config[key] = value
self.config = _config
if "codebase" in _config:
sys.path.insert(0, _config["codebase"])
def __call__(self, env, start_response):
"""
Run the WSGI app
"""
if "PATH_INFO" not in env:
env["PATH_INFO"] = ""
p = blog.PyBlosxom(self.config, env)
p.run()
pyresponse = p.getResponse()
start_response(pyresponse.status,
list(pyresponse.headers.items()))
pyresponse.seek(0)
return [pyresponse.read()]
def pyblosxom_app_factory(global_config, **local_config):
"""
App factory for paste
"""
conf = global_config.copy()
conf.update(local_config)
conf.update(dict(local_config=local_config, global_config=global_config))
return cgitb_catcher.make_cgitb_middleware(PyBlosxomWSGIApp(conf), global_config)
blog.ini
(text/plain, 495 B)
[DEFAULT] debug = True [server:main] use = egg:Paste#http host = 0.0.0.0 port = 5000 [app:main] paste.app_factory = pasted_pyblosxom:pyblosxom_app_factory # PyBlosxom config here blog_title = WSGIsh Blog blog_description = PyBlosxom with Paste/WSGI touch blog_author = pythy blog_email = [email protected] blog_language = ru blog_encoding = utf-8 blog_rights = Copyright 2007 Yury Yurevich datadir = /tmp/pyblog depth = 0 num_entries = 5 default_flavour = html