Skip to content

Commit

Permalink
Add-on handler and update check/Python 3: file function -> with open …
Browse files Browse the repository at this point in the history
…function for reading from and writing to pickle files. Re nvaccess#9038.
  • Loading branch information
josephsl committed Jun 4, 2019
1 parent a74796f commit 35f7975
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions source/addonHandler/__init__.py
Expand Up @@ -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:
Expand All @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions source/updateCheck.py
Expand Up @@ -735,15 +735,17 @@ 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)

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.
Expand Down

0 comments on commit 35f7975

Please sign in to comment.