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

Side by Side Diff: abp/filters/parser.py

Issue 29677724: Noissue - make parse_line and parse_filterlist also support byte strings (Closed)
Patch Set: Created Jan. 23, 2018, 4:30 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/test_parser.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 Returns 269 Returns
270 ------- 270 -------
271 namedtuple 271 namedtuple
272 Parsed line (see `_line_type`). 272 Parsed line (see `_line_type`).
273 273
274 Raises 274 Raises
275 ------ 275 ------
276 ParseError 276 ParseError
277 ParseError: If the line can't be parsed. 277 ParseError: If the line can't be parsed.
278 """ 278 """
279 if isinstance(line_text, type(b'')):
280 line_text = line_text.decode('utf-8')
281
279 content = line_text.strip() 282 content = line_text.strip()
280 283
281 if content == '': 284 if content == '':
282 line = EmptyLine() 285 line = EmptyLine()
283 elif content.startswith('!'): 286 elif content.startswith('!'):
284 line = _parse_comment(content) 287 line = _parse_comment(content)
285 elif content.startswith('%') and content.endswith('%'): 288 elif content.startswith('%') and content.endswith('%'):
286 line = _parse_instruction(content) 289 line = _parse_instruction(content)
287 elif content.startswith('[') and content.endswith(']'): 290 elif content.startswith('[') and content.endswith(']'):
288 line = _parse_header(content) 291 line = _parse_header(content)
(...skipping 20 matching lines...) Expand all
309 Raises 312 Raises
310 ------ 313 ------
311 ParseError 314 ParseError
312 Thrown during iteration for invalid filter list lines. 315 Thrown during iteration for invalid filter list lines.
313 TypeError 316 TypeError
314 If `lines` is not iterable. 317 If `lines` is not iterable.
315 318
316 """ 319 """
317 for line in lines: 320 for line in lines:
318 yield parse_line(line) 321 yield parse_line(line)
OLDNEW
« no previous file with comments | « no previous file | tests/test_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld