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 22 matching lines...) Expand all Loading... |
33 return showError('Unsupported request method', start_response) | 33 return showError('Unsupported request method', start_response) |
34 | 34 |
35 params = parse_qs(environ.get('QUERY_STRING', '')) | 35 params = parse_qs(environ.get('QUERY_STRING', '')) |
36 | 36 |
37 requestVersion = params.get('version', ['0'])[0] | 37 requestVersion = params.get('version', ['0'])[0] |
38 if requestVersion != '1': | 38 if requestVersion != '1': |
39 return showError('Unsupported request version', start_response) | 39 return showError('Unsupported request version', start_response) |
40 | 40 |
41 try: | 41 try: |
42 request_body_size = int(environ.get('CONTENT_LENGTH', 0)) | 42 request_body_size = int(environ.get('CONTENT_LENGTH', 0)) |
43 except (ValueError): | 43 except ValueError: |
44 return showError('No content', start_response) | 44 return showError('No content', start_response) |
45 | 45 |
46 dir = get_config().get('crashes', 'dataPath') | 46 dir = get_config().get('crashes', 'dataPath') |
47 if not os.path.exists(dir): | 47 if not os.path.exists(dir): |
48 os.makedirs(dir) | 48 os.makedirs(dir) |
49 | 49 |
50 filename = None | 50 filename = None |
51 try: | 51 try: |
52 fd, filename = mkstemp('.xml.tmp', 'crash_', dir) | 52 fd, filename = mkstemp('.xml.tmp', 'crash_', dir) |
53 file = os.fdopen(fd, 'wb') | 53 file = os.fdopen(fd, 'wb') |
54 file.write(environ['wsgi.input'].read(request_body_size)) | 54 file.write(environ['wsgi.input'].read(request_body_size)) |
55 file.close() | 55 file.close() |
56 os.rename(filename, os.path.splitext(filename)[0]) | 56 os.rename(filename, os.path.splitext(filename)[0]) |
57 except Exception as e: | 57 except Exception as e: |
58 if filename != None and os.path.isfile(filename): | 58 if filename != None and os.path.isfile(filename): |
59 os.remove(filename) | 59 os.remove(filename) |
60 raise e | 60 raise e |
61 | 61 |
62 start_response('200 Ok', [('Content-Type', 'text/plain; charset=utf-8')]) | 62 start_response('200 Ok', [('Content-Type', 'text/plain; charset=utf-8')]) |
63 return ['saved'.encode('utf-8')] | 63 return ['saved'.encode('utf-8')] |
64 | 64 |
65 | 65 |
66 def showError(message, start_response): | 66 def showError(message, start_response): |
67 start_response('400 Processing Error', [('Content-Type', 'text/plain; charse
t=utf-8')]) | 67 start_response('400 Processing Error', [('Content-Type', 'text/plain; charse
t=utf-8')]) |
68 return [message.encode('utf-8')] | 68 return [message.encode('utf-8')] |
OLD | NEW |