@@ -111,19 +111,20 @@ def _get_body_filename_from_response(self, response: Response) -> str:
111111 return "body.txt"
112112
113113 def _get_body_filename_from_path (self , path : Path ) -> str :
114- if (path / "body.json" ).exists ():
115- return "body.json"
116-
117- if (path / "body.xml" ).exists ():
118- return "body.xml"
114+ candidates = []
115+ for p in path .iterdir ():
116+ if p .name .startswith ("body." ) and len (p .suffixes ) == 1 :
117+ candidates .append (p )
119118
120- if ( path / "body.arff" ). exists () :
121- return " body.arff"
119+ if not candidates :
120+ raise FileNotFoundError ( f"No body file found in path: { path } " )
122121
123- if (path / "body.zip" ).exists ():
124- return "body.zip"
122+ if len (candidates ) > 1 :
123+ raise FileNotFoundError (
124+ f"Multiple body files found in path: { path } ({ [p .name for p in candidates ]} )"
125+ )
125126
126- return "body.txt"
127+ return candidates [ 0 ]. name
127128
128129 def load (self , key : str ) -> Response :
129130 """
@@ -148,6 +149,9 @@ def load(self, key: str) -> Response:
148149 """
149150 path = self ._key_to_path (key )
150151
152+ if not path .exists ():
153+ raise FileNotFoundError (f"Cache path not found: { path } " )
154+
151155 meta_path = path / "meta.json"
152156 meta_raw = meta_path .read_bytes () if meta_path .exists () else "{}"
153157 meta = json .loads (meta_raw )
@@ -157,8 +161,6 @@ def load(self, key: str) -> Response:
157161 headers = json .loads (headers_raw )
158162
159163 body_path = path / self ._get_body_filename_from_path (path )
160- if not body_path .exists ():
161- raise FileNotFoundError (f"Incomplete cache at { body_path } " )
162164 body = body_path .read_bytes ()
163165
164166 response = Response ()
0 commit comments