aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2020-08-26 12:23:08 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-08-26 12:23:08 +0000
commit425db52f349d233f4501180c8949bd6ba9f20b92 (patch)
tree0565ed442f7b0da0e9e150d6cfa5c13f2acc799d
parentfd6d0e0b33455142503a39741c486ff26c6ba232 (diff)
parent41a1fd1aac95a1037bfb58dc4bba99854272909c (diff)
downloadrepohooks-425db52f349d233f4501180c8949bd6ba9f20b92.tar.gz
config: add Python 3 compat APIs am: 41a1fd1aac
Original change: https://android-review.googlesource.com/c/platform/tools/repohooks/+/1409411 Change-Id: I20b225c3916994aabf677b5fdc86c5f5dbdae60f
-rw-r--r--rh/config.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/rh/config.py b/rh/config.py
index 00d4640..c3d983d 100644
--- a/rh/config.py
+++ b/rh/config.py
@@ -74,8 +74,14 @@ class RawConfigParser(configparser.RawConfigParser):
return default
raise
- def items(self, section, default=_UNSET):
+ def items(self, section=_UNSET, default=_UNSET):
"""Return a list of (key, value) tuples for the options in |section|."""
+ if section is _UNSET:
+ # Python 3 compat logic. Return a dict of section-to-options.
+ if sys.version_info.major < 3:
+ return [(x, self.items(x)) for x in self.sections()]
+ return super(RawConfigParser, self).items()
+
try:
return configparser.RawConfigParser.items(self, section)
except configparser.NoSectionError:
@@ -83,6 +89,14 @@ class RawConfigParser(configparser.RawConfigParser):
return default
raise
+ if sys.version_info.major < 3:
+ def read_dict(self, dictionary):
+ """Store |dictionary| into ourselves."""
+ for section, settings in dictionary.items():
+ for option, value in settings:
+ if not self.has_section(section):
+ self.add_section(section)
+ self.set(section, option, value)
class PreUploadConfig(object):
"""Config file used for per-project `repo upload` hooks."""