Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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