PageRenderTime 28ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/functional/example-app/example_app.py

https://bitbucket.org/ianb/silverlining/
Python | 38 lines | 36 code | 2 blank | 0 comment | 8 complexity | ecb0e7aaf5ad07ddf13070463c912684 MD5 | raw file
Possible License(s): GPL-2.0
  1. import os
  2. import sys
  3. import traceback
  4. def application(environ, start_response):
  5. try:
  6. path_info = environ['PATH_INFO']
  7. if path_info == '/update':
  8. body = []
  9. for name, value in sorted(os.environ.items()):
  10. if name.startswith('SILVER') or name.startswith('CONFIG_'):
  11. body.append('env %s=%s' % (name, value))
  12. body.append('wsgi.multiprocess=%r' % environ['wsgi.multiprocess'])
  13. body.append('wsgi.multithread=%r' % environ['wsgi.multithread'])
  14. body.append('path=%r %r' % (environ['SCRIPT_NAME'], environ['PATH_INFO']))
  15. body.append('Update run.')
  16. body = '\n'.join(body)
  17. elif path_info == '/write-root':
  18. write_root = os.environ['CONFIG_WRITABLE_ROOT']
  19. host = environ['HTTP_HOST'].split(':')[0]
  20. host_dir = os.path.join(write_root, host)
  21. if not os.path.exists(host_dir):
  22. os.mkdir(host_dir)
  23. open(os.path.join(write_root, 'test-writable.txt'), 'w').write('test writable')
  24. open(os.path.join(host_dir, 'test-hosted.txt'), 'w').write('test hosted')
  25. body = 'WRITABLE_ROOT=%s' % write_root
  26. else:
  27. body = 'INSTANCE=%s' % os.environ['SILVER_INSTANCE_NAME']
  28. start_response('200 OK', [('Content-type', 'text/plain')])
  29. environ['wsgi.errors'].write('Executed application\n')
  30. print 'This is stdout'
  31. print >> sys.stderr, 'This is stderr'
  32. return [body]
  33. except:
  34. start_response('500 Server Error', [('Content-type', 'text/plain')])
  35. exc = traceback.format_exc()
  36. return [exc]