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

Side by Side Diff: cms/converters.py

Issue 29711681: Noissue - Remove Redundant Parentheses (Closed) Base URL: https://hg.adblockplus.org/cms
Patch Set: add list comprehension and positional args Created March 2, 2018, 12:51 a.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 | « no previous file | 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
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 if callback: 174 if callback:
175 callback(page, locale, name, result, comment, fixed_strings) 175 callback(page, locale, name, result, comment, fixed_strings)
176 176
177 # Insert fixed strings 177 # Insert fixed strings
178 for i, fixed_string in enumerate(fixed_strings, 1): 178 for i, fixed_string in enumerate(fixed_strings, 1):
179 result = result.replace('{{{}}}'.format(i), fixed_string) 179 result = result.replace('{{{}}}'.format(i), fixed_string)
180 180
181 # Insert attributes 181 # Insert attributes
182 result = escape(result) 182 result = escape(result)
183 183
184 def stringify_attribute((name, value)): 184 def stringify_attribute(name, value):
185 return '{}="{}"'.format( 185 return '{}="{}"'.format(
186 escape(name), 186 escape(name),
187 escape(self.insert_localized_strings(value, {})) 187 escape(self.insert_localized_strings(value, {}))
188 ) 188 )
189 189
190 for tag in self.whitelist: 190 for tag in self.whitelist:
191 allowed_contents = '(?:[^<>]|{})'.format('|'.join( 191 allowed_contents = '(?:[^<>]|{})'.format('|'.join(
192 '<(?:{}[^<>]*?|/{})>'.format(t, t) 192 '<(?:{}[^<>]*?|/{})>'.format(t, t)
193 for t in map(re.escape, self.whitelist - {tag}) 193 for t in map(re.escape, self.whitelist - {tag})
194 )) 194 ))
195 saved = saved_attributes.get(tag, []) 195 saved = saved_attributes.get(tag, [])
196 for attrs in saved: 196 for attrs in saved:
197 attrs = map(stringify_attribute, attrs) 197 attrs = [stringify_attribute(*attr) for attr in attrs]
198 result = re.sub( 198 result = re.sub(
199 r'{}({}*?){}'.format(re_escape('<{}>'.format(tag)), 199 r'{}({}*?){}'.format(re_escape('<{}>'.format(tag)),
200 allowed_contents, 200 allowed_contents,
201 re_escape('</{}>'.format(tag))), 201 re_escape('</{}>'.format(tag))),
202 lambda match: r'<{}{}>{}</{}>'.format( 202 lambda match: r'<{}{}>{}</{}>'.format(
203 tag, 203 tag,
204 ' ' + ' '.join(attrs) if attrs else '', 204 ' ' + ' '.join(attrs) if attrs else '',
205 match.group(1), 205 match.group(1),
206 tag 206 tag
207 ), 207 ),
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 stack[-1]['subitems'].append(item) 528 stack[-1]['subitems'].append(item)
529 stack.append(item) 529 stack.append(item)
530 return structured 530 return structured
531 531
532 532
533 converters = { 533 converters = {
534 'html': RawConverter, 534 'html': RawConverter,
535 'md': MarkdownConverter, 535 'md': MarkdownConverter,
536 'tmpl': TemplateConverter, 536 'tmpl': TemplateConverter,
537 } 537 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld