Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 # This file is part of the Adblock Plus website, | |
2 # Copyright (C) 2006-2016 Eyeo GmbH | |
3 # | |
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 | |
6 # published by the Free Software Foundation. | |
7 # | |
8 # Adblock Plus is distributed in the hope that it will be useful, | |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 # GNU General Public License for more details. | |
12 # | |
13 # You should have received a copy of the GNU General Public License | |
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
15 | |
16 import codecs | |
17 import os | |
18 import tarfile | |
19 import urllib | |
20 import logging | |
21 from ConfigParser import SafeConfigParser | |
22 subscriptions = None | |
23 | |
24 def get_subscriptions(_): | |
Wladimir Palant
2016/03/09 11:12:27
This shouldn't be a filter but rather a global fun
Sebastian Noack
2016/03/09 11:18:17
I agree that this should rather be a global. Howev
Wladimir Palant
2016/03/09 11:25:51
That's fine IMHO, with something like this functio
Sebastian Noack
2016/03/09 11:54:18
Whether you think it's safe or not, jinja's optimi
Wladimir Palant
2016/03/09 13:50:15
This makes sense because for filters same input sh
| |
25 global subscriptions | |
26 if not subscriptions is None: | |
27 return subscriptions | |
28 try: | |
29 from sitescripts.subscriptions import subscriptionParser | |
30 except ImportError: | |
31 logging.warning("Unable to import sitescripts, proceeding with empty " | |
32 "subscriptions list.") | |
33 return [] | |
34 | |
35 result = {} | |
36 utf8_reader = codecs.getreader('utf8') | |
37 source = urllib.urlopen("https://hg.adblockplus.org/subscriptionlist/archive/d efault.tar.gz") | |
38 orig_get_settings = subscriptionParser.get_settings | |
39 try: | |
40 # Hack: monkey-patch subscriptionParser.get_settings() | |
41 settings = SafeConfigParser() | |
42 settings_handle = urllib.urlopen("https://hg.adblockplus.org/subscriptionlis t/rawfile/default/settings") | |
43 try: | |
44 settings.readfp(utf8_reader(settings_handle)) | |
45 finally: | |
46 settings_handle.close() | |
47 subscriptionParser.get_settings = lambda: settings | |
48 | |
49 with tarfile.open(fileobj=source, mode="r|gz") as archive: | |
50 for fileinfo in archive: | |
51 if os.path.splitext(fileinfo.name)[1] != ".subscription": | |
52 continue | |
53 | |
54 filedata = subscriptionParser.parse_file(fileinfo.name, utf8_reader(arch ive.extractfile(fileinfo))) | |
55 if filedata.unavailable: | |
56 continue | |
57 | |
58 result[filedata.name] = filedata | |
59 finally: | |
60 source.close() | |
61 subscriptionParser.get_settings = orig_get_settings | |
62 | |
63 subscriptionParser.calculate_supplemented(result) | |
64 subscriptions = result.values() | |
65 return subscriptions | |
LEFT | RIGHT |