| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 '''Handling of the <include> element. | 6 '''Handling of the <include> element. |
| 7 ''' | 7 ''' |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 return resource_map.SourceFileInclude() | 67 return resource_map.SourceFileInclude() |
| 68 else: | 68 else: |
| 69 return super(type(self), self).ItemFormatter(t) | 69 return super(type(self), self).ItemFormatter(t) |
| 70 | 70 |
| 71 def FileForLanguage(self, lang, output_dir): | 71 def FileForLanguage(self, lang, output_dir): |
| 72 '''Returns the file for the specified language. This allows us to return | 72 '''Returns the file for the specified language. This allows us to return |
| 73 different files for different language variants of the include file. | 73 different files for different language variants of the include file. |
| 74 ''' | 74 ''' |
| 75 return self.FilenameToOpen() | 75 return self.FilenameToOpen() |
| 76 | 76 |
| 77 def GetDataPackPair(self, lang): | 77 def GetDataPackPair(self, lang, encoding): |
| 78 '''Returns a (id, string) pair that represents the resource id and raw | 78 '''Returns a (id, string) pair that represents the resource id and raw |
| 79 bytes of the data. This is used to generate the data pack data file. | 79 bytes of the data. This is used to generate the data pack data file. |
| 80 ''' | 80 ''' |
| 81 from grit.format import rc_header | 81 from grit.format import rc_header |
| 82 id_map = rc_header.Item.tids_ | 82 id_map = rc_header.Item.tids_ |
| 83 id = id_map[self.GetTextualIds()[0]] | 83 id = id_map[self.GetTextualIds()[0]] |
| 84 if self.attrs['flattenhtml'] == 'true': | 84 if self.attrs['flattenhtml'] == 'true': |
| 85 allow_external_script = self.attrs['allowexternalscript'] == 'true' | 85 allow_external_script = self.attrs['allowexternalscript'] == 'true' |
| 86 data = self._GetFlattenedData(allow_external_script=allow_external_script) | 86 data = self._GetFlattenedData(allow_external_script=allow_external_script) |
| 87 else: | 87 else: |
| 88 filename = self.FilenameToOpen() | 88 filename = self.FilenameToOpen() |
| 89 infile = open(filename, 'rb') | 89 infile = open(filename, 'rb') |
| 90 data = infile.read() | 90 data = infile.read() |
| 91 infile.close() | 91 infile.close() |
| 92 | 92 |
| 93 # Include does not care about the encoding, because it only returns binary |
| 94 # data. |
| 93 return id, data | 95 return id, data |
| 94 | 96 |
| 95 def Flatten(self, output_dir): | 97 def Flatten(self, output_dir): |
| 96 '''Rewrite file references to be base64 encoded data URLs. The new file | 98 '''Rewrite file references to be base64 encoded data URLs. The new file |
| 97 will be written to output_dir and the name of the new file is returned.''' | 99 will be written to output_dir and the name of the new file is returned.''' |
| 98 filename = self.FilenameToOpen() | 100 filename = self.FilenameToOpen() |
| 99 flat_filename = os.path.join(output_dir, | 101 flat_filename = os.path.join(output_dir, |
| 100 self.attrs['name'] + '_' + os.path.basename(filename)) | 102 self.attrs['name'] + '_' + os.path.basename(filename)) |
| 101 | 103 |
| 102 if self._last_flat_filename == flat_filename: | 104 if self._last_flat_filename == flat_filename: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 129 node.StartParsing('include', parent) | 131 node.StartParsing('include', parent) |
| 130 node.HandleAttribute('name', name) | 132 node.HandleAttribute('name', name) |
| 131 node.HandleAttribute('type', type) | 133 node.HandleAttribute('type', type) |
| 132 node.HandleAttribute('file', file) | 134 node.HandleAttribute('file', file) |
| 133 node.HandleAttribute('translateable', translateable) | 135 node.HandleAttribute('translateable', translateable) |
| 134 node.HandleAttribute('filenameonly', filenameonly) | 136 node.HandleAttribute('filenameonly', filenameonly) |
| 135 node.HandleAttribute('relativepath', relativepath) | 137 node.HandleAttribute('relativepath', relativepath) |
| 136 node.EndParsing() | 138 node.EndParsing() |
| 137 return node | 139 return node |
| 138 Construct = staticmethod(Construct) | 140 Construct = staticmethod(Construct) |
| 139 | |
| OLD | NEW |