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

Unified Diff: abp/filters/rpy.py

Issue 30031558: Issue 7391 - Let rpy recursively parse filter options to dicts (Closed) Base URL: https://hg.adblockplus.org/python-abp
Patch Set: Removed OrderedDict Created April 9, 2019, 12:46 a.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 | « no previous file | tests/test_rpy.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: abp/filters/rpy.py
===================================================================
--- a/abp/filters/rpy.py
+++ b/abp/filters/rpy.py
@@ -26,6 +26,27 @@
__all__ = ['line2dict']
+def option_list_to_dict(options):
+ """Recursively parse filter options into dicts.
+
+ Parameters
+ ----------
+ options: A list of tuples
+ The filter options
+
+ Returns
+ -------
+ dict
+ The resulting dictionary
+
+ """
+ result = dict(options)
+ if 'domain' in result:
+ result['domain'] = option_list_to_dict(result['domain'])
+
+ return result
+
+
def tuple2dict(data):
"""Convert a parsed filter from a namedtuple to a dict.
@@ -41,6 +62,9 @@
"""
result = dict(data._asdict())
+ if 'options' in result:
+ result['options'] = option_list_to_dict(result['options'])
+
result['type'] = data.__class__.__name__
return result
@@ -64,8 +88,6 @@
return {strings2utf8(k): strings2utf8(v) for k, v in data.items()}
if isinstance(data, list):
return [strings2utf8(v) for v in data]
- if isinstance(data, tuple):
- return tuple(strings2utf8(v) for v in data)
if isinstance(data, type('')):
# The condition is a Python 2/3 way of saying "unicode string".
return data.encode('utf-8')
« no previous file with comments | « no previous file | tests/test_rpy.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld