view example/example.py @ 53:d9e712cfd098

STUB: bitsyauth/__init__.py
author Jeff Hammel <k0scist@gmail.com>
date Thu, 06 Mar 2014 22:27:26 -0800
parents 52713d176ab9
children
line wrap: on
line source

#!/usr/bin/env python

def example_app(environ, start_response):
  if environ['PATH_INFO'].strip('/') == 'authorization_required':
    user = environ.get('REMOTE_USER')
    if user:
      start_response("200 OK", [('Content-Type', 'text/plain'),
                                ('Content-Length', str(len(user)))])
      return [user]
    else:
      text = '401 Unauthorized'
      start_response("401 Unauthorized", [('Content-Type', 'text/plain'),
                                          ('Content-Length', str(len(text)))])
      return [text]
  text = """<html><body>
  <a href="/authorization_required">bet you can't go here!</a>
</body></html>"""
  start_response("200 OK", [('Content-Type', 'text/html'),
                            ('Content-Length', str(len(text)))])
  return [text]

if __name__ == '__main__':
  from wsgiref import simple_server
  server = simple_server.make_server('127.0.0.1', 12345, example_app)
  server.serve_forever()