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

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

Issue 29845767: Issue 6685 - Offer incremental filter list downloads (Closed) Base URL: https://hg.adblockplus.org/python-abp/
Left Patch Set: Use namedtuple filter list objects instead of strings Created Aug. 9, 2018, 7:26 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 | « no previous file | abp/filters/renderer.py » ('j') | abp/filters/renderer.py » ('J')
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 133
134 134
135 Header = _line_type('Header', 'version', '[{.version}]') 135 Header = _line_type('Header', 'version', '[{.version}]')
136 EmptyLine = _line_type('EmptyLine', '', '') 136 EmptyLine = _line_type('EmptyLine', '', '')
137 Comment = _line_type('Comment', 'text', '! {.text}') 137 Comment = _line_type('Comment', 'text', '! {.text}')
138 Metadata = _line_type('Metadata', 'key value', '! {0.key}: {0.value}') 138 Metadata = _line_type('Metadata', 'key value', '! {0.key}: {0.value}')
139 Filter = _line_type('Filter', 'text selector action options', '{.text}') 139 Filter = _line_type('Filter', 'text selector action options', '{.text}')
140 Include = _line_type('Include', 'target', '%include {0.target}%') 140 Include = _line_type('Include', 'target', '%include {0.target}%')
141 141
142 142
143 METADATA_REGEXP = re.compile(r'!\s*([\w-]+)\s*:\s*(.*)') 143 METADATA_REGEXP = re.compile(r'!\s*([\w-]+)\s*:(?!//)\s*(.*)')
144 METADATA_KEYS = {'Homepage', 'Title', 'Expires', 'Checksum', 'Redirect',
145 'Version', 'Diff-URL', 'Diff-Expires'}
146 INCLUDE_REGEXP = re.compile(r'%include\s+(.+)%') 144 INCLUDE_REGEXP = re.compile(r'%include\s+(.+)%')
147 HEADER_REGEXP = re.compile(r'\[(Adblock(?:\s*Plus\s*[\d\.]+?)?)\]', flags=re.I) 145 HEADER_REGEXP = re.compile(r'\[(Adblock(?:\s*Plus\s*[\d\.]+?)?)\]', flags=re.I)
148 HIDING_FILTER_REGEXP = re.compile(r'^([^/*|@"!]*?)#([@?])?#(.+)$') 146 HIDING_FILTER_REGEXP = re.compile(r'^([^/*|@"!]*?)#([@?])?#(.+)$')
149 FILTER_OPTIONS_REGEXP = re.compile( 147 FILTER_OPTIONS_REGEXP = re.compile(
150 r'\$(~?[\w-]+(?:=[^,]+)?(?:,~?[\w-]+(?:=[^,]+)?)*)$' 148 r'\$(~?[\w-]+(?:=[^,]+)?(?:,~?[\w-]+(?:=[^,]+)?)*)$'
151 ) 149 )
152 150
153 151
154 def _parse_comment(text): 152 def _parse_comment(text):
155 match = METADATA_REGEXP.match(text) 153 match = METADATA_REGEXP.match(text)
156 if match and match.group(1) in METADATA_KEYS: 154 if match:
157 return Metadata(match.group(1), match.group(2)) 155 return Metadata(match.group(1), match.group(2))
158 return Comment(text[1:].strip()) 156 return Comment(text[1:].strip())
159 157
160 158
161 def _parse_header(text): 159 def _parse_header(text):
162 match = HEADER_REGEXP.match(text) 160 match = HEADER_REGEXP.match(text)
163 if not match: 161 if not match:
164 raise ParseError('Malformed header', text) 162 raise ParseError('Malformed header', text)
165 return Header(match.group(1)) 163 return Header(match.group(1))
166 164
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 Raises 312 Raises
315 ------ 313 ------
316 ParseError 314 ParseError
317 Thrown during iteration for invalid filter list lines. 315 Thrown during iteration for invalid filter list lines.
318 TypeError 316 TypeError
319 If `lines` is not iterable. 317 If `lines` is not iterable.
320 318
321 """ 319 """
322 for line in lines: 320 for line in lines:
323 yield parse_line(line) 321 yield parse_line(line)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld