darwin (owner)

Revisions

gist: 30262 Download_button fork
public
Public Clone URL: git://gist.github.com/30262.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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 ['']