OLD | NEW |
| (Empty) |
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 | |
23 def get_subscriptions(_): | |
24 try: | |
25 from sitescripts.subscriptions import subscriptionParser | |
26 except ImportError: | |
27 logging.warning("Unable to import sitescripts, proceeding with empty " | |
28 "subscriptions list.") | |
29 return [] | |
30 | |
31 result = {} | |
32 utf8_reader = codecs.getreader('utf8') | |
33 source = urllib.urlopen("https://hg.adblockplus.org/subscriptionlist/archive/d
efault.tar.gz") | |
34 orig_get_settings = subscriptionParser.get_settings | |
35 try: | |
36 # Hack: monkey-patch subscriptionParser.get_settings() | |
37 settings = SafeConfigParser() | |
38 settings_handle = urllib.urlopen("https://hg.adblockplus.org/subscriptionlis
t/rawfile/default/settings") | |
39 try: | |
40 settings.readfp(utf8_reader(settings_handle)) | |
41 finally: | |
42 settings_handle.close() | |
43 subscriptionParser.get_settings = lambda: settings | |
44 | |
45 with tarfile.open(fileobj=source, mode="r|gz") as archive: | |
46 for fileinfo in archive: | |
47 if os.path.splitext(fileinfo.name)[1] != ".subscription": | |
48 continue | |
49 | |
50 filedata = subscriptionParser.parse_file(fileinfo.name, utf8_reader(arch
ive.extractfile(fileinfo))) | |
51 if filedata.unavailable: | |
52 continue | |
53 | |
54 result[filedata.name] = filedata | |
55 finally: | |
56 source.close() | |
57 subscriptionParser.get_settings = orig_get_settings | |
58 | |
59 subscriptionParser.calculate_supplemented(result) | |
60 return result.values() | |
OLD | NEW |