| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Model types for describing description xml models.""" | 5 """Model types for describing description xml models.""" |
| 6 | 6 |
| 7 from xml.dom import minidom | 7 from xml.dom import minidom |
| 8 | 8 |
| 9 import sys | 9 import sys |
| 10 import os | 10 import os |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 else: | 151 else: |
| 152 obj[child.attr] = child.node_type.Unmarshall(nodes[0]) | 152 obj[child.attr] = child.node_type.Unmarshall(nodes[0]) |
| 153 return obj | 153 return obj |
| 154 | 154 |
| 155 def Marshall(self, doc, obj): | 155 def Marshall(self, doc, obj): |
| 156 node = doc.createElement(self.tag) | 156 node = doc.createElement(self.tag) |
| 157 attributes = (self.int_attributes + | 157 attributes = (self.int_attributes + |
| 158 self.float_attributes + | 158 self.float_attributes + |
| 159 self.string_attributes) | 159 self.string_attributes) |
| 160 for attr in attributes: | 160 for attr in attributes: |
| 161 node.setAttribute(attr, str(obj[attr])) | 161 if obj[attr]: |
| 162 node.setAttribute(attr, str(obj[attr])) |
| 162 | 163 |
| 163 PutComments(node, obj['comments']) | 164 PutComments(node, obj['comments']) |
| 164 | 165 |
| 165 for child in self.children: | 166 for child in self.children: |
| 166 if child.multiple: | 167 if child.multiple: |
| 167 for o in obj[child.attr]: | 168 for o in obj[child.attr]: |
| 168 node.appendChild(child.node_type.Marshall(doc, o)) | 169 node.appendChild(child.node_type.Marshall(doc, o)) |
| 169 else: | 170 else: |
| 170 node.appendChild(child.node_type.Marshall(doc, obj[child.attr])) | 171 node.appendChild(child.node_type.Marshall(doc, obj[child.attr])) |
| 171 return node | 172 return node |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 206 |
| 206 def ToXML(self, comments, obj): | 207 def ToXML(self, comments, obj): |
| 207 doc = minidom.Document() | 208 doc = minidom.Document() |
| 208 for comment in comments: | 209 for comment in comments: |
| 209 doc.appendChild(comment) | 210 doc.appendChild(comment) |
| 210 doc.appendChild(self.root_type.Marshall(doc, obj)) | 211 doc.appendChild(self.root_type.Marshall(doc, obj)) |
| 211 return doc | 212 return doc |
| 212 | 213 |
| 213 def PrettyPrint(self, comments, obj): | 214 def PrettyPrint(self, comments, obj): |
| 214 return self.GetPrintStyle().PrettyPrintNode(self.ToXML(comments, obj)) | 215 return self.GetPrintStyle().PrettyPrintNode(self.ToXML(comments, obj)) |
| OLD | NEW |