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 |
11 # GNU General Public License for more details. | 11 # GNU General Public License for more details. |
12 # | 12 # |
13 # You should have received a copy of the GNU General Public License | 13 # You should have received a copy of the GNU General Public License |
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 |
16 import argparse | 16 import argparse |
17 import codecs | 17 import io |
18 import logging | 18 import logging |
19 import sys | 19 import sys |
20 | 20 |
21 from .sources import FSSource, TopSource, WebSource, NotFound | 21 from .sources import FSSource, TopSource, WebSource, NotFound |
22 from .renderer import render_filterlist, IncludeError, MissingHeader | 22 from .renderer import render_filterlist, IncludeError, MissingHeader |
23 | 23 |
24 | 24 |
25 def parse_args(): | 25 def parse_args(): |
26 parser = argparse.ArgumentParser(description='Render a filter list.') | 26 parser = argparse.ArgumentParser(description='Render a filter list.') |
27 parser.add_argument( | 27 parser.add_argument( |
(...skipping 20 matching lines...) Expand all Loading... |
48 if args.verbose: | 48 if args.verbose: |
49 logging.basicConfig(level=logging.INFO, stream=sys.stderr, | 49 logging.basicConfig(level=logging.INFO, stream=sys.stderr, |
50 format='%(message)s') | 50 format='%(message)s') |
51 | 51 |
52 for include_path in args.include: | 52 for include_path in args.include: |
53 name, path = include_path.split('=', 1) | 53 name, path = include_path.split('=', 1) |
54 sources[name] = FSSource(path) | 54 sources[name] = FSSource(path) |
55 | 55 |
56 try: | 56 try: |
57 lines = render_filterlist(args.infile, sources, TopSource()) | 57 lines = render_filterlist(args.infile, sources, TopSource()) |
58 with codecs.open(args.outfile, 'wb', encoding='utf-8') as out_fp: | 58 with io.open(args.outfile, 'w', encoding='utf-8') as out_fp: |
59 for line in lines: | 59 for line in lines: |
60 out_fp.write(line.to_string() + '\n') | 60 out_fp.write(line.to_string() + '\n') |
61 except (MissingHeader, NotFound, IncludeError) as exc: | 61 except (MissingHeader, NotFound, IncludeError) as exc: |
62 sys.exit(exc) | 62 sys.exit(exc) |
OLD | NEW |