From 35f7975028eb57f76a34c5553f321fb0186c624a Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Sun, 2 Jun 2019 15:10:57 -0700 Subject: [PATCH] Add-on handler and update check/Python 3: file function -> with open function for reading from and writing to pickle files. Re #9038. --- source/addonHandler/__init__.py | 6 ++++-- source/updateCheck.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/addonHandler/__init__.py b/source/addonHandler/__init__.py index 7dd532acd0c..e9b3ebdea1e 100644 --- a/source/addonHandler/__init__.py +++ b/source/addonHandler/__init__.py @@ -47,7 +47,8 @@ def loadState(): global state statePath=os.path.join(globalVars.appArgs.configPath,stateFilename) try: - state = cPickle.load(file(statePath, "r")) + with open(statePath, "r") as f: + state = cPickle.load(f) if "disabledAddons" not in state: state["disabledAddons"] = set() if "pendingDisableSet" not in state: @@ -67,7 +68,8 @@ def loadState(): def saveState(): statePath=os.path.join(globalVars.appArgs.configPath,stateFilename) try: - cPickle.dump(state, file(statePath, "wb")) + with open(statePath, "wb") as f: + cPickle.dump(state, f) except: log.debugWarning("Error saving state", exc_info=True) diff --git a/source/updateCheck.py b/source/updateCheck.py index 3c36908c9e9..e27cedbbcc2 100644 --- a/source/updateCheck.py +++ b/source/updateCheck.py @@ -735,7 +735,8 @@ def onClose(self, evt): def saveState(): try: - cPickle.dump(state, file(_stateFilename, "wb")) + with open(_stateFilename, "wb") as f: + cPickle.dump(state, f) except: log.debugWarning("Error saving state", exc_info=True) @@ -743,7 +744,8 @@ def initialize(): global state, _stateFilename, autoChecker _stateFilename = os.path.join(globalVars.appArgs.configPath, "updateCheckState.pickle") try: - state = cPickle.load(file(_stateFilename, "r")) + with open(_stateFilename, "r") as f: + state = cPickle.load(f) except: log.debugWarning("Couldn't retrieve update state", exc_info=True) # Defaults.