mirror of
https://github.com/robweber/xbmcbackup.git
synced 2026-04-08 11:28:12 +02:00
use with syntax for file IO
This commit is contained in:
@@ -135,16 +135,15 @@ class DropboxAuthorizer:
|
|||||||
|
|
||||||
def _setToken(self, token):
|
def _setToken(self, token):
|
||||||
# write the token files
|
# 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.write(json.dumps({"access_token": token.access_token, "refresh_token": token.refresh_token, "expiration": str(token.expires_at)}))
|
||||||
token_file.close()
|
|
||||||
|
|
||||||
def _getToken(self):
|
def _getToken(self):
|
||||||
result = {}
|
result = {}
|
||||||
# get token, if it exists
|
# get token, if it exists
|
||||||
if(xbmcvfs.exists(xbmcvfs.translatePath(utils.data_dir() + self.TOKEN_FILE))):
|
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()
|
token = token_file.read()
|
||||||
|
|
||||||
if(token.strip() != ""):
|
if(token.strip() != ""):
|
||||||
@@ -152,8 +151,6 @@ class DropboxAuthorizer:
|
|||||||
# convert expiration back to a datetime object
|
# convert expiration back to a datetime object
|
||||||
result['expiration'] = patch_strptime(result['expiration'], "%Y-%m-%d %H:%M:%S.%f")
|
result['expiration'] = patch_strptime(result['expiration'], "%Y-%m-%d %H:%M:%S.%f")
|
||||||
|
|
||||||
token_file.close()
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _deleteToken(self):
|
def _deleteToken(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user