| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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-2015 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, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 | 110 |
| 111 def wrapped(arg): | 111 def wrapped(arg): |
| 112 if arg in results: | 112 if arg in results: |
| 113 result = results[arg] | 113 result = results[arg] |
| 114 del results[arg] | 114 del results[arg] |
| 115 else: | 115 else: |
| 116 if results.entries_left > 0: | 116 if results.entries_left > 0: |
| 117 results.entries_left -= 1 | 117 results.entries_left -= 1 |
| 118 else: | 118 else: |
| 119 results.popitem(last=False) | 119 results.popitem(last=False) |
| 120 result = func(arg) | 120 try: |
| 121 result = func(arg) | |
| 122 except: | |
|
Sebastian Noack
2015/10/21 15:19:20
You probably should explicitly catch Exception. Ot
Wladimir Palant
2015/10/21 15:42:40
Why shouldn't it? The exception is re-raised, the
Sebastian Noack
2015/10/21 15:49:13
Acknowledged.
| |
| 123 results.entries_left += 1 | |
| 124 raise | |
| 121 results[arg] = result | 125 results[arg] = result |
| 122 return result | 126 return result |
| 123 return wrapped | 127 return wrapped |
| 124 | 128 |
| 125 | 129 |
| 126 def cache_last(func): | 130 def cache_last(func): |
| 127 """ | 131 """ |
| 128 Decorator that memoizes the last return value of a function in case it is | 132 Decorator that memoizes the last return value of a function in case it is |
| 129 called again with the same parameters. | 133 called again with the same parameters. |
| 130 """ | 134 """ |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 except: | 264 except: |
| 261 path = urlparts.path | 265 path = urlparts.path |
| 262 return path[1:], urlparts.query | 266 return path[1:], urlparts.query |
| 263 | 267 |
| 264 @cache_lru | 268 @cache_lru |
| 265 def parse_query(query): | 269 def parse_query(query): |
| 266 return urlparse.parse_qs(query) | 270 return urlparse.parse_qs(query) |
| 267 | 271 |
| 268 @cache_lru | 272 @cache_lru |
| 269 def parse_lastversion(last_version): | 273 def parse_lastversion(last_version): |
| 274 if '-' in last_version: | |
| 275 last_version = last_version.split('-', 1)[0] | |
|
Sebastian Noack
2015/10/21 15:19:20
Nit: last_version.split('-')[0] would do as will a
Wladimir Palant
2015/10/21 15:42:40
Sure, but the point is doing as little work as pos
Sebastian Noack
2015/10/21 15:49:13
More than one dash given is a rather theoretical s
Sebastian Noack
2015/10/21 16:10:34
I did some more benchmarking, and confirmed that t
Wladimir Palant
2015/10/21 16:16:03
No, it's a very real scenario if more than one not
Sebastian Noack
2015/10/21 16:19:51
Well, I'm not arguing. I just try to understand wh
| |
| 270 return datetime.strptime(last_version, "%Y%m%d%H%M") | 276 return datetime.strptime(last_version, "%Y%m%d%H%M") |
| 271 | 277 |
| 272 @cache_lru | 278 @cache_lru |
| 273 def get_week(date): | 279 def get_week(date): |
| 274 return date.isocalendar()[0:2] | 280 return date.isocalendar()[0:2] |
| 275 | 281 |
| 276 def parse_downloader_query(info): | 282 def parse_downloader_query(info): |
| 277 params = parse_query(info["query"]) | 283 params = parse_query(info["query"]) |
| 278 for param in ("addonName", "addonVersion", "application", "applicationVersion" , "platform", "platformVersion"): | 284 for param in ("addonName", "addonVersion", "application", "applicationVersion" , "platform", "platformVersion"): |
| 279 info[param] = params.get(param, ["unknown"])[0] | 285 info[param] = params.get(param, ["unknown"])[0] |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 parser.add_argument("mirror_name", nargs="?", help="Name of the mirror server that the file belongs to") | 570 parser.add_argument("mirror_name", nargs="?", help="Name of the mirror server that the file belongs to") |
| 565 parser.add_argument("server_type", nargs="?", help="Server type like download, update or subscription") | 571 parser.add_argument("server_type", nargs="?", help="Server type like download, update or subscription") |
| 566 parser.add_argument("log_file", nargs="?", help="Log file path, can be a local file path, http:// or ssh:// URL") | 572 parser.add_argument("log_file", nargs="?", help="Log file path, can be a local file path, http:// or ssh:// URL") |
| 567 args = parser.parse_args() | 573 args = parser.parse_args() |
| 568 | 574 |
| 569 if args.mirror_name and args.server_type and args.log_file: | 575 if args.mirror_name and args.server_type and args.log_file: |
| 570 sources = [(args.mirror_name, args.server_type, args.log_file)] | 576 sources = [(args.mirror_name, args.server_type, args.log_file)] |
| 571 else: | 577 else: |
| 572 sources = get_stats_files() | 578 sources = get_stats_files() |
| 573 parse_sources(sources, args.factor, args.verbose) | 579 parse_sources(sources, args.factor, args.verbose) |
| OLD | NEW |