OLD | NEW |
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-2016 Eyeo GmbH | 2 # Copyright (C) 2006-2016 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 | 52 |
53 Header = line_type('Header', 'version', '[{.version}]') | 53 Header = line_type('Header', 'version', '[{.version}]') |
54 EmptyLine = line_type('EmptyLine', '', '') | 54 EmptyLine = line_type('EmptyLine', '', '') |
55 Comment = line_type('Comment', 'text', '! {.text}') | 55 Comment = line_type('Comment', 'text', '! {.text}') |
56 Metadata = line_type('Metadata', 'key value', '! {0.key}: {0.value}') | 56 Metadata = line_type('Metadata', 'key value', '! {0.key}: {0.value}') |
57 Filter = line_type('Filter', 'expression', '{.expression}') | 57 Filter = line_type('Filter', 'expression', '{.expression}') |
58 Include = line_type('Include', 'target', '%include {0.target}%') | 58 Include = line_type('Include', 'target', '%include {0.target}%') |
59 | 59 |
60 | 60 |
61 METADATA_REGEXP = re.compile('!\s*(\w+)\s*:\s*(.*)') | 61 METADATA_REGEXP = re.compile(r'!\s*(\w+)\s*:\s*(.*)') |
62 METADATA_KEYS = {'Homepage', 'Title', 'Expires', 'Checksum', 'Redirect', | 62 METADATA_KEYS = {'Homepage', 'Title', 'Expires', 'Checksum', 'Redirect', |
63 'Version'} | 63 'Version'} |
64 INCLUDE_REGEXP = re.compile('%include\s+(.+)%') | 64 INCLUDE_REGEXP = re.compile(r'%include\s+(.+)%') |
65 HEADER_REGEXP = re.compile('\[(Adblock(?:\s*Plus\s*[\d\.]+?)?)\]', flags=re.I) | 65 HEADER_REGEXP = re.compile(r'\[(Adblock(?:\s*Plus\s*[\d\.]+?)?)\]', flags=re.I) |
66 | 66 |
67 | 67 |
68 def _parse_comment(text): | 68 def _parse_comment(text): |
69 match = METADATA_REGEXP.match(text) | 69 match = METADATA_REGEXP.match(text) |
70 if match and match.group(1) in METADATA_KEYS: | 70 if match and match.group(1) in METADATA_KEYS: |
71 return Metadata(match.group(1), match.group(2)) | 71 return Metadata(match.group(1), match.group(2)) |
72 return Comment(text[1:].strip()) | 72 return Comment(text[1:].strip()) |
73 | 73 |
74 | 74 |
75 def _parse_header(text): | 75 def _parse_header(text): |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 112 |
113 def parse_filterlist(lines): | 113 def parse_filterlist(lines): |
114 """Parse filter list from an iterable. | 114 """Parse filter list from an iterable. |
115 | 115 |
116 :param lines: List of strings or file or other iterable. | 116 :param lines: List of strings or file or other iterable. |
117 :returns: Iterator over parsed lines. | 117 :returns: Iterator over parsed lines. |
118 :raises ParseError: Can be thrown during iteration for invalid lines. | 118 :raises ParseError: Can be thrown during iteration for invalid lines. |
119 """ | 119 """ |
120 for line in lines: | 120 for line in lines: |
121 yield parse_line(line) | 121 yield parse_line(line) |
OLD | NEW |