#!/usr/bin/python # -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil; -*- # # aggiungiamo la directory corrente al path (se non presente) # import sys wsgilib = '/'.join( __file__.split('/')[:-1] ) if wsgilib not in sys.path: sys.path.insert(0, wsgilib) # # inizializzazione path per templating # from decorators import WSGITemplate WSGITemplate( basedir='views' ) # # importazione handler # from router import WSGIRouter, WSGISmartRouter # # index: esempio minimo di applicazione WSGI (pagina iniziale) # def index( environ, start_response ): start_response( '200 OK', [('content-type', 'text/html')] ) return [ 'Index was here' ] # # hello: esempio minimo di applicazione WSGI # def hello( environ, start_response ): start_response( '200 OK', [('content-type', 'text/html')] ) return [ 'Simon says: Hello world!' ] # # fallback: mostra tutti i parametri disponibili all'applicazione WSGI # def fallback( environ, start_response ): from pprint import pformat start_response( '200 OK', [('Content-Type', 'text/html')] ) return [ '-- EMBEDDED MODE --' if not environ.get('mod_wsgi.process_group','') else '-- DAEMON MODE --', '
', pformat( environ, width=132 ).replace('\n','
\n'), ] # # definiamo gli handler per le url che vogliamo servire # from test_mysql import simple_mysql handlers = ( ( r'/', index ), ( r'/hello', hello ), ( r'/mysql', simple_mysql ), ) # # !!! mod_wsgi richiede che la nostra applicazione si chiami 'application' # application = WSGISmartRouter( handlers, fallback, cont_dir='controllers' )