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-2016 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 # |
(...skipping 24 matching lines...) Expand all Loading... | |
39 if not re.match(r'^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$', guid): | 39 if not re.match(r'^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$', guid): |
40 return showError('Invalid or missing GUID', start_response) | 40 return showError('Invalid or missing GUID', start_response) |
41 | 41 |
42 path = os.path.join(get_config().get('reports', 'dataPath'), guid + '.xml') | 42 path = os.path.join(get_config().get('reports', 'dataPath'), guid + '.xml') |
43 if os.path.exists(path) or os.path.exists(path + '.tmp'): | 43 if os.path.exists(path) or os.path.exists(path + '.tmp'): |
44 return showError('Duplicate GUID', start_response) | 44 return showError('Duplicate GUID', start_response) |
45 | 45 |
46 try: | 46 try: |
47 request_size= int(environ['CONTENT_LENGTH']) | 47 request_size= int(environ['CONTENT_LENGTH']) |
48 except (KeyError, ValueError): | 48 except (KeyError, ValueError): |
49 return showError('Invalid or missing Content-Length header', start_response) | 49 return showError('Invalid or missing Content-Length header', start_response, |
Sebastian Noack
2015/04/14 06:30:59
Status code should be 411, not 400 here.
Wladimir Palant
2016/02/10 15:43:42
Done.
| |
50 '411 Length Required') | |
50 | 51 |
51 dir = os.path.dirname(path) | 52 dir = os.path.dirname(path) |
52 if not os.path.exists(dir): | 53 if not os.path.exists(dir): |
53 os.makedirs(dir) | 54 os.makedirs(dir) |
54 try: | 55 try: |
55 file = open(path + '.tmp', 'wb') | 56 file = open(path + '.tmp', 'wb') |
56 data = environ['wsgi.input'].read(request_size) | 57 data = environ['wsgi.input'].read(request_size) |
57 file.write(data) | 58 file.write(data) |
58 file.close() | 59 file.close() |
59 | 60 |
60 knownIssues = knownIssuesParser.findMatches(data.splitlines(), params.get('l ang', ['en-US'])[0]) | 61 knownIssues = knownIssuesParser.findMatches(data.splitlines(), params.get('l ang', ['en-US'])[0]) |
61 | 62 |
62 os.rename(path + '.tmp', path); | 63 os.rename(path + '.tmp', path); |
63 except Exception, e: | 64 except Exception, e: |
64 if os.path.isfile(path + '.tmp'): | 65 if os.path.isfile(path + '.tmp'): |
65 os.remove(path + '.tmp') | 66 os.remove(path + '.tmp') |
66 raise e | 67 raise e |
67 | 68 |
68 template = get_template(get_config().get('reports', 'submitResponseTemplate')) | 69 template = get_template(get_config().get('reports', 'submitResponseTemplate')) |
69 start_response('200 OK', [('Content-Type', 'application/xhtml+xml; charset=utf -8')]) | 70 start_response('200 OK', [('Content-Type', 'application/xhtml+xml; charset=utf -8')]) |
70 return [template.render({'url': get_config().get('reports', 'urlRoot') + guid, 'knownIssues': knownIssues}).encode('utf-8')] | 71 return [template.render({'url': get_config().get('reports', 'urlRoot') + guid, 'knownIssues': knownIssues}).encode('utf-8')] |
71 | 72 |
72 def showError(message, start_response): | 73 def showError(message, start_response, response_code='400 Processing Error'): |
73 template = get_template(get_config().get('reports', 'errorTemplate')) | 74 template = get_template(get_config().get('reports', 'errorTemplate')) |
74 start_response('400 Processing Error', [('Content-Type', 'application/xhtml+xm l; charset=utf-8')]) | 75 start_response(response_code, [('Content-Type', 'application/xhtml+xml; charse t=utf-8')]) |
75 return [template.render({'message': message}).encode('utf-8')] | 76 return [template.render({'message': message}).encode('utf-8')] |
LEFT | RIGHT |