| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 | 244 |
| 245 | 245 |
| 246 def _urlopen(url, attempts=3): | 246 def _urlopen(url, attempts=3): |
| 247 """ | 247 """ |
| 248 Tries to open a particular URL, retries on failure. | 248 Tries to open a particular URL, retries on failure. |
| 249 """ | 249 """ |
| 250 for i in range(attempts): | 250 for i in range(attempts): |
| 251 try: | 251 try: |
| 252 return urllib.urlopen(url) | 252 return urllib.urlopen(url) |
| 253 except IOError as e: | 253 except IOError as e: |
| 254 error = e | 254 error = Exception('Error {0} while opening {1} url' |
|
Vasily Kuznetsov
2017/01/13 18:12:11
It would probably be good to improve the error rep
| |
| 255 .format(e, url)) | |
| 255 time.sleep(5) | 256 time.sleep(5) |
| 256 raise error | 257 raise error |
| 257 | 258 |
| 258 | 259 |
| 259 def _parseXMLDocument(url, attempts=2): | 260 def _parseXMLDocument(url, attempts=2): |
| 260 for i in range(attempts): | 261 for i in range(attempts): |
| 261 page = _urlopen(url) | 262 page = _urlopen(url) |
| 262 content = page.read() | 263 content = page.read() |
| 263 page.close() | 264 page.close() |
|
Sebastian Noack
2017/01/17 09:33:32
The close() should have gone into a finally block,
Sebastian Noack
2017/01/17 10:16:56
Yes, in Python 2, the repsonse object returned by
Sebastian Noack
2017/01/17 10:20:15
Well, alternatively you could use try-finally. But
Vasily Kuznetsov
2017/01/17 10:30:34
Yeah, with is nicer, especially having Python 3 in
| |
| 264 try: | 265 try: |
| 265 return dom.parseString(content) | 266 return dom.parseString(content) |
| 266 except ExpatError as err: | 267 except ExpatError as err: |
| 267 exception = Exception('Error {0} while parsing xml:\n{1}\nfrom {2}' | 268 exception = Exception('Error {0} while parsing xml:\n{1}\nfrom {2}' |
| 268 .format(err, content, url)) | 269 .format(err, content, url)) |
| 269 raise exception | 270 raise exception |
| 270 | 271 |
| 271 | 272 |
| 272 def _getMozillaDownloadLink(galleryID): | 273 def _getMozillaDownloadLink(galleryID): |
| 273 """ | 274 """ |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 if not extensions: | 394 if not extensions: |
| 394 return | 395 return |
| 395 | 396 |
| 396 updates = {} | 397 updates = {} |
| 397 for extension in extensions: | 398 for extension in extensions: |
| 398 updates[extension['basename']] = { | 399 updates[extension['basename']] = { |
| 399 'url': extension['updateURL'], | 400 'url': extension['updateURL'], |
| 400 'version': extension['version'] | 401 'version': extension['version'] |
| 401 } | 402 } |
| 402 writeLibabpUpdateManifest(path, updates) | 403 writeLibabpUpdateManifest(path, updates) |
| LEFT | RIGHT |