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-present eyeo GmbH | 2 # Copyright (C) 2006-present 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 |
11 # GNU General Public License for more details. | 11 # GNU General Public License for more details. |
12 # | 12 # |
13 # You should have received a copy of the GNU General Public License | 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/>. | 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 |
16 from time import time | 16 from time import time |
17 from urlparse import urlparse, parse_qs | 17 from urlparse import urlparse, parse_qs |
18 import sys | 18 import sys |
19 import os | 19 import os |
20 import re | 20 import re |
21 from sitescripts.utils import get_config, cached, setupStderr | 21 from sitescripts.utils import get_config, cached, setupStderr |
22 from sitescripts.web import url_handler | 22 from sitescripts.web import url_handler |
23 import sitescripts.subscriptions.subscriptionParser as subscriptionParser | 23 import sitescripts.subscriptions.subscriptionParser as subscriptionParser |
24 | 24 |
25 | 25 |
26 @url_handler('/getSubscription') | 26 @url_handler('/getSubscription') |
27 def handleSubscriptionFallbackRequest(environ, start_response): | 27 def handleSubscriptionFallbackRequest(environ, start_response): |
28 setupStderr(environ['wsgi.errors']) | 28 setupStderr(environ['wsgi.errors']) |
29 | 29 |
30 (redirects, gone) = getData() | 30 redirects, gone = getData() |
31 | 31 |
32 start_response('200 OK', [('Content-Type', 'text/plain')]) | 32 start_response('200 OK', [('Content-Type', 'text/plain')]) |
33 | 33 |
34 url = None | 34 url = None |
35 params = parse_qs(environ.get('QUERY_STRING', '')) | 35 params = parse_qs(environ.get('QUERY_STRING', '')) |
36 if 'url' in params: | 36 if 'url' in params: |
37 url = params['url'][0] | 37 url = params['url'][0] |
38 | 38 |
39 if url and url in gone: | 39 if url and url in gone: |
40 return ['410'] | 40 return ['410'] |
41 elif url and url in redirects: | 41 elif url and url in redirects: |
42 return ['301 %s' % redirects[url]] | 42 return ['301 %s' % redirects[url]] |
43 | 43 |
44 return [] | 44 return [] |
45 | 45 |
46 | 46 |
47 @cached(600) | 47 @cached(600) |
48 def getData(): | 48 def getData(): |
49 processed = set() | 49 processed = set() |
50 | 50 |
51 (redirectData, goneData) = subscriptionParser.getFallbackData() | 51 redirectData, goneData = subscriptionParser.getFallbackData() |
52 redirects = processData(redirectData, processed, {}) | 52 redirects = processData(redirectData, processed, {}) |
53 gone = processData(goneData, processed, set()) | 53 gone = processData(goneData, processed, set()) |
54 | 54 |
55 return (redirects, gone) | 55 return (redirects, gone) |
56 | 56 |
57 | 57 |
58 def processData(data, processed, var): | 58 def processData(data, processed, var): |
59 data = data.replace('\r', '') | 59 data = data.replace('\r', '') |
60 data = data.split('\n') | 60 data = data.split('\n') |
61 | 61 |
(...skipping 21 matching lines...) Expand all Loading... |
83 print >>sys.stderr, 'Gone entry with a target: %s' % line | 83 print >>sys.stderr, 'Gone entry with a target: %s' % line |
84 if line in processed: | 84 if line in processed: |
85 print >>sys.stderr, 'Multiple instructions for URL %s' % line | 85 print >>sys.stderr, 'Multiple instructions for URL %s' % line |
86 | 86 |
87 if isinstance(var, set): | 87 if isinstance(var, set): |
88 var.add(line) | 88 var.add(line) |
89 else: | 89 else: |
90 var[line] = currentTarget | 90 var[line] = currentTarget |
91 | 91 |
92 return var | 92 return var |
OLD | NEW |