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

Unified Diff: abp/filters/rpy.py

Issue 30053555: Issue 7471 - Add an API for working with blocks of filters (Closed) Base URL: https://hg.adblockplus.org/python-abp
Patch Set: Adjust the API in response to review comments Created May 9, 2019, 4:22 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/data/expected_blocks.json » ('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
@@ -21,60 +21,16 @@
from __future__ import unicode_literals
from abp.filters import parse_line
__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.
-
- Parameters
- ----------
- data: namedtuple
- The parsed filter.
-
- Returns
- -------
- dict
- The resulting dictionary
-
- """
- result = dict(data._asdict())
- if 'options' in result:
- result['options'] = option_list_to_dict(result['options'])
-
- result['type'] = data.__class__.__name__
-
- return result
-
-
def strings2utf8(data):
"""Convert strings in a data structure to utf8 byte strings.
Parameters
----------
data: dict
The data to convert. Can include nested dicts, lists and tuples.
@@ -109,17 +65,17 @@
Returns
-------
dict
With the parsing results and all strings converted to utf8 byte
strings.
"""
- return strings2utf8(tuple2dict(parse_line(text, mode)))
+ return strings2utf8(parse_line(text, mode).to_dict())
def lines2dicts(string_list, mode='body'):
"""Convert a list of filterlist strings to a dictionary.
All strings in the output dictionary will be UTF8 byte strings. This is
necessary to prevent unicode encoding errors in rPython conversion layer.
« no previous file with comments | « abp/filters/parser.py ('k') | tests/data/expected_blocks.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld