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

Side by Side Diff: cms/sources.py

Issue 30044555: Issue 7461 - Include source page into warning text for unresolved links (Closed) Base URL: https://hg.adblockplus.org/cms
Patch Set: Created April 12, 2019, 2:05 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 | « cms/converters.py ('k') | no next file » | 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 the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
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 import io 16 import io
17 import collections 17 import collections
18 import ConfigParser 18 import ConfigParser
19 import json 19 import json
20 import os 20 import os
21 from StringIO import StringIO 21 from StringIO import StringIO
22 from random import randint 22 from random import randint
23 import urlparse 23 import urlparse
24 import logging 24 import logging
25 25
26 from cms import utils 26 from cms import utils
27 27
28 28
29 class Source: 29 class Source:
30 def resolve_link(self, url, locale): 30 def resolve_link(self, url, locale, source_page=None):
31 parsed = urlparse.urlparse(url) 31 parsed = urlparse.urlparse(url)
32 page = parsed.path 32 page = parsed.path
33 if parsed.scheme != '' or page.startswith('/') or page.startswith('.'): 33 if parsed.scheme != '' or page.startswith('/') or page.startswith('.'):
34 # Not a page link 34 # Not a page link
35 return None, None 35 return None, None
36 36
37 if url.startswith('tel:'): 37 if url.startswith('tel:'):
38 # Workaround for 'tel' scheme not recognized in Python <=2.7.3. 38 # Workaround for 'tel' scheme not recognized in Python <=2.7.3.
39 return None, None 39 return None, None
40 40
(...skipping 11 matching lines...) Expand all
52 locale = default_locale 52 locale = default_locale
53 elif self.has_page(page): 53 elif self.has_page(page):
54 if not self.has_locale(locale, page): 54 if not self.has_locale(locale, page):
55 locale = default_locale 55 locale = default_locale
56 elif self.has_page(alternative_page): 56 elif self.has_page(alternative_page):
57 if not self.has_locale(locale, alternative_page): 57 if not self.has_locale(locale, alternative_page):
58 locale = default_locale 58 locale = default_locale
59 elif self.has_static(page): 59 elif self.has_static(page):
60 locale = None 60 locale = None
61 else: 61 else:
62 logging.warning('Link to %s cannot be resolved', page) 62 logging.warning('Link to "%s" (from "%s") cannot be resolved',
63 page, source_page)
63 64
64 parts = page.split('/') 65 parts = page.split('/')
65 if parts[-1] == default_page: 66 if parts[-1] == default_page:
66 page = '/'.join(parts[:-1]) 67 page = '/'.join(parts[:-1])
67 if locale: 68 if locale:
68 path = '/{}/{}'.format(locale, page) 69 path = '/{}/{}'.format(locale, page)
69 return locale, urlparse.urlunparse(parsed[0:2] + (path,) + parsed[3: ]) 70 return locale, urlparse.urlunparse(parsed[0:2] + (path,) + parsed[3: ])
70 return locale, '/' + page 71 return locale, '/' + page
71 72
72 def read_config(self): 73 def read_config(self):
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 'read_config', 400 'read_config',
400 'read_template', 401 'read_template',
401 'read_locale', 402 'read_locale',
402 'read_file', 403 'read_file',
403 'read_include', 404 'read_include',
404 'exec_file', 405 'exec_file',
405 ]: 406 ]:
406 setattr(source, fname, utils.memoize(getattr(source, fname))) 407 setattr(source, fname, utils.memoize(getattr(source, fname)))
407 408
408 return source 409 return source
OLDNEW
« no previous file with comments | « cms/converters.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld