From 6dce5f4f19b2096c6074fe78cfdd4c6305be8db6 Mon Sep 17 00:00:00 2001 From: jiansong Date: Wed, 11 Jan 2017 22:46:02 -0800 Subject: [PATCH] Handle readfp deprecation In py3.4 notice method readfp will removed in the future,so use method readfile to replace it.This warning is only in py3 and above.Py2,configparse do not have.Actually in py3,This function is finally pointed to the readfile function warnings.warn( "This method will be removed in future versions. " "Use 'parser.read_file()' instead.", DeprecationWarning, stacklevel=2 ) self.read_file(fp, source=filename) Change-Id: I22a2dca71008469a8c8b7afcc0934f3b4adcdae4 --- tools/trove-pylint.config | 8 +++++++- trove/common/stream_codecs.py | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/trove-pylint.config b/tools/trove-pylint.config index 06031e795d..9248f2f4de 100644 --- a/tools/trove-pylint.config +++ b/tools/trove-pylint.config @@ -405,6 +405,12 @@ "Instance of 'API' has no 'mongodb_add_shard_cluster' member", "MongoDbCluster.add_shard" ], + [ + "trove/common/stream_codecs.py", + "no-member", + "Instance of 'ConfigParser' has no 'read_file' member", + "IniCodec.deserialize" + ], [ "trove/common/utils.py", "E1127", @@ -1667,4 +1673,4 @@ "--rcfile=./pylintrc", "-E" ] -} \ No newline at end of file +} diff --git a/trove/common/stream_codecs.py b/trove/common/stream_codecs.py index 52fc3000aa..e6bb41b593 100644 --- a/trove/common/stream_codecs.py +++ b/trove/common/stream_codecs.py @@ -206,7 +206,10 @@ class IniCodec(StreamCodec): def deserialize(self, stream): parser = self._init_config_parser() - parser.readfp(self._pre_parse(stream)) + if sys.version_info >= (3, 2): + parser.read_file(self._pre_parse(stream)) + else: + parser.readfp(self._pre_parse(stream)) return {s: {k: StringConverter({None: self._default_value}).to_objects(v)