LEFT | RIGHT |
(no file at all) | |
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 dict | 59 dict |
60 With all strings encoded as unicode. | 60 With all strings encoded as unicode. |
61 | 61 |
62 """ | 62 """ |
63 if isinstance(data, dict): | 63 if isinstance(data, dict): |
64 return {strings2utf8(k): strings2utf8(v) for k, v in data.items()} | 64 return {strings2utf8(k): strings2utf8(v) for k, v in data.items()} |
65 if isinstance(data, list): | 65 if isinstance(data, list): |
66 return [strings2utf8(v) for v in data] | 66 return [strings2utf8(v) for v in data] |
67 if isinstance(data, tuple): | 67 if isinstance(data, tuple): |
68 return tuple(strings2utf8(v) for v in data) | 68 return tuple(strings2utf8(v) for v in data) |
69 if isinstance(data, type('')): # Python 2/3 compatible way of | 69 if isinstance(data, type('')): |
70 # saying "unicode string". | 70 # The condition is a Python 2/3 way of saying "unicode string". |
71 return data.encode('utf-8') | 71 return data.encode('utf-8') |
72 return data | 72 return data |
73 | 73 |
74 | 74 |
75 def line2dict(text, mode='body'): | 75 def line2dict(text, mode='body'): |
76 """Convert a filterlist line to a dictionary. | 76 """Convert a filterlist line to a dictionary. |
77 | 77 |
78 All strings in the output dictionary will be UTF8 byte strings. This is | 78 All strings in the output dictionary will be UTF8 byte strings. This is |
79 necessary to prevent unicode encoding errors in rPython conversion layer. | 79 necessary to prevent unicode encoding errors in rPython conversion layer. |
80 | 80 |
81 Parameters | 81 Parameters |
82 ---------- | 82 ---------- |
83 text: str | 83 text: str |
84 The filter text we want to parse | 84 The filter text we want to parse |
85 mode: str | 85 mode: str |
86 Parsing mode (see `abp.filters.parser.parse_line`). | 86 Parsing mode (see `abp.filters.parser.parse_line`). |
87 | 87 |
88 Returns | 88 Returns |
89 ------- | 89 ------- |
90 dict | 90 dict |
91 With the parsing results and all strings converted to utf8 byte | 91 With the parsing results and all strings converted to utf8 byte |
92 strings. | 92 strings. |
93 | 93 |
94 """ | 94 """ |
95 return strings2utf8(tuple2dict(parse_line(text, mode))) | 95 return strings2utf8(tuple2dict(parse_line(text, mode))) |
LEFT | RIGHT |