25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.0 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. # inizializzazione path per templating
  12. #
  13. from decorators import WSGITemplate
  14. WSGITemplate( basedir='views' )
  15. #
  16. # inizializzazione connessione al db ( mysql )
  17. #
  18. from decorators import WSGIMySQL
  19. WSGIMySQL(
  20. dsn = dict(
  21. DB = "mywiki",
  22. HOST = "localhost",
  23. USER = "corso",
  24. PASSWORD = "pwdcorso"
  25. )
  26. )
  27. #
  28. # importazione handler definiti esternamente
  29. #
  30. from router import WSGIRouter, WSGISmartRouter
  31. #
  32. # index: esempio minimo di applicazione WSGI (pagina iniziale)
  33. #
  34. def index( environ, start_response ):
  35. start_response( '200 OK', [('content-type', 'text/html')] )
  36. return [ 'Index was here' ]
  37. #
  38. # hello: esempio minimo di applicazione WSGI
  39. #
  40. def hello( environ, start_response ):
  41. start_response( '200 OK', [('content-type', 'text/html')] )
  42. return [ 'Simon says: Hello world!' ]
  43. #
  44. # fallback: mostra tutti i parametri disponibili all'applicazione WSGI
  45. #
  46. def fallback( environ, start_response ):
  47. from pprint import pformat
  48. start_response( '200 OK', [('Content-Type', 'text/html')] )
  49. return [
  50. '-- EMBEDDED MODE --' if not environ.get('mod_wsgi.process_group','') else '-- DAEMON MODE --',
  51. '<form method="POST"><input type="submit"/></form>',
  52. pformat( environ, width=132 ).replace('\n','<br>\n'),
  53. ]
  54. #
  55. # definiamo gli handler per le url che vogliamo servire
  56. #
  57. ################################################################################ from test_mysql import simple_mysql
  58. handlers = (
  59. ( r'/', index ),
  60. ( r'/hello', hello ),
  61. ############################################################################ ( r'/mysql', simple_mysql ),
  62. )
  63. #
  64. # !!! mod_wsgi richiede che la nostra applicazione si chiami 'application'
  65. #
  66. application = WSGISmartRouter( handlers, fallback, cont_dir='controllers' )