OLD | NEW |
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. |
11 """ | 11 """ |
12 | 12 |
13 import os | 13 import os |
14 import re | 14 import re |
15 import sys | 15 import sys |
16 import base64 | 16 import base64 |
17 import mimetypes | 17 import mimetypes |
18 | 18 |
19 from grit import lazy_re | 19 from grit import lazy_re |
20 from grit import util | 20 from grit import util |
21 | 21 |
| 22 # There is a python bug that makes mimetypes crash if the Windows |
| 23 # registry contains non-Latin keys ( http://bugs.python.org/issue9291 |
| 24 # ). Initing manually and blocking external mime-type databases will |
| 25 # prevent that bug and still give us the data we need. |
| 26 mimetypes.init([]) |
| 27 |
22 DIST_DEFAULT = 'chromium' | 28 DIST_DEFAULT = 'chromium' |
23 DIST_ENV_VAR = 'CHROMIUM_BUILD' | 29 DIST_ENV_VAR = 'CHROMIUM_BUILD' |
24 DIST_SUBSTR = '%DISTRIBUTION%' | 30 DIST_SUBSTR = '%DISTRIBUTION%' |
25 | 31 |
26 # Matches beginning of an "if" block with trailing spaces. | 32 # Matches beginning of an "if" block with trailing spaces. |
27 _BEGIN_IF_BLOCK = lazy_re.compile( | 33 _BEGIN_IF_BLOCK = lazy_re.compile( |
28 '<if [^>]*?expr="(?P<expression>[^"]*)"[^>]*?>\s*') | 34 '<if [^>]*?expr="(?P<expression>[^"]*)"[^>]*?>\s*') |
29 | 35 |
30 # Matches ending of an "if" block with preceding spaces. | 36 # Matches ending of an "if" block with preceding spaces. |
31 _END_IF_BLOCK = lazy_re.compile('\s*</if>') | 37 _END_IF_BLOCK = lazy_re.compile('\s*</if>') |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 | 418 |
413 def main(): | 419 def main(): |
414 if len(sys.argv) <= 2: | 420 if len(sys.argv) <= 2: |
415 print "Flattens a HTML file by inlining its external resources.\n" | 421 print "Flattens a HTML file by inlining its external resources.\n" |
416 print "html_inline.py inputfile outputfile" | 422 print "html_inline.py inputfile outputfile" |
417 else: | 423 else: |
418 InlineToFile(sys.argv[1], sys.argv[2], None) | 424 InlineToFile(sys.argv[1], sys.argv[2], None) |
419 | 425 |
420 if __name__ == '__main__': | 426 if __name__ == '__main__': |
421 main() | 427 main() |
OLD | NEW |