Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: sitescripts/web.py

Issue 29328589: Issue 3122 - Add testpages.web.sitekey_frame URL handler (Closed)
Patch Set: Addressed feedback Created Oct. 7, 2015, 4:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sitescripts/utils.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 raw_data = parse_qsl(environ['wsgi.input'].read(content_length)) 90 raw_data = parse_qsl(environ['wsgi.input'].read(content_length))
91 try: 91 try:
92 data = {k.decode('utf-8'): v.decode('utf-8') for k, v in raw_data} 92 data = {k.decode('utf-8'): v.decode('utf-8') for k, v in raw_data}
93 except UnicodeDecodeError: 93 except UnicodeDecodeError:
94 return send_simple_response(start_response, 400, 'Invalid form data encodi ng') 94 return send_simple_response(start_response, 400, 'Invalid form data encodi ng')
95 95
96 return func(environ, start_response, data) 96 return func(environ, start_response, data)
97 97
98 return wrapper 98 return wrapper
99 99
100 def get_handler(path):
101 """Returns the URL handler for the given path if avaliable, otherwise
102 throws a KeyError exception."""
103 try:
104 handler = handlers[path]
105 except KeyError:
106 handler = handlers[re.sub(r"[^/]+$", "", path)]
107 return handler
108
100 def multiplex(environ, start_response): 109 def multiplex(environ, start_response):
101 try: 110 try:
102 path = environ["PATH_INFO"] 111 handler = get_handler(environ["PATH_INFO"])
103 try:
104 handler = handlers[path]
105 except KeyError:
106 handler = handlers[re.sub(r"[^/]+$", "", path)]
107 except KeyError: 112 except KeyError:
108 start_response("404 Not Found", [("Content-Type", "text/plain")]) 113 start_response("404 Not Found", [("Content-Type", "text/plain")])
109 return ["Not Found"] 114 return ["Not Found"]
110 115
111 return handler(environ, start_response) 116 return handler(environ, start_response)
112 117
113 for module in set(get_config().options("multiplexer")) - set(get_config().defaul ts()): 118 for module in set(get_config().options("multiplexer")) - set(get_config().defaul ts()):
114 module_path = get_config().get("multiplexer", module) 119 module_path = get_config().get("multiplexer", module)
115 if module_path: 120 if module_path:
116 imp.load_source(module, module_path) 121 imp.load_source(module, module_path)
117 else: 122 else:
118 importlib.import_module(module) 123 importlib.import_module(module)
OLDNEW
« no previous file with comments | « sitescripts/utils.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld