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

Unified Diff: abp/filters/renderer.py

Issue 29845767: Issue 6685 - Offer incremental filter list downloads (Closed) Base URL: https://hg.adblockplus.org/python-abp/
Patch Set: Use namedtuple filter list objects instead of strings Created Aug. 9, 2018, 7:26 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « abp/filters/parser.py ('k') | tests/test_differ.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: abp/filters/renderer.py
===================================================================
--- a/abp/filters/renderer.py
+++ b/abp/filters/renderer.py
@@ -199,3 +199,41 @@
_insert_checksum, _validate]:
lines = proc(lines)
return lines
+
+
+def render_diff(base, latest):
Vasily Kuznetsov 2018/08/17 10:30:54 I think it makes more sense to make `base`, `lates
rhowell 2018/08/20 18:21:27 Done.
+ """Return a diff between two filter lists."""
+ # Collect the special comments
+ diff = ['[Adblock Plus Diff]\n']
+ latest_fl, latest_md, latest_keys = (set() for i in range(3))
+ base_fl, base_md, base_keys = (set() for i in range(3))
+
+ for line in parse_filterlist(latest.splitlines()):
+ if line.type == 'metadata' and 'Checksum' not in line.to_string():
Vasily Kuznetsov 2018/08/17 10:30:53 Note: If this lands after the checksum patch, the
rhowell 2018/08/20 18:21:27 Are we guaranteed that no filter lists will be enc
Vasily Kuznetsov 2018/08/21 14:59:59 Hm. No, for now we're not guaranteed that there's
Sebastian Noack 2018/08/21 19:42:45 Isn't python-abp stripping checksums when generati
Sebastian Noack 2018/08/22 16:03:29 Moving the discussion from IRC over here: 16:34:4
+ latest_md.add(line.to_string())
+ latest_keys.add(line.key)
+ elif line.type == 'filter':
+ latest_fl.add(line.to_string())
+
+ # Get the diff between the rest of the lines
+ for line in parse_filterlist(base.splitlines()):
Vasily Kuznetsov 2018/08/17 10:30:53 It would be good to move this repeated piece of co
rhowell 2018/08/20 18:21:27 Done.
+ if line.type == 'metadata' and 'Checksum' not in line.to_string():
+ base_md.add(line.to_string())
+ base_keys.add(line.key)
+ elif line.type == 'filter':
+ base_fl.add(line.to_string())
+ new_md = latest_md - base_md
+ removed_keys = base_keys - latest_keys
+ add_fl = latest_fl - base_fl
+ remove_fl = base_fl - latest_fl
+ for item in new_md:
+ diff.append('{}\n'.format(item))
Vasily Kuznetsov 2018/08/17 10:30:53 If we return an iterable of strings from this func
rhowell 2018/08/20 18:21:27 Done.
+ for key in removed_keys:
+ # If a special comment has been removed, enter it with a blank value
+ # so the client will set it back to the default value
+ diff.append('! {}:\n'.format(key))
+ for item in add_fl:
+ diff.append('+ {}\n'.format(item))
+ for item in remove_fl:
+ diff.append('- {}\n'.format(item))
+ return ''.join(diff)
« no previous file with comments | « abp/filters/parser.py ('k') | tests/test_differ.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld