From eefeef573d544be5dac3f665b10a4b757762e900 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Fri, 23 Sep 2016 12:36:05 +0700 Subject: [PATCH] fix a couple of python warnings (#3526) --- python/plugins/MetaSearch/util.py | 4 +++- python/pyplugin_installer/installer_data.py | 3 ++- python/utils.py | 5 ++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/python/plugins/MetaSearch/util.py b/python/plugins/MetaSearch/util.py index 627bd3d3ff3..9522e5165ff 100644 --- a/python/plugins/MetaSearch/util.py +++ b/python/plugins/MetaSearch/util.py @@ -35,6 +35,7 @@ import configparser from gettext import gettext, ngettext import logging import os +import codecs import webbrowser from xml.dom.minidom import parseString import xml.etree.ElementTree as etree @@ -61,7 +62,8 @@ class StaticContext(object): """init""" self.ppath = os.path.dirname(os.path.abspath(__file__)) self.metadata = configparser.ConfigParser() - self.metadata.readfp(open(os.path.join(self.ppath, 'metadata.txt'))) + with codecs.open(os.path.join(self.ppath, 'metadata.txt'), "r", "utf8") as f: + self.metadata.read_file(f) def get_ui_class(ui_file): diff --git a/python/pyplugin_installer/installer_data.py b/python/pyplugin_installer/installer_data.py index c7db0e7926a..af125dcb36a 100644 --- a/python/pyplugin_installer/installer_data.py +++ b/python/pyplugin_installer/installer_data.py @@ -580,7 +580,8 @@ class Plugins(QObject): global errorDetails cp = configparser.ConfigParser() try: - cp.read_file(codecs.open(metadataFile, "r", "utf8")) + with codecs.open(metadataFile, "r", "utf8") as f: + cp.read_file(f) return cp.get('general', fct) except Exception as e: if not errorDetails: diff --git a/python/utils.py b/python/utils.py index 24b8caa82db..e15cc752122 100644 --- a/python/utils.py +++ b/python/utils.py @@ -254,9 +254,8 @@ def findPlugins(path): cp = configparser.ConfigParser() try: - f = codecs.open(metadataFile, "r", "utf8") - cp.read_file(f) - f.close() + with codecs.open(metadataFile, "r", "utf8") as f: + cp.read_file(f) except: cp = None