Skip to content

Commit eefeef5

Browse files
nirvnm-kuhn
authored andcommitted
fix a couple of python warnings (#3526)
1 parent 9900036 commit eefeef5

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

python/plugins/MetaSearch/util.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from gettext import gettext, ngettext
3636
import logging
3737
import os
38+
import codecs
3839
import webbrowser
3940
from xml.dom.minidom import parseString
4041
import xml.etree.ElementTree as etree
@@ -61,7 +62,8 @@ def __init__(self):
6162
"""init"""
6263
self.ppath = os.path.dirname(os.path.abspath(__file__))
6364
self.metadata = configparser.ConfigParser()
64-
self.metadata.readfp(open(os.path.join(self.ppath, 'metadata.txt')))
65+
with codecs.open(os.path.join(self.ppath, 'metadata.txt'), "r", "utf8") as f:
66+
self.metadata.read_file(f)
6567

6668

6769
def get_ui_class(ui_file):

python/pyplugin_installer/installer_data.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ def metadataParser(fct):
580580
global errorDetails
581581
cp = configparser.ConfigParser()
582582
try:
583-
cp.read_file(codecs.open(metadataFile, "r", "utf8"))
583+
with codecs.open(metadataFile, "r", "utf8") as f:
584+
cp.read_file(f)
584585
return cp.get('general', fct)
585586
except Exception as e:
586587
if not errorDetails:

python/utils.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,8 @@ def findPlugins(path):
254254
cp = configparser.ConfigParser()
255255

256256
try:
257-
f = codecs.open(metadataFile, "r", "utf8")
258-
cp.read_file(f)
259-
f.close()
257+
with codecs.open(metadataFile, "r", "utf8") as f:
258+
cp.read_file(f)
260259
except:
261260
cp = None
262261

0 commit comments

Comments
 (0)