| 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 '''Class for reading GRD files into memory, without processing them. | 6 '''Class for reading GRD files into memory, without processing them. |
| 7 ''' | 7 ''' |
| 8 | 8 |
| 9 import os.path | 9 import os.path |
| 10 import types | 10 import types |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 def endElement(self, name): | 78 def endElement(self, name): |
| 79 if self.ignore_depth: | 79 if self.ignore_depth: |
| 80 self.ignore_depth -= 1 | 80 self.ignore_depth -= 1 |
| 81 return | 81 return |
| 82 | 82 |
| 83 if name == 'part': | 83 if name == 'part': |
| 84 partnode = self.stack[-1] | 84 partnode = self.stack[-1] |
| 85 partnode.started_inclusion = True | 85 partnode.started_inclusion = True |
| 86 # Add the contents of the sub-grd file as children of the <part> node. | 86 # Add the contents of the sub-grd file as children of the <part> node. |
| 87 partname = partnode.GetInputPath() | 87 partname = os.path.join(self.dir, partnode.GetInputPath()) |
| 88 if os.path.dirname(partname): | 88 # Check the GRDP file exists. |
| 89 # TODO(benrg): Remove this limitation. (The problem is that GRIT | 89 if not os.path.exists(partname): |
| 90 # assumes that files referenced from the GRD file are relative to | 90 raise exception.FileNotFound() |
| 91 # a path stored in the root <grit> node.) | |
| 92 raise exception.GotPathExpectedFilenameOnly() | |
| 93 partname = os.path.join(self.dir, partname) | |
| 94 # Exceptions propagate to the handler in grd_reader.Parse(). | 91 # Exceptions propagate to the handler in grd_reader.Parse(). |
| 95 xml.sax.parse(partname, GrdPartContentHandler(self)) | 92 xml.sax.parse(partname, GrdPartContentHandler(self)) |
| 96 | 93 |
| 97 if self.debug: | 94 if self.debug: |
| 98 print "End parsing of element %s" % name | 95 print "End parsing of element %s" % name |
| 99 self.stack.pop().EndParsing() | 96 self.stack.pop().EndParsing() |
| 100 | 97 |
| 101 if name == self.stop_after: | 98 if name == self.stop_after: |
| 102 raise StopParsingException() | 99 raise StopParsingException() |
| 103 | 100 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 handler.root.attrs['first_ids_file'] = first_ids_file | 215 handler.root.attrs['first_ids_file'] = first_ids_file |
| 219 # Assign first ids to the nodes that don't have them. | 216 # Assign first ids to the nodes that don't have them. |
| 220 handler.root.AssignFirstIds(filename_or_stream, defines) | 217 handler.root.AssignFirstIds(filename_or_stream, defines) |
| 221 | 218 |
| 222 return handler.root | 219 return handler.root |
| 223 | 220 |
| 224 | 221 |
| 225 if __name__ == '__main__': | 222 if __name__ == '__main__': |
| 226 util.ChangeStdoutEncoding() | 223 util.ChangeStdoutEncoding() |
| 227 print unicode(Parse(sys.argv[1])) | 224 print unicode(Parse(sys.argv[1])) |
| OLD | NEW |