MCPcopy Create free account
hub / github.com/apache/arrow / FSSpecHandler

Class FSSpecHandler

python/pyarrow/fs.py:265–428  ·  view source on GitHub ↗

Handler for fsspec-based Python filesystems. https://filesystem-spec.readthedocs.io/en/latest/index.html Parameters ---------- fs : FSSpec-compliant filesystem instance Examples -------- >>> PyFileSystem(FSSpecHandler(fsspec_fs)) # doctest: +SKIP

Source from the content-addressed store, hash-verified

263
264
265class FSSpecHandler(FileSystemHandler):
266 """
267 Handler for fsspec-based Python filesystems.
268
269 https://filesystem-spec.readthedocs.io/en/latest/index.html
270
271 Parameters
272 ----------
273 fs : FSSpec-compliant filesystem instance
274
275 Examples
276 --------
277 >>> PyFileSystem(FSSpecHandler(fsspec_fs)) # doctest: +SKIP
278 """
279
280 def __init__(self, fs):
281 self.fs = fs
282
283 def __eq__(self, other):
284 if isinstance(other, FSSpecHandler):
285 return self.fs == other.fs
286 return NotImplemented
287
288 def __ne__(self, other):
289 if isinstance(other, FSSpecHandler):
290 return self.fs != other.fs
291 return NotImplemented
292
293 def get_type_name(self):
294 protocol = self.fs.protocol
295 if isinstance(protocol, list):
296 protocol = protocol[0]
297 return f"fsspec+{protocol}"
298
299 def normalize_path(self, path):
300 return path
301
302 @staticmethod
303 def _create_file_info(path, info):
304 size = info["size"]
305 if info["type"] == "file":
306 ftype = FileType.File
307 elif info["type"] == "directory":
308 ftype = FileType.Directory
309 # some fsspec filesystems include a file size for directories
310 size = None
311 else:
312 ftype = FileType.Unknown
313 return FileInfo(path, ftype, size=size, mtime=info.get("mtime", None))
314
315 def get_file_info(self, paths):
316 infos = []
317 for path in paths:
318 try:
319 info = self.fs.info(path)
320 except FileNotFoundError:
321 infos.append(FileInfo(path, FileType.NotFound))
322 else:

Calls

no outgoing calls