Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

59 righe
1.5 KiB

  1. #!/usr/bin/python
  2. # -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil; -*-
  3. #
  4. # aggiungiamo la directory corrente al path (se non presente)
  5. #
  6. import sys
  7. wsgilib = '/'.join( __file__.split('/')[:-1] )
  8. if wsgilib not in sys.path:
  9. sys.path.insert(0, wsgilib)
  10. #
  11. # importazione handler
  12. #
  13. from router import WSGIRouter, WSGISmartRouter
  14. #
  15. # index: esempio minimo di applicazione WSGI (pagina iniziale)
  16. #
  17. def index( environ, start_response ):
  18. start_response( '200 OK', [('content-type', 'text/html')] )
  19. return [ 'Index was here' ]
  20. #
  21. # hello: esempio minimo di applicazione WSGI
  22. #
  23. def hello( environ, start_response ):
  24. start_response( '200 OK', [('content-type', 'text/html')] )
  25. return [ 'Simon says: Hello world!' ]
  26. #
  27. # fallback: mostra tutti i parametri disponibili all'applicazione WSGI
  28. #
  29. def fallback( environ, start_response ):
  30. from pprint import pformat
  31. start_response( '200 OK', [('Content-Type', 'text/html')] )
  32. return [
  33. '-- EMBEDDED MODE --' if not environ.get('mod_wsgi.process_group','') else '-- DAEMON MODE --',
  34. '<form method="POST"><input type="submit"/></form>',
  35. pformat( environ, width=132 ).replace('\n','<br>\n'),
  36. ]
  37. #
  38. # definiamo gli handler per le url che vogliamo servire
  39. #
  40. from test_mysql import simple_mysql
  41. handlers = (
  42. ( r'/', index ),
  43. ( r'/hello', hello ),
  44. ( r'/mysql', simple_mysql ),
  45. )
  46. #
  47. # !!! mod_wsgi richiede che la nostra applicazione si chiami 'application'
  48. #
  49. application = WSGISmartRouter( handlers, fallback, cont_dir='controllers' )