| 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 '''Base types for nodes in a GRIT resource tree. | 6 '''Base types for nodes in a GRIT resource tree. |
| 7 ''' | 7 ''' |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 return ''.join([c for c in self.mixed_content | 215 return ''.join([c for c in self.mixed_content |
| 216 if isinstance(c, types.StringTypes)]) | 216 if isinstance(c, types.StringTypes)]) |
| 217 | 217 |
| 218 def __unicode__(self): | 218 def __unicode__(self): |
| 219 '''Returns this node and all nodes below it as an XML document in a Unicode | 219 '''Returns this node and all nodes below it as an XML document in a Unicode |
| 220 string.''' | 220 string.''' |
| 221 header = u'<?xml version="1.0" encoding="UTF-8"?>\n' | 221 header = u'<?xml version="1.0" encoding="UTF-8"?>\n' |
| 222 return header + self.FormatXml() | 222 return header + self.FormatXml() |
| 223 | 223 |
| 224 # Compliance with ItemFormatter interface. | 224 # Compliance with ItemFormatter interface. |
| 225 def Format(self, item, lang_re = None, begin_item=True): | 225 def Format(self, item, lang_re = None): |
| 226 if not begin_item: | 226 return item.FormatXml() |
| 227 return '' | |
| 228 else: | |
| 229 return item.FormatXml() | |
| 230 | 227 |
| 231 def FormatXml(self, indent = u'', one_line = False): | 228 def FormatXml(self, indent = u'', one_line = False): |
| 232 '''Returns this node and all nodes below it as an XML | 229 '''Returns this node and all nodes below it as an XML |
| 233 element in a Unicode string. This differs from __unicode__ in that it does | 230 element in a Unicode string. This differs from __unicode__ in that it does |
| 234 not include the <?xml> stuff at the top of the string. If one_line is true, | 231 not include the <?xml> stuff at the top of the string. If one_line is true, |
| 235 children and CDATA are layed out in a way that preserves internal | 232 children and CDATA are layed out in a way that preserves internal |
| 236 whitespace. | 233 whitespace. |
| 237 ''' | 234 ''' |
| 238 assert isinstance(indent, types.StringTypes) | 235 assert isinstance(indent, types.StringTypes) |
| 239 | 236 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 if recursive: | 312 if recursive: |
| 316 process_last = [] | 313 process_last = [] |
| 317 for child in self.children: | 314 for child in self.children: |
| 318 if child.name == 'translations': | 315 if child.name == 'translations': |
| 319 process_last.append(child) | 316 process_last.append(child) |
| 320 else: | 317 else: |
| 321 child.RunGatherers(recursive=recursive, debug=debug) | 318 child.RunGatherers(recursive=recursive, debug=debug) |
| 322 for child in process_last: | 319 for child in process_last: |
| 323 child.RunGatherers(recursive=recursive, debug=debug) | 320 child.RunGatherers(recursive=recursive, debug=debug) |
| 324 | 321 |
| 322 def SubstituteMessages(self, substituter): |
| 323 '''Applies substitutions to all messages in the tree. |
| 324 |
| 325 Called as a final step of RunGatherers. |
| 326 |
| 327 Args: |
| 328 substituter: a grit.util.Substituter object. |
| 329 ''' |
| 330 for child in self.children: |
| 331 child.SubstituteMessages(substituter) |
| 332 |
| 325 def ItemFormatter(self, type): | 333 def ItemFormatter(self, type): |
| 326 '''Returns an instance of the item formatter for this object of the | 334 '''Returns an instance of the item formatter for this object of the |
| 327 specified type, or None if not supported. | 335 specified type, or None if not supported. |
| 328 | 336 |
| 329 Args: | 337 Args: |
| 330 type: 'rc-header' | 338 type: 'rc-header' |
| 331 | 339 |
| 332 Return: | 340 Return: |
| 333 (object RcHeaderItemFormatter) | 341 (object RcHeaderItemFormatter) |
| 334 ''' | 342 ''' |
| 335 if type == 'xml': | 343 if type == 'xml': |
| 336 return self | 344 return self |
| 337 else: | 345 else: |
| 338 return None | 346 return None |
| 339 | 347 |
| 340 def SatisfiesOutputCondition(self): | 348 def SatisfiesOutputCondition(self): |
| 341 '''Returns true if this node is either not a child of an <if> element | 349 '''Returns true if this node is either not a descendant of an <if> element, |
| 342 or if it is a child of an <if> element and the conditions for it being | 350 or if all conditions on its <if> element ancestors are satisfied. |
| 343 output are satisfied. | |
| 344 | 351 |
| 345 Used to determine whether to return item formatters for formats that | 352 Used to determine whether to return item formatters for formats that |
| 346 obey conditional output of resources (e.g. the RC formatters). | 353 obey conditional output of resources (e.g. the RC formatters). |
| 347 ''' | 354 ''' |
| 348 from grit.node import misc | 355 from grit.node import misc |
| 349 if not self.parent or not isinstance(self.parent, misc.IfNode): | 356 if self.parent: |
| 357 return self.parent.SatisfiesOutputCondition() |
| 358 else: |
| 350 return True | 359 return True |
| 351 else: | |
| 352 return self.parent.IsConditionSatisfied() | |
| 353 | 360 |
| 354 def _IsValidChild(self, child): | 361 def _IsValidChild(self, child): |
| 355 '''Returns true if 'child' is a valid child of this node. | 362 '''Returns true if 'child' is a valid child of this node. |
| 356 Overridden by subclasses.''' | 363 Overridden by subclasses.''' |
| 357 return False | 364 return False |
| 358 | 365 |
| 359 def _IsValidAttribute(self, name, value): | 366 def _IsValidAttribute(self, name, value): |
| 360 '''Returns true if 'name' is the name of a valid attribute of this element | 367 '''Returns true if 'name' is the name of a valid attribute of this element |
| 361 and 'value' is a valid value for that attribute. Overriden by | 368 and 'value' is a valid value for that attribute. Overriden by |
| 362 subclasses unless they have only mandatory attributes.''' | 369 subclasses unless they have only mandatory attributes.''' |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 '''Returns true if the node is marked to be skipped in the output by a | 553 '''Returns true if the node is marked to be skipped in the output by a |
| 547 whitelist. | 554 whitelist. |
| 548 ''' | 555 ''' |
| 549 return self._whitelist_marked_as_skip | 556 return self._whitelist_marked_as_skip |
| 550 | 557 |
| 551 def SetWhitelistMarkedAsSkip(self, mark_skipped): | 558 def SetWhitelistMarkedAsSkip(self, mark_skipped): |
| 552 '''Sets WhitelistMarkedAsSkip. | 559 '''Sets WhitelistMarkedAsSkip. |
| 553 ''' | 560 ''' |
| 554 self._whitelist_marked_as_skip = mark_skipped | 561 self._whitelist_marked_as_skip = mark_skipped |
| 555 | 562 |
| 563 def ExpandVariables(self): |
| 564 '''Whether we need to expand variables on a given node.''' |
| 565 return False |
| 566 |
| 556 | 567 |
| 557 class ContentNode(Node): | 568 class ContentNode(Node): |
| 558 '''Convenience baseclass for nodes that can have content.''' | 569 '''Convenience baseclass for nodes that can have content.''' |
| 559 def _ContentType(self): | 570 def _ContentType(self): |
| 560 return self._CONTENT_TYPE_MIXED | 571 return self._CONTENT_TYPE_MIXED |
| 561 | 572 |
| OLD | NEW |