Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: grit/format/html_inline.py

Issue 1002663003: Raises an exception when an unexpected </if> occurs (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | grit/format/html_inline_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Flattens a HTML file by inlining its external resources. 6 """Flattens a HTML file by inlining its external resources.
7 7
8 This is a small script that takes a HTML file, looks for src attributes 8 This is a small script that takes a HTML file, looks for src attributes
9 and inlines the specified file, producing one HTML file with no external 9 and inlines the specified file, producing one HTML file with no external
10 dependencies. It recursively inlines the included files. 10 dependencies. It recursively inlines the included files.
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 def IsConditionSatisfied(src_match): 178 def IsConditionSatisfied(src_match):
179 expression = src_match.group('expression') 179 expression = src_match.group('expression')
180 return grd_node is None or grd_node.EvaluateCondition(expression) 180 return grd_node is None or grd_node.EvaluateCondition(expression)
181 181
182 def CheckConditionalElements(str): 182 def CheckConditionalElements(str):
183 """Helper function to conditionally inline inner elements""" 183 """Helper function to conditionally inline inner elements"""
184 while True: 184 while True:
185 begin_if = _BEGIN_IF_BLOCK.search(str) 185 begin_if = _BEGIN_IF_BLOCK.search(str)
186 if begin_if is None: 186 if begin_if is None:
187 if _END_IF_BLOCK.search(str) is not None:
188 raise Exception('Unexpected </if>')
Nico 2015/03/26 17:58:56 Should this be 'Unmatched </if>' to match the simi
187 return str 189 return str
188 190
189 condition_satisfied = IsConditionSatisfied(begin_if) 191 condition_satisfied = IsConditionSatisfied(begin_if)
190 leading = str[0:begin_if.start()] 192 leading = str[0:begin_if.start()]
191 content_start = begin_if.end() 193 content_start = begin_if.end()
192 194
193 # Find matching "if" block end. 195 # Find matching "if" block end.
194 count = 1 196 count = 1
195 pos = begin_if.end() 197 pos = begin_if.end()
196 while True: 198 while True:
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 414
413 def main(): 415 def main():
414 if len(sys.argv) <= 2: 416 if len(sys.argv) <= 2:
415 print "Flattens a HTML file by inlining its external resources.\n" 417 print "Flattens a HTML file by inlining its external resources.\n"
416 print "html_inline.py inputfile outputfile" 418 print "html_inline.py inputfile outputfile"
417 else: 419 else:
418 InlineToFile(sys.argv[1], sys.argv[2], None) 420 InlineToFile(sys.argv[1], sys.argv[2], None)
419 421
420 if __name__ == '__main__': 422 if __name__ == '__main__':
421 main() 423 main()
OLDNEW
« no previous file with comments | « no previous file | grit/format/html_inline_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698