use with syntax for file IO

This commit is contained in:
Rob Weber
2026-04-01 08:16:23 -05:00
parent 71285a7c7e
commit cdd8faf990

View File

@@ -135,16 +135,15 @@ class DropboxAuthorizer:
def _setToken(self, token):
# write the token files
token_file = open(xbmcvfs.translatePath(utils.data_dir() + self.TOKEN_FILE), 'w')
with open(xbmcvfs.translatePath(utils.data_dir() + self.TOKEN_FILE), 'w') as token_file:
token_file.write(json.dumps({"access_token": token.access_token, "refresh_token": token.refresh_token, "expiration": str(token.expires_at)}))
token_file.close()
def _getToken(self):
result = {}
# get token, if it exists
if(xbmcvfs.exists(xbmcvfs.translatePath(utils.data_dir() + self.TOKEN_FILE))):
token_file = open(xbmcvfs.translatePath(utils.data_dir() + self.TOKEN_FILE))
token = ""
with open(xbmcvfs.translatePath(utils.data_dir() + self.TOKEN_FILE), 'r') as token_file:
token = token_file.read()
if(token.strip() != ""):
@@ -152,8 +151,6 @@ class DropboxAuthorizer:
# convert expiration back to a datetime object
result['expiration'] = patch_strptime(result['expiration'], "%Y-%m-%d %H:%M:%S.%f")
token_file.close()
return result
def _deleteToken(self):