OLD | NEW |
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 21 matching lines...) Expand all Loading... |
32 class Subscription(object): | 32 class Subscription(object): |
33 def define_property(propName, readonly=False): | 33 def define_property(propName, readonly=False): |
34 if readonly: | 34 if readonly: |
35 return property(lambda self: self._data[propName]) | 35 return property(lambda self: self._data[propName]) |
36 else: | 36 else: |
37 def set_property(self, value): | 37 def set_property(self, value): |
38 self._data[propName] = value | 38 self._data[propName] = value |
39 | 39 |
40 return property(lambda self: self._data[propName], set_property) | 40 return property(lambda self: self._data[propName], set_property) |
41 | 41 |
42 name = define_property("name") | 42 name = define_property('name') |
43 type = define_property("type") | 43 type = define_property('type') |
44 maintainer = define_property("maintainer") | 44 maintainer = define_property('maintainer') |
45 email = define_property("email") | 45 email = define_property('email') |
46 specialization = define_property("specialization") | 46 specialization = define_property('specialization') |
47 languages = define_property("languages") | 47 languages = define_property('languages') |
48 recommendation = define_property("recommendation", readonly=True) | 48 recommendation = define_property('recommendation', readonly=True) |
49 deprecated = define_property("deprecated", readonly=True) | 49 deprecated = define_property('deprecated', readonly=True) |
50 unavailable = define_property("unavailable", readonly=True) | 50 unavailable = define_property('unavailable', readonly=True) |
51 catchall = define_property("catchall", readonly=True) | 51 catchall = define_property('catchall', readonly=True) |
52 supplements = define_property("supplements", readonly=True) | 52 supplements = define_property('supplements', readonly=True) |
53 supplementsType = define_property("supplementsType", readonly=True) | 53 supplementsType = define_property('supplementsType', readonly=True) |
54 supplemented = define_property("supplemented", readonly=True) | 54 supplemented = define_property('supplemented', readonly=True) |
55 variants = define_property("variants", readonly=True) | 55 variants = define_property('variants', readonly=True) |
56 homepage = define_property("homepage") | 56 homepage = define_property('homepage') |
57 contact = define_property("contact") | 57 contact = define_property('contact') |
58 forum = define_property("forum") | 58 forum = define_property('forum') |
59 faq = define_property("faq") | 59 faq = define_property('faq') |
60 blog = define_property("blog") | 60 blog = define_property('blog') |
61 changelog = define_property("changelog") | 61 changelog = define_property('changelog') |
62 policy = define_property("policy") | 62 policy = define_property('policy') |
63 digest = define_property("digest") | 63 digest = define_property('digest') |
64 digestDay = define_property("digestDay") | 64 digestDay = define_property('digestDay') |
65 | 65 |
66 def __init__(self, path, data): | 66 def __init__(self, path, data): |
67 self._data = { | 67 self._data = { |
68 'name': None, | 68 'name': None, |
69 'type': 'ads', | 69 'type': 'ads', |
70 'maintainer': None, | 70 'maintainer': None, |
71 'email': None, | 71 'email': None, |
72 'specialization': None, | 72 'specialization': None, |
73 'languages': None, | 73 'languages': None, |
74 'deprecated': False, | 74 'deprecated': False, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 languagenames = [] | 177 languagenames = [] |
178 for language in value.split(','): | 178 for language in value.split(','): |
179 if settings.has_option('languages', language): | 179 if settings.has_option('languages', language): |
180 languagenames.append(settings.get('languages', language)
) | 180 languagenames.append(settings.get('languages', language)
) |
181 else: | 181 else: |
182 warn('Unknown language code %s in %s' % (language, path)
) | 182 warn('Unknown language code %s in %s' % (language, path)
) |
183 self._data['languageSpecialization'] = ', '.join(languagenames) | 183 self._data['languageSpecialization'] = ', '.join(languagenames) |
184 | 184 |
185 if 'languageSpecialization' in self._data: | 185 if 'languageSpecialization' in self._data: |
186 if self.specialization != None: | 186 if self.specialization != None: |
187 self.specialization += ", " + self._data['languageSpecialization
'] | 187 self.specialization += ', ' + self._data['languageSpecialization
'] |
188 else: | 188 else: |
189 self.specialization = self._data['languageSpecialization'] | 189 self.specialization = self._data['languageSpecialization'] |
190 del self._data['languageSpecialization'] | 190 del self._data['languageSpecialization'] |
191 | 191 |
192 for group in mandatory: | 192 for group in mandatory: |
193 found = False | 193 found = False |
194 for key in group: | 194 for key in group: |
195 if self._data[key] != None: | 195 if self._data[key] != None: |
196 found = True | 196 found = True |
197 if not found: | 197 if not found: |
198 str = ", ".join(group) | 198 str = ', '.join(group) |
199 warn('None of the attributes %s present in %s' % (str, path)) | 199 warn('None of the attributes %s present in %s' % (str, path)) |
200 | 200 |
201 if len(self.variants) == 0: | 201 if len(self.variants) == 0: |
202 warn('No list locations given in %s' % (path)) | 202 warn('No list locations given in %s' % (path)) |
203 if self.type not in ('ads', 'anti-adblock', 'other', 'malware', 'social'
, 'privacy'): | 203 if self.type not in ('ads', 'anti-adblock', 'other', 'malware', 'social'
, 'privacy'): |
204 warn('Unknown type given in %s' % (path)) | 204 warn('Unknown type given in %s' % (path)) |
205 if self.digest != 'daily' and self.digest != 'weekly': | 205 if self.digest != 'daily' and self.digest != 'weekly': |
206 warn('Unknown digest frequency given in %s' % (path)) | 206 warn('Unknown digest frequency given in %s' % (path)) |
207 if not self.digestDay[0:3].lower() in weekdays: | 207 if not self.digestDay[0:3].lower() in weekdays: |
208 warn('Unknown digest day given in %s' % (path)) | 208 warn('Unknown digest day given in %s' % (path)) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 def getFallbackData(): | 265 def getFallbackData(): |
266 repo = os.path.abspath(get_config().get('subscriptions', 'repository')) | 266 repo = os.path.abspath(get_config().get('subscriptions', 'repository')) |
267 redirectdata = subprocess.check_output(['hg', '-R', repo, 'cat', '-r', 'defa
ult', os.path.join(repo, 'redirects')]) | 267 redirectdata = subprocess.check_output(['hg', '-R', repo, 'cat', '-r', 'defa
ult', os.path.join(repo, 'redirects')]) |
268 gonedata = subprocess.check_output(['hg', '-R', repo, 'cat', '-r', 'default'
, os.path.join(repo, 'gone')]) | 268 gonedata = subprocess.check_output(['hg', '-R', repo, 'cat', '-r', 'default'
, os.path.join(repo, 'gone')]) |
269 return (redirectdata, gonedata) | 269 return (redirectdata, gonedata) |
270 | 270 |
271 | 271 |
272 def _validate_URL(url): | 272 def _validate_URL(url): |
273 parse_result = urlparse(url) | 273 parse_result = urlparse(url) |
274 return parse_result.scheme in ('http', 'https') and parse_result.netloc != '
' | 274 return parse_result.scheme in ('http', 'https') and parse_result.netloc != '
' |
OLD | NEW |