Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: abp/filters/renderer.py

Issue 29845767: Issue 6685 - Offer incremental filter list downloads (Closed) Base URL: https://hg.adblockplus.org/python-abp/
Left Patch Set: Store metadata in a dict Created Aug. 29, 2018, 10:51 p.m.
Right Patch Set: Address comments on PS8 Created Aug. 30, 2018, 5:37 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « abp/filters/parser.py ('k') | tests/test_differ.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of Adblock Plus <https://adblockplus.org/>, 1 # This file is part of Adblock Plus <https://adblockplus.org/>,
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 _logger.info('Rendering: %s', name) 177 _logger.info('Rendering: %s', name)
178 lines, default_source = _get_and_parse_fragment(name, sources, top_source) 178 lines, default_source = _get_and_parse_fragment(name, sources, top_source)
179 lines = _process_includes(sources, default_source, [name], lines) 179 lines = _process_includes(sources, default_source, [name], lines)
180 for proc in [_process_timestamps, _insert_version, _remove_duplicates, 180 for proc in [_process_timestamps, _insert_version, _remove_duplicates,
181 _validate]: 181 _validate]:
182 lines = proc(lines) 182 lines = proc(lines)
183 return lines 183 return lines
184 184
185 185
186 def _split_list_for_diff(list_in): 186 def _split_list_for_diff(list_in):
187 """Split a filter list into metadata, keys, and rules.""" 187 """Split a filter list into metadata, keys, and rules."""
Vasily Kuznetsov 2018/08/31 12:11:02 Nit: strictly speaking this function now returns m
rhowell 2018/08/31 21:21:02 Ah, good point! I'll update that.
188 metadata = {} 188 metadata = {}
189 rules = set() 189 rules = set()
190 for line in parse_filterlist(list_in): 190 for line in parse_filterlist(list_in):
191 if line.type == 'metadata': 191 if line.type == 'metadata':
192 metadata[line.key.lower()] = line 192 metadata[line.key.lower()] = line
193 elif line.type == 'filter': 193 elif line.type == 'filter':
194 rules.add(line.to_string()) 194 rules.add(line.to_string())
195 return metadata, rules 195 return metadata, rules
196 196
197 197
198 def render_diff(base, latest): 198 def render_diff(base, latest):
199 """Return a diff between two filter lists. 199 """Return a diff between two filter lists.
200 200
201 Parameters 201 Parameters
202 ---------- 202 ----------
203 base : iterator of str 203 base : iterator of str
204 The base (old) list that we want to update to latest. 204 The base (old) list that we want to update to latest.
205 lastest : iterator of str 205 lastest : iterator of str
206 The latest (most recent) list that we want to update to. 206 The latest (most recent) list that we want to update to.
207 207
208 Returns 208 Returns
209 ------- 209 -------
210 iterable of str 210 iterable of str
211 A diff between two lists (https://issues.adblockplus.org/ticket/6685) 211 A diff between two lists (https://issues.adblockplus.org/ticket/6685)
212 212
213 """ 213 """
214 latest_md, latest_rules = _split_list_for_diff(latest) 214 latest_metadata, latest_rules = _split_list_for_diff(latest)
215 base_md, base_rules = _split_list_for_diff(base) 215 base_metadata, base_rules = _split_list_for_diff(base)
Sebastian Noack 2018/08/29 23:46:26 Nit: Is it necessary to abbreviate metadata to md
rhowell 2018/08/30 16:23:30 Done.
216 add_fl = latest_rules - base_rules
Sebastian Noack 2018/08/29 23:46:25 Nit: These expressions could be inlined below. Thi
rhowell 2018/08/30 16:23:30 Done.
217 remove_fl = base_rules - latest_rules
218 216
219 yield '[Adblock Plus Diff]' 217 yield '[Adblock Plus Diff]'
220 for key, latest in latest_md.items(): 218 for key, latest in latest_metadata.items():
221 base = base_md.get(key) 219 base = base_metadata.get(key)
222 if not base or base.value != latest.value: 220 if not base or base.value != latest.value:
223 yield latest.to_string() 221 yield latest.to_string()
224 for key in set(base_md) - set(latest_md): 222 for key in set(base_metadata) - set(latest_metadata):
225 yield '! {}:'.format(base_md[key].key) 223 yield '! {}:'.format(base_metadata[key].key)
226 for item in remove_fl: 224 for rule in base_rules - latest_rules:
227 yield '- {}'.format(item) 225 yield '- {}'.format(rule)
228 for item in add_fl: 226 for rule in latest_rules - base_rules:
229 yield '+ {}'.format(item) 227 yield '+ {}'.format(rule)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld