MCPcopy Index your code
hub / github.com/python/cpython / next

Method next

Lib/tarfile.py:2842–2904  ·  view source on GitHub ↗

Return the next member of the archive as a TarInfo object, when TarFile is opened for reading. Return None if there is no more available.

(self)

Source from the content-addressed store, hash-verified

2840
2841 #--------------------------------------------------------------------------
2842 def next(self):
2843 """Return the next member of the archive as a TarInfo object, when
2844 TarFile is opened for reading. Return None if there is no more
2845 available.
2846 """
2847 self._check("ra")
2848 if self.firstmember is not None:
2849 m = self.firstmember
2850 self.firstmember = None
2851 return m
2852
2853 # Advance the file pointer.
2854 if self.offset != self.fileobj.tell():
2855 if self.offset == 0:
2856 return None
2857 self.fileobj.seek(self.offset - 1)
2858 if not self.fileobj.read(1):
2859 raise ReadError("unexpected end of data")
2860
2861 # Read the next block.
2862 tarinfo = None
2863 while True:
2864 try:
2865 tarinfo = self.tarinfo.fromtarfile(self)
2866 except EOFHeaderError as e:
2867 if self.ignore_zeros:
2868 self._dbg(2, "0x%X: %s" % (self.offset, e))
2869 self.offset += BLOCKSIZE
2870 continue
2871 except InvalidHeaderError as e:
2872 if self.ignore_zeros:
2873 self._dbg(2, "0x%X: %s" % (self.offset, e))
2874 self.offset += BLOCKSIZE
2875 continue
2876 elif self.offset == 0:
2877 raise ReadError(str(e)) from None
2878 except EmptyHeaderError:
2879 if self.offset == 0:
2880 raise ReadError("empty file") from None
2881 except TruncatedHeaderError as e:
2882 if self.offset == 0:
2883 raise ReadError(str(e)) from None
2884 except SubsequentHeaderError as e:
2885 raise ReadError(str(e)) from None
2886 except Exception as e:
2887 try:
2888 import zlib
2889 if isinstance(e, zlib.error):
2890 raise ReadError(f'zlib error: {e}') from None
2891 else:
2892 raise e
2893 except ImportError:
2894 raise e
2895 break
2896
2897 if tarinfo is not None:
2898 # if streaming the file we do not want to cache the tarinfo
2899 if not self.stream:

Callers 4

__init__Method · 0.95
_loadMethod · 0.95
__iter__Method · 0.95
testFunction · 0.45

Calls 9

_checkMethod · 0.95
_dbgMethod · 0.95
strFunction · 0.85
fromtarfileMethod · 0.80
ReadErrorClass · 0.70
tellMethod · 0.45
seekMethod · 0.45
readMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected