| 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 | 6 |
| 7 import json |
| 7 from xml.dom import minidom | 8 from xml.dom import minidom |
| 8 from grit import lazy_re | 9 from grit import lazy_re |
| 9 from grit.format.policy_templates.writers import xml_formatted_writer | 10 from grit.format.policy_templates.writers import xml_formatted_writer |
| 10 | 11 |
| 11 | 12 |
| 12 def GetWriter(config): | 13 def GetWriter(config): |
| 13 '''Factory method for creating DocWriter objects. | 14 '''Factory method for creating DocWriter objects. |
| 14 See the constructor of TemplateWriter for description of | 15 See the constructor of TemplateWriter for description of |
| 15 arguments. | 16 arguments. |
| 16 ''' | 17 ''' |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 '''Adds an example value for Windows of a 'dict' policy to a DOM node. | 281 '''Adds an example value for Windows of a 'dict' policy to a DOM node. |
| 281 | 282 |
| 282 Args: | 283 Args: |
| 283 parent: The DOM node for which the example will be added. | 284 parent: The DOM node for which the example will be added. |
| 284 policy: A policy of type 'dict', for which the Windows example value | 285 policy: A policy of type 'dict', for which the Windows example value |
| 285 is generated. | 286 is generated. |
| 286 ''' | 287 ''' |
| 287 self.AddElement(parent, 'dt', {}, 'Windows:') | 288 self.AddElement(parent, 'dt', {}, 'Windows:') |
| 288 win = self._AddStyledElement(parent, 'dd', ['.monospace', '.pre']) | 289 win = self._AddStyledElement(parent, 'dd', ['.monospace', '.pre']) |
| 289 key_name = self.config['win_reg_mandatory_key_name'] | 290 key_name = self.config['win_reg_mandatory_key_name'] |
| 290 example = str(policy['example_value']) | 291 example = json.dumps(policy['example_value']) |
| 291 self.AddText(win, '%s\\%s = "%s"' % (key_name, policy['name'], example)) | 292 self.AddText(win, '%s\\%s = %s' % (key_name, policy['name'], example)) |
| 292 | 293 |
| 293 def _AddDictionaryExampleLinux(self, parent, policy): | 294 def _AddDictionaryExampleLinux(self, parent, policy): |
| 294 '''Adds an example value for Linux of a 'dict' policy to a DOM node. | 295 '''Adds an example value for Linux of a 'dict' policy to a DOM node. |
| 295 | 296 |
| 296 Args: | 297 Args: |
| 297 parent: The DOM node for which the example will be added. | 298 parent: The DOM node for which the example will be added. |
| 298 policy: A policy of type 'dict', for which the Linux example value | 299 policy: A policy of type 'dict', for which the Linux example value |
| 299 is generated. | 300 is generated. |
| 300 ''' | 301 ''' |
| 301 self.AddElement(parent, 'dt', {}, 'Linux:') | 302 self.AddElement(parent, 'dt', {}, 'Linux:') |
| 302 linux = self._AddStyledElement(parent, 'dd', ['.monospace']) | 303 linux = self._AddStyledElement(parent, 'dd', ['.monospace']) |
| 303 example = str(policy['example_value']) | 304 example = json.dumps(policy['example_value']) |
| 304 self.AddText(linux, '%s: %s' % (policy['name'], example)) | 305 self.AddText(linux, '%s: %s' % (policy['name'], example)) |
| 305 | 306 |
| 306 def _AddDictionaryExample(self, parent, policy): | 307 def _AddDictionaryExample(self, parent, policy): |
| 307 '''Adds the example value of a 'dict' policy to a DOM node. Example output: | 308 '''Adds the example value of a 'dict' policy to a DOM node. Example output: |
| 308 <dl> | 309 <dl> |
| 309 <dt>Windows:</dt> | 310 <dt>Windows:</dt> |
| 310 <dd> | 311 <dd> |
| 311 Software\Policies\Chromium\ProxySettings = "{ 'ProxyMode': 'direct' }" | 312 Software\Policies\Chromium\ProxySettings = "{ 'ProxyMode': 'direct' }" |
| 312 </dd> | 313 </dd> |
| 313 <dt>Linux:</dt> | 314 <dt>Linux:</dt> |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 } | 675 } |
| 675 | 676 |
| 676 # A simple regexp to search for URLs. It is enough for now. | 677 # A simple regexp to search for URLs. It is enough for now. |
| 677 self._url_matcher = lazy_re.compile('(http://[^\\s]*[^\\s\\.])') | 678 self._url_matcher = lazy_re.compile('(http://[^\\s]*[^\\s\\.])') |
| 678 | 679 |
| 679 def GetTemplateText(self): | 680 def GetTemplateText(self): |
| 680 # Return the text representation of the main <div> tag. | 681 # Return the text representation of the main <div> tag. |
| 681 return self._main_div.toxml() | 682 return self._main_div.toxml() |
| 682 # To get a complete HTML file, use the following. | 683 # To get a complete HTML file, use the following. |
| 683 # return self._doc.toxml() | 684 # return self._doc.toxml() |
| OLD | NEW |