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

Side by Side Diff: sitescripts/web.py

Issue 6209629180657664: Issue 2169 - Unify development and production implementation of multiplexer (Closed)
Patch Set: Created March 23, 2015, 4:23 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 | « multiplexer.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,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details. 13 # GNU General Public License for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17 17
18 import base64 18 import base64
19 import imp 19 import imp
20 import importlib 20 import importlib
21 import re
21 from sitescripts.utils import get_config 22 from sitescripts.utils import get_config
22 23
23 handlers = {} 24 handlers = {}
24 authenticated_users = {} 25 authenticated_users = {}
25 26
26 def url_handler(url): 27 def url_handler(url):
27 def decorator(func): 28 def decorator(func):
28 registerUrlHandler(url, func) 29 registerUrlHandler(url, func)
29 return func 30 return func
30 return decorator 31 return decorator
(...skipping 20 matching lines...) Expand all
51 expected_username = config.get(config_section, "basic_auth_username") 52 expected_username = config.get(config_section, "basic_auth_username")
52 expected_password = config.get(config_section, "basic_auth_password") 53 expected_password = config.get(config_section, "basic_auth_password")
53 if username == expected_username and password == expected_password: 54 if username == expected_username and password == expected_password:
54 return f(environ, start_response) 55 return f(environ, start_response)
55 56
56 realm = get_config().get("DEFAULT", "basic_auth_realm") 57 realm = get_config().get("DEFAULT", "basic_auth_realm")
57 start_response("401 UNAUTHORIZED", 58 start_response("401 UNAUTHORIZED",
58 [("WWW-Authenticate", 'Basic realm="%s"' % realm)]) 59 [("WWW-Authenticate", 'Basic realm="%s"' % realm)])
59 return "" 60 return ""
60 61
62 def multiplex(environ, start_response):
63 try:
64 path = environ["PATH_INFO"]
65 try:
66 handler = handlers[path]
67 except KeyError:
68 handler = handlers[re.sub(r"[^/]+$", "", path)]
69 except KeyError:
70 start_response("404 Not Found", [("Content-Type", "text/plain")])
71 return ["Not Found"]
72
73 return handler(environ, start_response)
74
61 for module in set(get_config().options("multiplexer")) - set(get_config().defaul ts()): 75 for module in set(get_config().options("multiplexer")) - set(get_config().defaul ts()):
62 module_path = get_config().get("multiplexer", module) 76 module_path = get_config().get("multiplexer", module)
63 if module_path: 77 if module_path:
64 imp.load_source(module, module_path) 78 imp.load_source(module, module_path)
65 else: 79 else:
66 importlib.import_module(module) 80 importlib.import_module(module)
OLDNEW
« no previous file with comments | « multiplexer.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld