| LEFT | RIGHT | 
|---|
| (no file at all) |  | 
| 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 import re | 
| 22 import httplib | 22 import httplib | 
|  | 23 import urllib | 
| 23 from urlparse import parse_qsl | 24 from urlparse import parse_qsl | 
| 24 | 25 | 
| 25 from sitescripts.utils import get_config | 26 from sitescripts.utils import get_config | 
| 26 | 27 | 
| 27 handlers = {} | 28 handlers = {} | 
| 28 authenticated_users = {} | 29 authenticated_users = {} | 
| 29 | 30 | 
| 30 def url_handler(url): | 31 def url_handler(url): | 
| 31   def decorator(func): | 32   def decorator(func): | 
| 32     registerUrlHandler(url, func) | 33     registerUrlHandler(url, func) | 
| 33     return func | 34     return func | 
| 34   return decorator | 35   return decorator | 
| 35 | 36 | 
| 36 def registerUrlHandler(url, func): | 37 def registerUrlHandler(url, func): | 
| 37   if url in handlers: | 38   if url in handlers: | 
| 38     raise Exception('A handler for url %s is already registered' % url) | 39     raise Exception('A handler for url %s is already registered' % url) | 
| 39   handlers[url] = func | 40   handlers[url] = func | 
|  | 41 | 
|  | 42 # https://www.python.org/dev/peps/pep-0333/#url-reconstruction | 
|  | 43 def request_path(environ, include_query=True): | 
|  | 44   path = urllib.quote(environ.get("SCRIPT_NAME", "") + | 
|  | 45                       environ.get("PATH_INFO", "")) | 
|  | 46   query_string = environ.get("QUERY_STRING", "") | 
|  | 47   if query_string and include_query: | 
|  | 48     path += "?" + urllib.quote(query_string) | 
|  | 49   return path | 
| 40 | 50 | 
| 41 def basic_auth(config_section = "DEFAULT"): | 51 def basic_auth(config_section = "DEFAULT"): | 
| 42   def decorator(function): | 52   def decorator(function): | 
| 43     def authenticating_wrapper(environ, start_response): | 53     def authenticating_wrapper(environ, start_response): | 
| 44       return authenticate(function, environ, start_response, config_section) | 54       return authenticate(function, environ, start_response, config_section) | 
| 45     return authenticating_wrapper | 55     return authenticating_wrapper | 
| 46   return decorator | 56   return decorator | 
| 47 | 57 | 
| 48 def authenticate(f, environ, start_response, config_section): | 58 def authenticate(f, environ, start_response, config_section): | 
| 49   if "HTTP_AUTHORIZATION" in environ: | 59   if "HTTP_AUTHORIZATION" in environ: | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 114     return ["Not Found"] | 124     return ["Not Found"] | 
| 115 | 125 | 
| 116   return handler(environ, start_response) | 126   return handler(environ, start_response) | 
| 117 | 127 | 
| 118 for module in set(get_config().options("multiplexer")) - set(get_config().defaul
     ts()): | 128 for module in set(get_config().options("multiplexer")) - set(get_config().defaul
     ts()): | 
| 119   module_path = get_config().get("multiplexer", module) | 129   module_path = get_config().get("multiplexer", module) | 
| 120   if module_path: | 130   if module_path: | 
| 121     imp.load_source(module, module_path) | 131     imp.load_source(module, module_path) | 
| 122   else: | 132   else: | 
| 123     importlib.import_module(module) | 133     importlib.import_module(module) | 
| LEFT | RIGHT | 
|---|