OLD | NEW |
1 # This file is part of the Adblock Plus web scripts, | 1 # This file is part of the Adblock Plus web scripts, |
2 # Copyright (C) 2006-present eyeo GmbH | 2 # Copyright (C) 2006-present eyeo GmbH |
3 # | 3 # |
4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify |
5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as |
6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. |
7 # | 7 # |
8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 def make_handler(name, config): | 117 def make_handler(name, config): |
118 try: | 118 try: |
119 url = config['url'].value | 119 url = config['url'].value |
120 except (KeyError, AttributeError): | 120 except (KeyError, AttributeError): |
121 raise Exception('No URL configured for form handler: ' + name) | 121 raise Exception('No URL configured for form handler: ' + name) |
122 try: | 122 try: |
123 template = config['template'].value | 123 template = config['template'].value |
124 get_template(template, autoescape=False) | 124 get_template(template, autoescape=False) |
125 except (KeyError, AttributeError): | 125 except (KeyError, AttributeError): |
126 raise Exception('No template configured for form handler: ' + name) | 126 raise Exception('No template configured for form handler: ' + name) |
127 except (jinja2.TemplateNotFound): | 127 except jinja2.TemplateNotFound: |
128 raise Exception('Template not found at: ' + template) | 128 raise Exception('Template not found at: ' + template) |
129 try: | 129 try: |
130 fields = config['fields'] | 130 fields = config['fields'] |
131 for field, spec in fields.items(): | 131 for field, spec in fields.items(): |
132 spec.value = {s.strip() for s in spec.value.split(',')} | 132 spec.value = {s.strip() for s in spec.value.split(',')} |
133 except KeyError: | 133 except KeyError: |
134 raise Exception('No fields configured for form handler: ' + name) | 134 raise Exception('No fields configured for form handler: ' + name) |
135 if len(fields) == 0: | 135 if len(fields) == 0: |
136 raise Exception('No fields configured for form handler: ' + name) | 136 raise Exception('No fields configured for form handler: ' + name) |
137 | 137 |
(...skipping 24 matching lines...) Expand all Loading... |
162 start_response('200 OK', response_headers) | 162 start_response('200 OK', response_headers) |
163 return '' | 163 return '' |
164 | 164 |
165 return url, handler | 165 return url, handler |
166 | 166 |
167 | 167 |
168 conf_dict = conf_parse(get_config_items()) | 168 conf_dict = conf_parse(get_config_items()) |
169 for name, config in conf_dict.items(): | 169 for name, config in conf_dict.items(): |
170 url, handler = make_handler(name, config) | 170 url, handler = make_handler(name, config) |
171 registerUrlHandler(url, handler) | 171 registerUrlHandler(url, handler) |
OLD | NEW |