|
15 | 15 | pass |
16 | 16 |
|
17 | 17 | # fix for datetime.strptime bug https://kodi.wiki/view/Python_Problems#datetime.strptime |
18 | | -class proxydt(datetime.datetime): |
| 18 | +def patch_strptime(date_string, format): |
| 19 | + return datetime.datetime(*(time.strptime(date_string, format)[:6])) |
19 | 20 |
|
20 | | - @classmethod |
21 | | - def strptime(cls, date_string, format): |
22 | | - return datetime.datetime(*(time.strptime(date_string, format)[:6])) |
23 | | - |
24 | | -datetime.datetime = proxydt |
25 | 21 |
|
26 | 22 | class QRCode(xbmcgui.WindowXMLDialog): |
27 | 23 | def __init__(self, *args, **kwargs): |
@@ -139,24 +135,21 @@ def getClient(self): |
139 | 135 |
|
140 | 136 | def _setToken(self, token): |
141 | 137 | # write the token files |
142 | | - token_file = open(xbmcvfs.translatePath(utils.data_dir() + self.TOKEN_FILE), 'w') |
143 | | - |
144 | | - token_file.write(json.dumps({"access_token": token.access_token, "refresh_token": token.refresh_token, "expiration": str(token.expires_at)})) |
145 | | - token_file.close() |
| 138 | + with open(xbmcvfs.translatePath(utils.data_dir() + self.TOKEN_FILE), 'w') as token_file: |
| 139 | + token_file.write(json.dumps({"access_token": token.access_token, "refresh_token": token.refresh_token, "expiration": str(token.expires_at)})) |
146 | 140 |
|
147 | 141 | def _getToken(self): |
148 | 142 | result = {} |
149 | 143 | # get token, if it exists |
150 | 144 | if(xbmcvfs.exists(xbmcvfs.translatePath(utils.data_dir() + self.TOKEN_FILE))): |
151 | | - token_file = open(xbmcvfs.translatePath(utils.data_dir() + self.TOKEN_FILE)) |
152 | | - token = token_file.read() |
| 145 | + token = "" |
| 146 | + with open(xbmcvfs.translatePath(utils.data_dir() + self.TOKEN_FILE), 'r') as token_file: |
| 147 | + token = token_file.read() |
153 | 148 |
|
154 | 149 | if(token.strip() != ""): |
155 | 150 | result = json.loads(token) |
156 | 151 | # convert expiration back to a datetime object |
157 | | - result['expiration'] = datetime.datetime.strptime(result['expiration'], "%Y-%m-%d %H:%M:%S.%f") |
158 | | - |
159 | | - token_file.close() |
| 152 | + result['expiration'] = patch_strptime(result['expiration'], "%Y-%m-%d %H:%M:%S.%f") |
160 | 153 |
|
161 | 154 | return result |
162 | 155 |
|
|
0 commit comments