| OLD | NEW |
| 1 # coding: utf-8 | 1 # coding: utf-8 |
| 2 | 2 |
| 3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, |
| 4 # Copyright (C) 2006-2015 Eyeo GmbH | 4 # Copyright (C) 2006-2015 Eyeo GmbH |
| 5 # | 5 # |
| 6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify |
| 7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as |
| 8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
| 9 # | 9 # |
| 10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 group["variant"] = i + 1 | 52 group["variant"] = i + 1 |
| 53 break | 53 break |
| 54 return groups | 54 return groups |
| 55 | 55 |
| 56 def _get_active_variant(notifications, groups): | 56 def _get_active_variant(notifications, groups): |
| 57 for group in groups: | 57 for group in groups: |
| 58 group_id = group["id"] | 58 group_id = group["id"] |
| 59 variant = group["variant"] | 59 variant = group["variant"] |
| 60 if variant == 0: | 60 if variant == 0: |
| 61 continue | 61 continue |
| 62 notification = next(x for x in notifications if x["id"] == group_id) | 62 notification = next((x for x in notifications if x["id"] == group_id), None) |
| 63 if not notification: |
| 64 continue |
| 63 notification = copy.deepcopy(notification) | 65 notification = copy.deepcopy(notification) |
| 64 notification.update(notification["variants"][variant - 1]) | 66 notification.update(notification["variants"][variant - 1]) |
| 65 for key_to_remove in ("sample", "variants"): | 67 for key_to_remove in ("sample", "variants"): |
| 66 notification.pop(key_to_remove, None) | 68 notification.pop(key_to_remove, None) |
| 67 return notification | 69 return notification |
| 68 | 70 |
| 69 def _can_be_shown(notification): | 71 def _can_be_shown(notification): |
| 70 return notification.get("title", None) and notification.get("message", None) | 72 return notification.get("title", None) and notification.get("message", None) |
| 71 | 73 |
| 72 def _generate_version(groups): | 74 def _generate_version(groups): |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 if not groups: | 108 if not groups: |
| 107 groups = _assign_groups(notifications) | 109 groups = _assign_groups(notifications) |
| 108 response = _create_response(notifications, groups) | 110 response = _create_response(notifications, groups) |
| 109 response_headers = [("Content-Type", "application/json; charset=utf-8"), | 111 response_headers = [("Content-Type", "application/json; charset=utf-8"), |
| 110 ("ABP-Notification-Version", response["version"])] | 112 ("ABP-Notification-Version", response["version"])] |
| 111 response_body = json.dumps(response, ensure_ascii=False, indent=2, | 113 response_body = json.dumps(response, ensure_ascii=False, indent=2, |
| 112 separators=(",", ": "), | 114 separators=(",", ": "), |
| 113 sort_keys=True).encode("utf-8") | 115 sort_keys=True).encode("utf-8") |
| 114 start_response("200 OK", response_headers) | 116 start_response("200 OK", response_headers) |
| 115 return response_body | 117 return response_body |
| OLD | NEW |