Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

70 linhas
1.6 KiB

  1. import sys, os
  2. import json
  3. sys.path.insert(0, '.')
  4. sys.path.insert(0, 'app')
  5. sys.path.insert(0, 'lib')
  6. from werkzeug.wrappers import Request, Response
  7. from werkzeug.local import LocalManager
  8. from webnotes.middlewares import StaticDataMiddleware
  9. from werkzeug.exceptions import HTTPException
  10. from werkzeug.contrib.profiler import ProfilerMiddleware
  11. from webnotes import get_config
  12. import mimetypes
  13. import webnotes
  14. import webnotes.handler
  15. import webnotes.auth
  16. import webnotes.webutils
  17. local_manager = LocalManager([webnotes.local])
  18. @Request.application
  19. def application(request):
  20. webnotes.local.request = request
  21. try:
  22. site = webnotes.utils.get_site_name(request.host)
  23. webnotes.init(site=site)
  24. webnotes.local.form_dict = webnotes._dict({ k:v[0] if isinstance(v, (list, tuple)) else v \
  25. for k, v in (request.form or request.args).iteritems() })
  26. webnotes.local._response = Response()
  27. try:
  28. webnotes.http_request = webnotes.auth.HTTPRequest()
  29. except webnotes.AuthenticationError, e:
  30. pass
  31. if webnotes.form_dict.cmd:
  32. webnotes.handler.handle()
  33. else:
  34. webnotes.webutils.render(webnotes.request.path[1:])
  35. except HTTPException, e:
  36. return e
  37. finally:
  38. if webnotes.conn:
  39. webnotes.conn.close()
  40. return webnotes._response
  41. application = local_manager.make_middleware(application)
  42. application = StaticDataMiddleware(application, {
  43. '/': 'public',
  44. })
  45. def serve(port=8000, profile=False):
  46. global application
  47. from werkzeug.serving import run_simple
  48. if profile:
  49. application = ProfilerMiddleware(application)
  50. run_simple('0.0.0.0', int(port), application, use_reloader=True,
  51. use_debugger=True, use_evalex=True)