Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-2016 Eyeo GmbH | 2 # Copyright (C) 2006-2016 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 23 matching lines...) Expand all Loading... | |
34 !''' | 34 !''' |
35 | 35 |
36 MALWAREDOMAINS_PATH = '/files/justdomains.zip' | 36 MALWAREDOMAINS_PATH = '/files/justdomains.zip' |
37 | 37 |
38 | 38 |
39 def try_mirror(mirror): | 39 def try_mirror(mirror): |
40 url = mirror + MALWAREDOMAINS_PATH | 40 url = mirror + MALWAREDOMAINS_PATH |
41 try: | 41 try: |
42 with contextlib.closing(urllib2.urlopen(url)) as response: | 42 with contextlib.closing(urllib2.urlopen(url)) as response: |
43 return None, response.read() | 43 return None, response.read() |
44 except urllib2.HTTPError as exc: | |
45 exc.close() | |
44 except urllib2.URLError as exc: | 46 except urllib2.URLError as exc: |
45 error_message = 'Failed to fetch {}: {}'.format(url, exc) | 47 pass |
46 if hasattr(exc, 'close'): | 48 return 'Failed to fetch {}: {}'.format(url, exc), None |
Vasily Kuznetsov
2017/01/19 16:34:08
I tried to do it with two separate except clauses
Sebastian Noack
2017/01/19 17:13:33
I don't see how that creates any duplication.
t
Vasily Kuznetsov
2017/01/20 13:44:49
Yeah, this is better. Thanks.
| |
47 exc.close() | |
48 return error_message, None | |
49 | 49 |
50 | 50 |
51 def main(): | 51 def main(): |
52 config = get_config() | 52 config = get_config() |
53 section = 'subscriptionDownloads' | 53 section = 'subscriptionDownloads' |
54 repository = config.get(section, 'malwaredomains_repository') | 54 repository = config.get(section, 'malwaredomains_repository') |
55 mirrors = config.get(section, 'malwaredomains_mirrors').split() | 55 mirrors = config.get(section, 'malwaredomains_mirrors').split() |
56 | 56 |
57 tempdir = tempfile.mkdtemp(prefix='malwaredomains') | 57 tempdir = tempfile.mkdtemp(prefix='malwaredomains') |
58 try: | 58 try: |
(...skipping 26 matching lines...) Expand all Loading... | |
85 | 85 |
86 if subprocess.check_output(['hg', 'stat', '-R', tempdir]) != '': | 86 if subprocess.check_output(['hg', 'stat', '-R', tempdir]) != '': |
87 subprocess.check_call(['hg', '-q', 'commit', '-R', tempdir, '-A', '- u', 'hgbot', '-m', 'Updated malwaredomains.com data']) | 87 subprocess.check_call(['hg', '-q', 'commit', '-R', tempdir, '-A', '- u', 'hgbot', '-m', 'Updated malwaredomains.com data']) |
88 subprocess.check_call(['hg', '-q', 'push', '-R', tempdir]) | 88 subprocess.check_call(['hg', '-q', 'push', '-R', tempdir]) |
89 finally: | 89 finally: |
90 shutil.rmtree(tempdir, ignore_errors=True) | 90 shutil.rmtree(tempdir, ignore_errors=True) |
91 | 91 |
92 | 92 |
93 if __name__ == '__main__': | 93 if __name__ == '__main__': |
94 main() | 94 main() |
LEFT | RIGHT |