Skip to content

Commit c54c4cf

Browse files
committed
fix some issues in the backup handler
1 parent f166f4c commit c54c4cf

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/pyff/resource.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
from __future__ import annotations
77

8+
import logging
89
import os
910
from collections import deque
1011
from copy import deepcopy
@@ -118,7 +119,7 @@ def i_handle(self, t, url=None, response=None, exception=None, last_fetched=None
118119
else:
119120
self.icon_store.update(url, None, info=dict(exception=exception))
120121
except BaseException as ex:
121-
log.warning(ex)
122+
log.error(ex)
122123

123124

124125
class ResourceHandler(URLHandler):
@@ -136,14 +137,14 @@ def i_handle(self, t, url=None, response=None, exception=None, last_fetched=None
136137
children = t.parse(lambda u: response)
137138
self.i_schedule(children)
138139
except BaseException as ex:
139-
log.warning(ex)
140+
log.error(ex)
140141
t.info['Exception'] = ex
141142

142143

143144
class Resource(Watchable):
144145
def __init__(self, url=None, **kwargs):
145146
super().__init__()
146-
self.url = url
147+
self.url: str = url
147148
self.opts = kwargs
148149
self.t = None
149150
self.type = "text/plain"
@@ -184,7 +185,7 @@ def __setstate__(self, state):
184185

185186
@property
186187
def local_copy_fn(self):
187-
return os.path.join(config.local_copy_dir, urlescape(self.url, True))
188+
return os.path.join(config.local_copy_dir, urlescape(self.url))
188189

189190
@property
190191
def post(self):
@@ -300,9 +301,6 @@ def load_backup(self):
300301
if config.local_copy_dir is None:
301302
return None
302303

303-
log.warning(
304-
"Got status={:d} while getting {}. Attempting fallback to local copy.".format(r.status_code, self.url)
305-
)
306304
try:
307305
return resource_string(self.local_copy_fn)
308306
except IOError as ex:
@@ -343,6 +341,11 @@ def load_resource(self, getter: Callable[[str], Response]) -> Tuple[Optional[str
343341
data = r.text
344342
self.etag = r.headers.get('ETag', None) or hex_digest(r.text, 'sha256')
345343
elif self.local_copy_fn is not None:
344+
log.warning(
345+
"Got status={:d} while getting {}. Attempting fallback to local copy.".format(
346+
r.status_code, self.url
347+
)
348+
)
346349
data = self.load_backup()
347350
if data is not None and len(data) > 0:
348351
info['Reason'] = "Retrieved from local cache because status: {} != 200".format(status)

0 commit comments

Comments
 (0)