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

Delta Between Two Patch Sets: sitescripts/web.py

Issue 8327353: Crawler backend (Closed)
Left Patch Set: Created Sept. 27, 2012, 6:22 a.m.
Right Patch Set: Created Sept. 27, 2012, 2:15 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « sitescripts/hg/bin/irchook.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This Source Code is subject to the terms of the Mozilla Public License 3 # This Source Code is subject to the terms of the Mozilla Public License
4 # version 2.0 (the "License"). You can obtain a copy of the License at 4 # version 2.0 (the "License"). You can obtain a copy of the License at
5 # http://mozilla.org/MPL/2.0/. 5 # http://mozilla.org/MPL/2.0/.
6 6
7 import base64 7 import base64
8 from sitescripts.utils import get_config 8 from sitescripts.utils import get_config
9 9
10 handlers = {} 10 handlers = {}
11 authenticated_users = {} 11 authenticated_users = {}
12 12
13 def url_handler(url): 13 def url_handler(url):
14 def decorator(func): 14 def decorator(func):
15 registerUrlHandler(url, func) 15 registerUrlHandler(url, func)
16 return func 16 return func
17 return decorator 17 return decorator
18 18
19 def registerUrlHandler(url, func): 19 def registerUrlHandler(url, func):
20 if url in handlers: 20 if url in handlers:
21 raise Exception('A handler for url %s is already registered' % url) 21 raise Exception('A handler for url %s is already registered' % url)
22 handlers[url] = func 22 handlers[url] = func
23 23
24 def basic_auth(f): 24 def basic_auth(config_section = "DEFAULT"):
Wladimir Palant 2012/09/27 07:34:17 This should accept an optional config_section para
Felix Dahlke 2012/09/27 09:26:24 Done. Somehow thought authenticate was used direct
25 return lambda environ, start_response: authenticate(f, environ, start_response ) 25 def decorator(function):
26 def authenticating_wrapper(environ, start_response):
27 return authenticate(function, environ, start_response, config_section)
28 return authenticating_wrapper
29 return decorator
Wladimir Palant 2012/09/27 14:24:13 I already suspected that the old version didn't wo
26 30
27 def authenticate(f, environ, start_response, config_section = "DEFAULT"): 31 def authenticate(f, environ, start_response, config_section):
28 if "HTTP_AUTHORIZATION" in environ: 32 if "HTTP_AUTHORIZATION" in environ:
29 auth = environ["HTTP_AUTHORIZATION"].split() 33 auth = environ["HTTP_AUTHORIZATION"].split()
30 if len(auth) == 2: 34 if len(auth) == 2:
31 if auth[0].lower() == "basic": 35 if auth[0].lower() == "basic":
32 username, password = base64.b64decode(auth[1]).split(":") 36 username, password = base64.b64decode(auth[1]).split(":")
33 config = get_config() 37 config = get_config()
34 expected_username = config.get(config_section, "basic_auth_username") 38 expected_username = config.get(config_section, "basic_auth_username")
35 expected_password = config.get(config_section, "basic_auth_password") 39 expected_password = config.get(config_section, "basic_auth_password")
36 if username == expected_username and password == expected_password: 40 if username == expected_username and password == expected_password:
37 return f(environ, start_response) 41 return f(environ, start_response)
38 42
39 realm = get_config().get("DEFAULT", "basic_auth_realm") 43 realm = get_config().get("DEFAULT", "basic_auth_realm")
40 start_response("401 UNAUTHORIZED", 44 start_response("401 UNAUTHORIZED",
41 [("WWW-Authenticate", 'Basic realm="%s"' % realm)]) 45 [("WWW-Authenticate", 'Basic realm="%s"' % realm)])
42 return "" 46 return ""
43 47
44 import openid.web.server 48 import openid.web.server
45 import subscriptions.web.fallback 49 import subscriptions.web.fallback
46 import crashes.web.submitCrash 50 import crashes.web.submitCrash
47 import reports.web.submitReport 51 import reports.web.submitReport
48 import reports.web.updateReport 52 import reports.web.updateReport
49 import reports.web.showDigest 53 import reports.web.showDigest
50 import extensions.web.translationCheck 54 import extensions.web.translationCheck
51 import tasks.web.tasks 55 import tasks.web.tasks
52 import formmail.web.formmail 56 import formmail.web.formmail
53 import crawler.web.crawler 57 import crawler.web.crawler
LEFTRIGHT

Powered by Google App Engine
This is Rietveld