summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-10-02 06:12:33 +0300
committerSimon Glass <sjg@chromium.org>2018-10-08 16:34:34 +0300
commitec9e0f471291233491d1bd213d32bb259821da95 (patch)
tree5c44359d4e2978b124656a627436af1a679f6456 /tools
parent9f8037ea9ca81fc158bc190f7427f329d96ad76c (diff)
downloadu-boot-ec9e0f471291233491d1bd213d32bb259821da95.tar.xz
patman: Handle unicode in _ProjectConfigParser tests
With Python 2.7.15rc1, ConfigParser.SafeConfigParser has unfortunately started returning unicode, for unknown reasons. Adjust the code to handle this by converting everything to unicode. We cannot convert things to ASCII since email addresses may be encoded with UTF-8. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/patman/settings.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/tools/patman/settings.py b/tools/patman/settings.py
index ca4334426b..ea2bc74f75 100644
--- a/tools/patman/settings.py
+++ b/tools/patman/settings.py
@@ -58,25 +58,25 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser):
>>> config = _ProjectConfigParser("zzz")
>>> config.readfp(StringIO(sample_config))
>>> config.get("alias", "enemies")
- 'Evil <evil@example.com>'
+ u'Evil <evil@example.com>'
# Check to make sure that alias gets overridden by project.
>>> config = _ProjectConfigParser("sm")
>>> config.readfp(StringIO(sample_config))
>>> config.get("alias", "enemies")
- 'Green G. <ugly@example.com>'
+ u'Green G. <ugly@example.com>'
# Check to make sure that settings get merged with project.
>>> config = _ProjectConfigParser("linux")
>>> config.readfp(StringIO(sample_config))
>>> sorted(config.items("settings"))
- [('am_hero', 'True'), ('process_tags', 'False')]
+ [(u'am_hero', u'True'), (u'process_tags', u'False')]
# Check to make sure that settings works with unknown project.
>>> config = _ProjectConfigParser("unknown")
>>> config.readfp(StringIO(sample_config))
>>> sorted(config.items("settings"))
- [('am_hero', 'True')]
+ [(u'am_hero', u'True')]
"""
def __init__(self, project_name):
"""Construct _ProjectConfigParser.
@@ -99,6 +99,17 @@ 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.
@@ -108,14 +119,15 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser):
See SafeConfigParser.
"""
try:
- return ConfigParser.SafeConfigParser.get(
+ val = ConfigParser.SafeConfigParser.get(
self, "%s_%s" % (self._project_name, section), option,
*args, **kwargs
)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
- return ConfigParser.SafeConfigParser.get(
+ val = ConfigParser.SafeConfigParser.get(
self, section, option, *args, **kwargs
)
+ return self._to_unicode(val)
def items(self, section, *args, **kwargs):
"""Extend SafeConfigParser to add project_section to section.
@@ -150,7 +162,8 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser):
item_dict = dict(top_items)
item_dict.update(project_items)
- return item_dict.items()
+ return {(self._to_unicode(item), self._to_unicode(val))
+ for item, val in item_dict.iteritems()}
def ReadGitAliases(fname):
"""Read a git alias file. This is in the form used by git: