Created
November 29, 2008 17:27
-
-
Save darwin/30262 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Application(object): | |
def __call__(self, environ, start_response): | |
import logging | |
import base64 | |
from root import LOCAL_DEVELOPMENT | |
request = webapp.Request(environ) | |
response = webapp.Response() | |
Application.active_instance = self | |
handler = AppHandler() | |
handler.initialize(request, response) | |
if not LOCAL_DEVELOPMENT: | |
# check if HTTP_AUTHORIZATION ISSET, DECODE & SPLIT | |
username = "" | |
password = "" | |
try: | |
(method, encoded) = environ['HTTP_AUTHORIZATION'].split() | |
if method.lower() == 'basic': | |
(username, password) = base64.b64decode(encoded).split(':') | |
except: | |
pass | |
# check user credentials | |
if not (password=='xxx'): | |
handler.response.headers['WWW-Authenticate'] = 'Basic realm=pagebout' | |
handler.response.set_status(401) | |
handler.response.wsgi_write(start_response) | |
return [''] | |
groups = [] | |
try: | |
method = environ['REQUEST_METHOD'] | |
if method == 'GET': | |
handler.get(*groups) | |
elif method == 'POST': | |
handler.post(*groups) | |
elif method == 'HEAD': | |
handler.head(*groups) | |
elif method == 'OPTIONS': | |
handler.options(*groups) | |
elif method == 'PUT': | |
handler.put(*groups) | |
elif method == 'DELETE': | |
handler.delete(*groups) | |
elif method == 'TRACE': | |
handler.trace(*groups) | |
else: | |
handler.error(501) | |
except Exception, e: | |
# beep | |
import sys | |
sys.__stdout__.write('\a') | |
sys.__stdout__.flush() | |
from lib.nice_traceback import show_error | |
show_error(handler, 500) | |
handler.response.wsgi_write(start_response) | |
return [''] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment