Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 group = {'id': notification['id'], 'variant': 0} | 45 group = {'id': notification['id'], 'variant': 0} |
46 groups.append(group) | 46 groups.append(group) |
47 for i, variant in enumerate(notification['variants']): | 47 for i, variant in enumerate(notification['variants']): |
48 sample_size = variant['sample'] | 48 sample_size = variant['sample'] |
49 end = start + sample_size | 49 end = start + sample_size |
50 selected = sample_size > 0 and start <= selection <= end | 50 selected = sample_size > 0 and start <= selection <= end |
51 start = end | 51 start = end |
52 if selected: | 52 if selected: |
53 group['variant'] = i + 1 | 53 group['variant'] = i + 1 |
54 break | 54 break |
55 return groups | |
Felix Dahlke
2017/10/10 14:10:01
Nit: The way this function works now, returning gr
Vasily Kuznetsov
2017/10/10 14:17:18
I agree. Also, if we make it return None, the fact
wspee
2017/10/10 14:46:49
Done.
| |
56 | 55 |
57 | 56 |
58 def _get_active_variant(notifications, groups): | 57 def _get_active_variant(notifications, groups): |
59 for group in groups: | 58 for group in groups: |
60 group_id = group['id'] | 59 group_id = group['id'] |
61 variant = group['variant'] | 60 variant = group['variant'] |
62 if variant == 0: | 61 if variant == 0: |
63 continue | 62 continue |
64 notification = next((x for x in notifications if x['id'] == group_id), N one) | 63 notification = next((x for x in notifications if x['id'] == group_id), N one) |
65 if not notification: | 64 if not notification: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 } | 104 } |
106 | 105 |
107 | 106 |
108 @url_handler('/notification.json') | 107 @url_handler('/notification.json') |
109 def notification(environ, start_response): | 108 def notification(environ, start_response): |
110 params = urlparse.parse_qs(environ.get('QUERY_STRING', '')) | 109 params = urlparse.parse_qs(environ.get('QUERY_STRING', '')) |
111 version = params.get('lastVersion', [''])[0] | 110 version = params.get('lastVersion', [''])[0] |
112 notifications = load_notifications() | 111 notifications = load_notifications() |
113 groups = _determine_groups(version, notifications) | 112 groups = _determine_groups(version, notifications) |
114 notifications = [x for x in notifications if not x.get('inactive', False)] | 113 notifications = [x for x in notifications if not x.get('inactive', False)] |
115 groups = _assign_groups(groups, notifications) | 114 _assign_groups(groups, notifications) |
116 response = _create_response(notifications, groups) | 115 response = _create_response(notifications, groups) |
117 response_headers = [('Content-Type', 'application/json; charset=utf-8'), | 116 response_headers = [('Content-Type', 'application/json; charset=utf-8'), |
118 ('ABP-Notification-Version', response['version'])] | 117 ('ABP-Notification-Version', response['version'])] |
119 response_body = json.dumps(response, ensure_ascii=False, indent=2, | 118 response_body = json.dumps(response, ensure_ascii=False, indent=2, |
120 separators=(',', ': '), | 119 separators=(',', ': '), |
121 sort_keys=True).encode('utf-8') | 120 sort_keys=True).encode('utf-8') |
122 start_response('200 OK', response_headers) | 121 start_response('200 OK', response_headers) |
123 return response_body | 122 return response_body |
LEFT | RIGHT |