diff options
author | Simon Glass <sjg@chromium.org> | 2019-05-14 15:53:50 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2019-07-10 16:52:58 -0600 |
commit | 513eace47d63161cabfd3cce82f3e075525b164a (patch) | |
tree | 912b530a6efc46823f3e2f6e9894b0a5cb09e386 /tools/patman/settings.py | |
parent | ade1e3864f1508ad0ccbce72a39d815c2d7d7c87 (diff) |
patman: Move unicode helpers to tools
Create helper functions in the tools module to deal with the differences
between unicode in Python 2 (where we use the 'unicode' type) and Python 3
(where we use the 'str' type).
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/patman/settings.py')
-rw-r--r-- | tools/patman/settings.py | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/tools/patman/settings.py b/tools/patman/settings.py index 07bf6a6ea4..b080136d88 100644 --- a/tools/patman/settings.py +++ b/tools/patman/settings.py @@ -14,6 +14,7 @@ import re import command import gitutil +import tools """Default settings per-project. @@ -99,17 +100,6 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser): for setting_name, setting_value in project_defaults.items(): self.set(project_settings, setting_name, setting_value) - def _to_unicode(self, val): - """Make sure a value is of type 'unicode' - - Args: - val: string or unicode object - - Returns: - unicode version of val - """ - return val if isinstance(val, unicode) else val.decode('utf-8') - def get(self, section, option, *args, **kwargs): """Extend SafeConfigParser to try project_section before section. @@ -127,7 +117,7 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser): val = ConfigParser.SafeConfigParser.get( self, section, option, *args, **kwargs ) - return self._to_unicode(val) + return tools.ToUnicode(val) def items(self, section, *args, **kwargs): """Extend SafeConfigParser to add project_section to section. @@ -162,7 +152,7 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser): item_dict = dict(top_items) item_dict.update(project_items) - return {(self._to_unicode(item), self._to_unicode(val)) + return {(tools.ToUnicode(item), tools.ToUnicode(val)) for item, val in item_dict.items()} def ReadGitAliases(fname): |