| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 content_length = int(environ['CONTENT_LENGTH']) | 84 content_length = int(environ['CONTENT_LENGTH']) |
| 85 except (KeyError, ValueError): | 85 except (KeyError, ValueError): |
| 86 content_length = None | 86 content_length = None |
| 87 if content_length is None or content_length < 0: | 87 if content_length is None or content_length < 0: |
| 88 return send_simple_response(start_response, 411) | 88 return send_simple_response(start_response, 411) |
| 89 | 89 |
| 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, 'Form data must use UTF-8 ') | 94 return send_simple_response(start_response, 400, 'Invalid form data encodi ng') |
|
Wladimir Palant
2015/04/24 22:50:48
'Invalid form data encoding'?
Sebastian Noack
2015/04/27 13:39:10
Not sure why this message would be any better, but
| |
| 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 multiplex(environ, start_response): | 100 def multiplex(environ, start_response): |
| 101 try: | 101 try: |
| 102 path = environ["PATH_INFO"] | 102 path = environ["PATH_INFO"] |
| 103 try: | 103 try: |
| 104 handler = handlers[path] | 104 handler = handlers[path] |
| 105 except KeyError: | 105 except KeyError: |
| 106 handler = handlers[re.sub(r"[^/]+$", "", path)] | 106 handler = handlers[re.sub(r"[^/]+$", "", path)] |
| 107 except KeyError: | 107 except KeyError: |
| 108 start_response("404 Not Found", [("Content-Type", "text/plain")]) | 108 start_response("404 Not Found", [("Content-Type", "text/plain")]) |
| 109 return ["Not Found"] | 109 return ["Not Found"] |
| 110 | 110 |
| 111 return handler(environ, start_response) | 111 return handler(environ, start_response) |
| 112 | 112 |
| 113 for module in set(get_config().options("multiplexer")) - set(get_config().defaul ts()): | 113 for module in set(get_config().options("multiplexer")) - set(get_config().defaul ts()): |
| 114 module_path = get_config().get("multiplexer", module) | 114 module_path = get_config().get("multiplexer", module) |
| 115 if module_path: | 115 if module_path: |
| 116 imp.load_source(module, module_path) | 116 imp.load_source(module, module_path) |
| 117 else: | 117 else: |
| 118 importlib.import_module(module) | 118 importlib.import_module(module) |
| LEFT | RIGHT |