MCPcopy Index your code
hub / github.com/RustPython/RustPython / extractfile

Method extractfile

Lib/tarfile.py:2550–2580  ·  view source on GitHub ↗

Extract a member from the archive as a file object. 'member' may be a filename or a TarInfo object. If 'member' is a regular file or a link, an io.BufferedReader object is returned. For all other existing members, None is returned. If 'member' does not appear

(self, member)

Source from the content-addressed store, hash-verified

2548 self._dbg(1, "tarfile: %s %s" % (type(e).__name__, e))
2549
2550 def extractfile(self, member):
2551 """Extract a member from the archive as a file object. 'member' may be
2552 a filename or a TarInfo object. If 'member' is a regular file or
2553 a link, an io.BufferedReader object is returned. For all other
2554 existing members, None is returned. If 'member' does not appear
2555 in the archive, KeyError is raised.
2556 """
2557 self._check("r")
2558
2559 if isinstance(member, str):
2560 tarinfo = self.getmember(member)
2561 else:
2562 tarinfo = member
2563
2564 if tarinfo.isreg() or tarinfo.type not in SUPPORTED_TYPES:
2565 # Members with unknown types are treated as regular files.
2566 return self.fileobject(self, tarinfo)
2567
2568 elif tarinfo.islnk() or tarinfo.issym():
2569 if isinstance(self.fileobj, _Stream):
2570 # A small but ugly workaround for the case that someone tries
2571 # to extract a (sym)link as a file-object from a non-seekable
2572 # stream of tar blocks.
2573 raise StreamError("cannot extract (sym)link as file object")
2574 else:
2575 # A (sym)link's file object is its target's file object.
2576 return self.extractfile(self._find_link_target(tarinfo))
2577 else:
2578 # If there's no data associated with the member (directory, chrdev,
2579 # blkdev, etc.), return None instead of a file object.
2580 return None
2581
2582 def _extract_member(self, tarinfo, targetpath, set_attrs=True,
2583 numeric_owner=False, *, filter_function=None,

Callers 15

test_fileobj_iterMethod · 0.80
test_fileobj_seekMethod · 0.80
test_fileobj_textMethod · 0.80
_test_fileobj_linkMethod · 0.80
test_read_throughMethod · 0.80

Calls 8

_checkMethod · 0.95
getmemberMethod · 0.95
_find_link_targetMethod · 0.95
isinstanceFunction · 0.85
StreamErrorClass · 0.85
isregMethod · 0.80
islnkMethod · 0.80
issymMethod · 0.80

Tested by 15

test_fileobj_iterMethod · 0.64
test_fileobj_seekMethod · 0.64
test_fileobj_textMethod · 0.64
_test_fileobj_linkMethod · 0.64
test_read_throughMethod · 0.64