+

:4736 Function create_function() is deprecated [8192]

Last commit for mycoserver/application.py: 7004713412b51ec58cf01149ba736fadf769acaf

Initial commit

Benjamin Renard [2014-01-12 00:33:07]
Initial commit
  1. # -*- coding: utf-8 -*-
  2.  
  3.  
  4. """Middleware initialization"""
  5.  
  6.  
  7. import logging.config
  8. import os
  9.  
  10. from paste.cascade import Cascade
  11. from paste.urlparser import StaticURLParser
  12. from weberror.errormiddleware import ErrorMiddleware
  13.  
  14. from . import configuration, context, controllers, templates
  15.  
  16. import db
  17.  
  18.  
  19. def make_app(global_conf, **app_conf):
  20. """Create a WSGI application and return it
  21.  
  22. ``global_conf``
  23. The inherited configuration for this application. Normally from
  24. the [DEFAULT] section of the Paste ini file.
  25.  
  26. ``app_conf``
  27. The application's local configuration. Normally specified in
  28. the [app:<name>] section of the Paste ini file (where <name>
  29. defaults to main).
  30. """
  31. logging.config.fileConfig(global_conf['__file__'])
  32. app_ctx = context.Context()
  33. app_ctx.conf = configuration.load_configuration(global_conf, app_conf)
  34. app_ctx.templates = templates.load_templates(app_ctx)
  35. app_ctx.db = db.DB(
  36. app_ctx.conf.get('dbhost','localhost'),
  37. app_ctx.conf.get('dbuser','myco'),
  38. app_ctx.conf.get('dbpass','password'),
  39. app_ctx.conf.get('dbname','myco'),
  40. )
  41. if not app_ctx.db.connect():
  42. logging.error('Failed to connect DB')
  43. app = controllers.make_router()
  44. app = context.make_add_context_to_request(app, app_ctx)
  45. if not app_ctx.conf['debug']:
  46. app = ErrorMiddleware(
  47. app,
  48. error_email=app_ctx.conf['email_to'],
  49. error_log=app_ctx.conf.get('error_log', None),
  50. error_message=app_ctx.conf.get('error_message', 'An internal server error occurred'),
  51. error_subject_prefix=app_ctx.conf.get('error_subject_prefix', 'Web application error: '),
  52. from_address=app_ctx.conf['from_address'],
  53. smtp_server=app_ctx.conf.get('smtp_server', 'localhost'),
  54. )
  55. app = Cascade([StaticURLParser(os.path.join(app_ctx.conf['app_dir'], 'static')), app])
  56. app.ctx = app_ctx
  57. return app