source: TI12-security/trunk/NDGSecurity/python/Tests/query_arg_test/test_query_arg.py @ 7572

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDGSecurity/python/Tests/query_arg_test/test_query_arg.py@7572
Revision 7572, 1.2 KB checked in by pjkersha, 10 years ago (diff)

2.0.0 release for NDG Security

  • made extra_requires entry in setup for ndg_xacml
Line 
1'''
2Created on 27 Sep 2010
3
4@author: pjkersha
5'''
6import logging
7logging.basicConfig(level=logging.INFO)
8log = logging.getLogger(__name__)
9from webob import Request
10   
11class QueryArgFilter(object):
12    def __init__(self, app):
13        self.app = app
14       
15    def __call__(self, environ, start_response):
16        log.info("QueryArgFilter called ...")
17        request = Request(environ)
18        if environ.get('QUERY_STRING'):
19            response = 'Application response was filtered'
20            start_response('200 OK', 
21                           [('Content-type', 'text/html'),
22                            ('Content-length', str(len(response)))])
23            return [response]
24        else:   
25            return self.app(environ, start_response)
26   
27   
28def hello_application(environ, start_response):
29    log.info("hello_application called ...")
30    response = 'Hello'
31    start_response('200 OK', 
32                   [('Content-type', 'text/html'),
33                    ('Content-length', str(len(response)))])
34    return [response]
35
36
37if __name__ == '__main__':
38    from paste.httpserver import serve
39
40    app = QueryArgFilter(hello_application)
41    serve(app, host='0.0.0.0', port=5000)
Note: See TracBrowser for help on using the repository browser.