Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: grit/format/policy_templates/writers/xml_formatted_writer.py

Issue 687073003: Set the MAXLEN/maxLength attribute for strings in ADM[X] templates. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « grit/format/policy_templates/writers/admx_writer_unittest.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 from grit.format.policy_templates.writers import template_writer 7 from grit.format.policy_templates.writers import template_writer
8 8
9 9
10 class XMLFormattedWriter(template_writer.TemplateWriter): 10 class XMLFormattedWriter(template_writer.TemplateWriter):
(...skipping 13 matching lines...) Expand all
24 text: Text content for the new element. 24 text: Text content for the new element.
25 25
26 Returns: 26 Returns:
27 The created new element. 27 The created new element.
28 ''' 28 '''
29 if attrs == None: 29 if attrs == None:
30 attrs = {} 30 attrs = {}
31 31
32 doc = parent.ownerDocument 32 doc = parent.ownerDocument
33 element = doc.createElement(name) 33 element = doc.createElement(name)
34 for key, value in attrs.iteritems(): 34 for key, value in sorted(attrs.iteritems()):
35 element.setAttribute(key, value) 35 element.setAttribute(key, value)
36 if text: 36 if text:
37 element.appendChild(doc.createTextNode(text)) 37 element.appendChild(doc.createTextNode(text))
38 parent.appendChild(element) 38 parent.appendChild(element)
39 return element 39 return element
40 40
41 def AddText(self, parent, text): 41 def AddText(self, parent, text):
42 '''Adds text to a parent node. 42 '''Adds text to a parent node.
43 ''' 43 '''
44 doc = parent.ownerDocument 44 doc = parent.ownerDocument
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 # printing. 82 # printing.
83 indent = indent[2:] 83 indent = indent[2:]
84 lines[i] = indent + '<' + line + '>' 84 lines[i] = indent + '<' + line + '>'
85 if (line[0] not in ['/', '?', '!'] and '</' not in line and 85 if (line[0] not in ['/', '?', '!'] and '</' not in line and
86 line[len(line) - 1] != '/'): 86 line[len(line) - 1] != '/'):
87 # If the current line starts with an opening tag and does not conatin a 87 # If the current line starts with an opening tag and does not conatin a
88 # closing tag, increase indent after the line is printed. 88 # closing tag, increase indent after the line is printed.
89 indent += ' ' 89 indent += ' '
90 # Reconstruct XML text from the lines. 90 # Reconstruct XML text from the lines.
91 return '\n'.join(lines) 91 return '\n'.join(lines)
OLDNEW
« no previous file with comments | « grit/format/policy_templates/writers/admx_writer_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698