您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12 年前
12 年前
12 年前
12 年前
12 年前
11 年前
12 年前
12 年前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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, NotFound
  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. def handle_session_stopped():
  19. res = Response("""<html>
  20. <body style="background-color: #EEE;">
  21. <h3 style="width: 900px; background-color: #FFF; border: 2px solid #AAA; padding: 20px; font-family: Arial; margin: 20px auto">
  22. Updating.
  23. We will be back in a few moments...
  24. </h3>
  25. </body>
  26. </html>""")
  27. res.status_code = 503
  28. res.content_type = 'text/html'
  29. return res
  30. @Request.application
  31. def application(request):
  32. webnotes.local.request = request
  33. try:
  34. site = webnotes.utils.get_site_name(request.host)
  35. webnotes.init(site=site)
  36. webnotes.local.form_dict = webnotes._dict({ k:v[0] if isinstance(v, (list, tuple)) else v \
  37. for k, v in (request.form or request.args).iteritems() })
  38. webnotes.local._response = Response()
  39. try:
  40. webnotes.http_request = webnotes.auth.HTTPRequest()
  41. except webnotes.AuthenticationError, e:
  42. pass
  43. if webnotes.form_dict.cmd:
  44. webnotes.handler.handle()
  45. elif webnotes.local.request.method in ('GET', 'HEAD'):
  46. webnotes.webutils.render(webnotes.request.path[1:])
  47. else:
  48. raise NotFound
  49. except HTTPException, e:
  50. return e
  51. except webnotes.SessionStopped, e:
  52. webnotes.local._response = handle_session_stopped()
  53. finally:
  54. if webnotes.conn:
  55. webnotes.conn.close()
  56. return webnotes.local._response
  57. application = local_manager.make_middleware(application)
  58. if not os.environ.get('NO_STATICS'):
  59. application = StaticDataMiddleware(application, {
  60. '/': 'public',
  61. })
  62. def serve(port=8000, profile=False):
  63. webnotes.validate_versions()
  64. global application
  65. from werkzeug.serving import run_simple
  66. if profile:
  67. application = ProfilerMiddleware(application)
  68. run_simple('0.0.0.0', int(port), application, use_reloader=True,
  69. use_debugger=True, use_evalex=True)