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

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

Issue 29968569: Issue 4014 - Publish python-abp on PyPI (Closed) Base URL: https://hg.adblockplus.org/python-abp/
Left Patch Set: Created Dec. 27, 2018, 11:31 p.m.
Right Patch Set: Address comment on PS5 Created Jan. 3, 2019, 9:32 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 | « README.rst ('k') | setup.py » ('j') | no next file with change/comment »
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
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 """Helper classes that handle IO for filter list parsing and rendering.""" 16 """Helper classes that handle IO for filter list parsing and rendering."""
17 17
18 import io 18 import io
19 from os import path 19 from os import path
20 import sys 20 import sys
21 21
22 try: 22 try:
23 from urllib2 import urlopen, HTTPError 23 from urllib2 import urlopen, HTTPError
24 except ImportError: # pragma: no py2 cover 24 except ImportError: # pragma: no py2 cover
25 # The module was renamed in Python 3
26 from urllib.request import urlopen 25 from urllib.request import urlopen
27 from urllib.error import HTTPError 26 from urllib.error import HTTPError
28 27
29 __all__ = ['NotFound', 'FSSource', 'TopSource', 'WebSource'] 28 __all__ = ['NotFound', 'FSSource', 'TopSource', 'WebSource']
30 29
31 30
32 class NotFound(Exception): 31 class NotFound(Exception):
33 """Requested file doesn't exist in this source. 32 """Requested file doesn't exist in this source.
34 33
35 The file with requested name doesn't exist. If this results from an 34 The file with requested name doesn't exist. If this results from an
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 try: 167 try:
169 response = urlopen(url) 168 response = urlopen(url)
170 info = response.info() 169 info = response.info()
171 # info.getparam became info.get_param in Python 3 so we'll 170 # info.getparam became info.get_param in Python 3 so we'll
172 # try both. 171 # try both.
173 get_param = (getattr(info, 'get_param', None) 172 get_param = (getattr(info, 'get_param', None)
174 or getattr(info, 'getparam', None)) 173 or getattr(info, 'getparam', None))
175 encoding = get_param('charset') or self.default_encoding 174 encoding = get_param('charset') or self.default_encoding
176 for line in response: 175 for line in response:
177 yield line.decode(encoding).rstrip() 176 yield line.decode(encoding).rstrip()
178 except (HTTPError, ValueError) as err: 177 except HTTPError as err:
179 try: 178 if err.code == 404:
180 if err.code == 404: 179 raise NotFound("HTTP 404 Not found: '{}:{}'"
181 raise NotFound("HTTP 404 Not found: '{}:{}'" 180 .format(self.protocol, path_in_source))
182 .format(self.protocol, path_in_source)) 181 raise err
183 except AttributeError: # Need to catch so the real err is raised
184 raise err
Sebastian Noack 2018/12/28 00:22:51 Previously, when we got an HTTPError with a code o
rhowell 2018/12/28 21:50:07 Ah, you're right, thanks.
LEFTRIGHT

Powered by Google App Engine
This is Rietveld