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

Unified Diff: grit/format/policy_templates/policy_template_generator.py

Issue 14940026: Fixes the policy template generator to work predictably even with Python hash randomization turned … (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | grit/format/policy_templates/writers/json_writer_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: grit/format/policy_templates/policy_template_generator.py
===================================================================
--- grit/format/policy_templates/policy_template_generator.py (revision 119)
+++ grit/format/policy_templates/policy_template_generator.py (working copy)
@@ -5,6 +5,7 @@
import copy
+import types
class PolicyTemplateGenerator:
@@ -101,6 +102,20 @@
})
return result
+ def _PrintPolicyValue(self, item):
+ '''Produces a string representation for a policy value. Taking care to print
+ dictionaries in a sorted order.'''
+ if type(item) == types.StringType:
+ str_val = "'%s'" % item
+ elif isinstance(item, dict):
+ str_val = "{";
+ for it in sorted(item.iterkeys()):
+ str_val += "\'%s\': %s, " % (it, self._PrintPolicyValue(item[it]))
+ str_val = str_val.rstrip(", ") + "}";
+ else:
+ str_val = str(item)
+ return str_val;
+
def _ProcessPolicy(self, policy):
'''Processes localized message strings in a policy or a group.
Also breaks up the content of 'supported_on' attribute into a list.
@@ -120,6 +135,8 @@
# Iterate through all the items of an enum-type policy, and add captions.
for item in policy['items']:
item['caption'] = self._ImportMessage(item['caption'])
+ elif policy['type'] == 'dict' and 'example_value' in policy:
+ policy['example_value'] = self._PrintPolicyValue(policy['example_value'])
if policy['type'] != 'group':
if not 'label' in policy:
# If 'label' is not specified, then it defaults to 'caption':
« no previous file with comments | « no previous file | grit/format/policy_templates/writers/json_writer_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698