{
  "format": "promptkb-evidence-brief",
  "version": 2,
  "title": "Tar extraction: Python 3.12 documentation review",
  "question": "For an application maintainer, what does the documented release say about tar extraction defaults, cleanup after a refusal, and the remaining security limits? Keep documented behavior separate from actual runtime observations; do not imply that a filter makes arbitrary uploads safe.",
  "sources": [
    {
      "id": "S1",
      "title": "CPython 3.14.0 tarfile documentation (raw RST)",
      "locator": "https://raw.githubusercontent.com/python/cpython/ebf955df7a89ed0c7968f79faec1de49f61ed7cb/Doc/library/tarfile.rst",
      "text": ":mod:`!tarfile` --- Read and write tar archive files\n====================================================\n\n.. module:: tarfile\n   :synopsis: Read and write tar-format archive files.\n\n.. moduleauthor:: Lars Gustäbel <lars@gustaebel.de>\n.. sectionauthor:: Lars Gustäbel <lars@gustaebel.de>\n\n**Source code:** :source:`Lib/tarfile.py`\n\n--------------\n\nThe :mod:`tarfile` module makes it possible to read and write tar\narchives, including those using gzip, bz2 and lzma compression.\nUse the :mod:`zipfile` module to read or write :file:`.zip` files, or the\nhigher-level functions in :ref:`shutil <archiving-operations>`.\n\nSome facts and figures:\n\n* reads and writes :mod:`gzip`, :mod:`bz2`, :mod:`compression.zstd`, and\n  :mod:`lzma` compressed archives if the respective modules are available.\n\n* read/write support for the POSIX.1-1988 (ustar) format.\n\n* read/write support for the GNU tar format including *longname* and *longlink*\n  extensions, read-only support for all variants of the *sparse* extension\n  including restoration of sparse files.\n\n* read/write support for the POSIX.1-2001 (pax) format.\n\n* handles directories, regular files, hardlinks, symbolic links, fifos,\n  character devices and block devices and is able to acquire and restore file\n  information like timestamp, access permissions and owner.\n\n.. versionchanged:: 3.3\n   Added support for :mod:`lzma` compression.\n\n.. versionchanged:: 3.12\n   Archives are extracted using a :ref:`filter <tarfile-extraction-filter>`,\n   which makes it possible to either limit surprising/dangerous features,\n   or to acknowledge that they are expected and the archive is fully trusted.\n\n.. versionchanged:: 3.14\n   Set the default extraction filter to :func:`data <data_filter>`,\n   which disallows some dangerous features such as links to absolute paths\n   or paths outside of the destination. Previously, the filter strategy\n   was equivalent to :func:`fully_trusted <fully_trusted_filter>`.\n\n.. versionchanged:: 3.14\n\n   Added support for Zstandard compression using :mod:`compression.zstd`.\n\n.. function:: open(name=None, mode='r', fileobj=None, bufsize=10240, **kwargs)\n\n   Return a :class:`TarFile` object for the pathname *name*. For detailed\n   information on :class:`TarFile` objects and the keyword arguments that are\n   allowed, see :ref:`tarfile-objects`.\n\n   *mode* has to be a string of the form ``'filemode[:compression]'``, it defaults\n   to ``'r'``. Here is a full list of mode combinations:\n\n   +------------------+---------------------------------------------+\n   | mode             | action                                      |\n   +==================+=============================================+\n   | ``'r'`` or       | Open for reading with transparent           |\n   | ``'r:*'``        | compression (recommended).                  |\n   +------------------+---------------------------------------------+\n   | ``'r:'``         | Open for reading exclusively without        |\n   |                  | compression.                                |\n   +------------------+---------------------------------------------+\n   | ``'r:gz'``       | Open for reading with gzip compression.     |\n   +------------------+---------------------------------------------+\n   | ``'r:bz2'``      | Open for reading with bzip2 compression.    |\n   +------------------+---------------------------------------------+\n   | ``'r:xz'``       | Open for reading with lzma compression.     |\n   +------------------+---------------------------------------------+\n   | ``'r:zst'``      | Open for reading with Zstandard compression.|\n   +------------------+---------------------------------------------+\n   | ``'x'`` or       | Create a tarfile exclusively without        |\n   | ``'x:'``         | compression.                                |\n   |                  | Raise a :exc:`FileExistsError` exception    |\n   |                  | if it already exists.                       |\n   +------------------+---------------------------------------------+\n   | ``'x:gz'``       | Create a tarfile with gzip compression.     |\n   |                  | Raise a :exc:`FileExistsError` exception    |\n   |                  | if it already exists.                       |\n   +------------------+---------------------------------------------+\n   | ``'x:bz2'``      | Create a tarfile with bzip2 compression.    |\n   |                  | Raise a :exc:`FileExistsError` exception    |\n   |                  | if it already exists.                       |\n   +------------------+---------------------------------------------+\n   | ``'x:xz'``       | Create a tarfile with lzma compression.     |\n   |                  | Raise a :exc:`FileExistsError` exception    |\n   |                  | if it already exists.                       |\n   +------------------+---------------------------------------------+\n   | ``'x:zst'``      | Create a tarfile with Zstandard compression.|\n   |                  | Raise a :exc:`FileExistsError` exception    |\n   |                  | if it already exists.                       |\n   +------------------+---------------------------------------------+\n   | ``'a'`` or       | Open for appending with no compression. The |\n   | ``'a:'``         | file is created if it does not exist.       |\n   +------------------+---------------------------------------------+\n   | ``'w'`` or       | Open for uncompressed writing.              |\n   | ``'w:'``         |                                             |\n   +------------------+---------------------------------------------+\n   | ``'w:gz'``       | Open for gzip compressed writing.           |\n   +------------------+---------------------------------------------+\n   | ``'w:bz2'``      | Open for bzip2 compressed writing.          |\n   +------------------+---------------------------------------------+\n   | ``'w:xz'``       | Open for lzma compressed writing.           |\n   +------------------+---------------------------------------------+\n   | ``'w:zst'``      | Open for Zstandard compressed writing.      |\n   +------------------+---------------------------------------------+\n\n   Note that ``'a:gz'``, ``'a:bz2'`` or ``'a:xz'`` is not possible. If *mode*\n   is not suitable to open a certain (compressed) file for reading,\n   :exc:`ReadError` is raised. Use *mode* ``'r'`` to avoid this.  If a\n   compression method is not supported, :exc:`CompressionError` is raised.\n\n   If *fileobj* is specified, it is used as an alternative to a :term:`file object`\n   opened in binary mode for *name*. It is supposed to be at position 0.\n\n   For modes ``'w:gz'``, ``'x:gz'``, ``'w|gz'``, ``'w:bz2'``, ``'x:bz2'``,\n   ``'w|bz2'``, :func:`tarfile.open` accepts the keyword argument\n   *compresslevel* (default ``9``) to specify the compression level of the file.\n\n   For modes ``'w:xz'``, ``'x:xz'`` and ``'w|xz'``, :func:`tarfile.open` accepts the\n   keyword argument *preset* to specify the compression level of the file.\n\n   For modes ``'w:zst'``, ``'x:zst'`` and ``'w|zst'``, :func:`tarfile.open`\n   accepts the keyword argument *level* to specify the compression level of\n   the file. The keyword argument *options* may also be passed, providing\n   advanced Zstandard compression parameters described by\n   :class:`~compression.zstd.CompressionParameter`. The keyword argument\n   *zstd_dict* can be passed to provide a :class:`~compression.zstd.ZstdDict`,\n   a Zstandard dictionary used to improve compression of smaller amounts of\n   data.\n\n   For special purposes, there is a second format for *mode*:\n   ``'filemode|[compression]'``.  :func:`tarfile.open` will return a :class:`TarFile`\n   object that processes its data as a stream of blocks.  No random seeking will\n   be done on the file. If given, *fileobj* may be any object that has a\n   :meth:`~io.RawIOBase.read` or :meth:`~io.RawIOBase.write` method\n   (depending on the *mode*) that works with bytes.\n   *bufsize* specifies the blocksize and defaults to ``20 * 512`` bytes.\n   Use this variant in combination with e.g. ``sys.stdin.buffer``, a socket\n   :term:`file object` or a tape device.\n   However, such a :class:`TarFile` object is limited in that it does\n   not allow random access, see :ref:`tar-examples`.  The currently\n   possible modes:\n\n   +-------------+--------------------------------------------+\n   | Mode        | Action                                     |\n   +=============+============================================+\n   | ``'r|*'``   | Open a *stream* of tar blocks for reading  |\n   |             | with transparent compression.              |\n   +-------------+--------------------------------------------+\n   | ``'r|'``    | Open a *stream* of uncompressed tar blocks |\n   |             | for reading.                               |\n   +-------------+--------------------------------------------+\n   | ``'r|gz'``  | Open a gzip compressed *stream* for        |\n   |             | reading.                                   |\n   +-------------+--------------------------------------------+\n   | ``'r|bz2'`` | Open a bzip2 compressed *stream* for       |\n   |             | reading.                                   |\n   +-------------+--------------------------------------------+\n   | ``'r|xz'``  | Open an lzma compressed *stream* for       |\n   |             | reading.                                   |\n   +-------------+--------------------------------------------+\n   | ``'r|zst'`` | Open a Zstandard compressed *stream* for   |\n   |             | reading.                                   |\n   +-------------+--------------------------------------------+\n   | ``'w|'``    | Open an uncompressed *stream* for writing. |\n   +-------------+--------------------------------------------+\n   | ``'w|gz'``  | Open a gzip compressed *stream* for        |\n   |             | writing.                                   |\n   +-------------+--------------------------------------------+\n   | ``'w|bz2'`` | Open a bzip2 compressed *stream* for       |\n   |             | writing.                                   |\n   +-------------+--------------------------------------------+\n   | ``'w|xz'``  | Open an lzma compressed *stream* for       |\n   |             | writing.                                   |\n   +-------------+--------------------------------------------+\n   | ``'w|zst'`` | Open a Zstandard compressed *stream* for   |\n   |             | writing.                                   |\n   +-------------+--------------------------------------------+\n\n   .. versionchanged:: 3.5\n      The ``'x'`` (exclusive creation) mode was added.\n\n   .. versionchanged:: 3.6\n      The *name* parameter accepts a :term:`path-like object`.\n\n   .. versionchanged:: 3.12\n      The *compresslevel* keyword argument also works for streams.\n\n   .. versionchanged:: 3.14\n      The *preset* keyword argument also works for streams.\n\n\n.. class:: TarFile\n   :noindex:\n\n   Class for reading and writing tar archives. Do not use this class directly:\n   use :func:`tarfile.open` instead. See :ref:`tarfile-objects`.\n\n\n.. function:: is_tarfile(name)\n\n   Return :const:`True` if *name* is a tar archive file, that the :mod:`tarfile`\n   module can read. *name* may be a :class:`str`, file, or file-like object.\n\n   .. versionchanged:: 3.9\n      Support for file and file-like objects.\n\n\nThe :mod:`tarfile` module defines the following exceptions:\n\n\n.. exception:: TarError\n\n   Base class for all :mod:`tarfile` exceptions.\n\n\n.. exception:: ReadError\n\n   Is raised when a tar archive is opened, that either cannot be handled by the\n   :mod:`tarfile` module or is somehow invalid.\n\n\n.. exception:: CompressionError\n\n   Is raised when a compression method is not supported or when the data cannot be\n   decoded properly.\n\n\n.. exception:: StreamError\n\n   Is raised for the limitations that are typical for stream-like :class:`TarFile`\n   objects.\n\n\n.. exception:: ExtractError\n\n   Is raised for *non-fatal* errors when using :meth:`TarFile.extract`, but only if\n   :attr:`TarFile.errorlevel`\\ ``== 2``.\n\n\n.. exception:: HeaderError\n\n   Is raised by :meth:`TarInfo.frombuf` if the buffer it gets is invalid.\n\n\n.. exception:: FilterError\n\n   Base class for members :ref:`refused <tarfile-extraction-refuse>` by\n   filters.\n\n   .. attribute:: tarinfo\n\n      Information about the member that the filter refused to extract,\n      as :ref:`TarInfo <tarinfo-objects>`.\n\n.. exception:: AbsolutePathError\n\n   Raised to refuse extracting a member with an absolute path.\n\n.. exception:: OutsideDestinationError\n\n   Raised to refuse extracting a member outside the destination directory.\n\n.. exception:: SpecialFileError\n\n   Raised to refuse extracting a special file (e.g. a device or pipe).\n\n.. exception:: AbsoluteLinkError\n\n   Raised to refuse extracting a symbolic link with an absolute path.\n\n.. exception:: LinkOutsideDestinationError\n\n   Raised to refuse extracting a symbolic link pointing outside the destination\n   directory.\n\n.. exception:: LinkFallbackError\n\n   Raised to refuse emulating a link (hard or symbolic) by extracting another\n   archive member, when that member would be rejected by the filter location.\n   The exception that was raised to reject the replacement member is available\n   as :attr:`!BaseException.__context__`.\n\n   .. versionadded:: 3.14\n\n\nThe following constants are available at the module level:\n\n.. data:: ENCODING\n\n   The default character encoding: ``'utf-8'`` on Windows, the value returned by\n   :func:`sys.getfilesystemencoding` otherwise.\n\n.. data:: REGTYPE\n          AREGTYPE\n\n   A regular file :attr:`~TarInfo.type`.\n\n.. data:: LNKTYPE\n\n   A link (inside tarfile) :attr:`~TarInfo.type`.\n\n.. data:: SYMTYPE\n\n   A symbolic link :attr:`~TarInfo.type`.\n\n.. data:: CHRTYPE\n\n   A character special device :attr:`~TarInfo.type`.\n\n.. data:: BLKTYPE\n\n   A block special device :attr:`~TarInfo.type`.\n\n.. data:: DIRTYPE\n\n   A directory :attr:`~TarInfo.type`.\n\n.. data:: FIFOTYPE\n\n   A FIFO special device :attr:`~TarInfo.type`.\n\n.. data:: CONTTYPE\n\n   A contiguous file :attr:`~TarInfo.type`.\n\n.. data:: GNUTYPE_LONGNAME\n\n   A GNU tar longname :attr:`~TarInfo.type`.\n\n.. data:: GNUTYPE_LONGLINK\n\n   A GNU tar longlink :attr:`~TarInfo.type`.\n\n.. data:: GNUTYPE_SPARSE\n\n   A GNU tar sparse file :attr:`~TarInfo.type`.\n\n\nEach of the following constants defines a tar archive format that the\n:mod:`tarfile` module is able to create. See section :ref:`tar-formats` for\ndetails.\n\n\n.. data:: USTAR_FORMAT\n\n   POSIX.1-1988 (ustar) format.\n\n\n.. data:: GNU_FORMAT\n\n   GNU tar format.\n\n\n.. data:: PAX_FORMAT\n\n   POSIX.1-2001 (pax) format.\n\n\n.. data:: DEFAULT_FORMAT\n\n   The default format for creating archives. This is currently :const:`PAX_FORMAT`.\n\n   .. versionchanged:: 3.8\n      The default format for new archives was changed to\n      :const:`PAX_FORMAT` from :const:`GNU_FORMAT`.\n\n\n.. seealso::\n\n   Module :mod:`zipfile`\n      Documentation of the :mod:`zipfile` standard module.\n\n   :ref:`archiving-operations`\n      Documentation of the higher-level archiving facilities provided by the\n      standard :mod:`shutil` module.\n\n   `GNU tar manual, Basic Tar Format <https://www.gnu.org/software/tar/manual/html_node/Standard.html>`_\n      Documentation for tar archive files, including GNU tar extensions.\n\n\n.. _tarfile-objects:\n\nTarFile Objects\n---------------\n\nThe :class:`TarFile` object provides an interface to a tar archive. A tar\narchive is a sequence of blocks. An archive member (a stored file) is made up of\na header block followed by data blocks. It is possible to store a file in a tar\narchive several times. Each archive member is represented by a :class:`TarInfo`\nobject, see :ref:`tarinfo-objects` for details.\n\nA :class:`TarFile` object can be used as a context manager in a :keyword:`with`\nstatement. It will automatically be closed when the block is completed. Please\nnote that in the event of an exception an archive opened for writing will not\nbe finalized; only the internally used file object will be closed. See the\n:ref:`tar-examples` section for a use case.\n\n.. versionadded:: 3.2\n   Added support for the context management protocol.\n\n.. class:: TarFile(name=None, mode='r', fileobj=None, format=DEFAULT_FORMAT, tarinfo=TarInfo, dereference=False, ignore_zeros=False, encoding=ENCODING, errors='surrogateescape', pax_headers=None, debug=0, errorlevel=1, stream=False)\n\n   All following arguments are optional and can be accessed as instance attributes\n   as well.\n\n   *name* is the pathname of the archive. *name* may be a :term:`path-like object`.\n   It can be omitted if *fileobj* is given.\n   In this case, the file object's :attr:`!name` attribute is used if it exists.\n\n   *mode* is either ``'r'`` to read from an existing archive, ``'a'`` to append\n   data to an existing file, ``'w'`` to create a new file overwriting an existing\n   one, or ``'x'`` to create a new file only if it does not already exist.\n\n   If *fileobj* is given, it is used for reading or writing data. If it can be\n   determined, *mode* is overridden by *fileobj*'s mode. *fileobj* will be used\n   from position 0.\n\n   .. note::\n\n      *fileobj* is not closed, when :class:`TarFile` is closed.\n\n   *format* controls the archive format for writing. It must be one of the constants\n   :const:`USTAR_FORMAT`, :const:`GNU_FORMAT` or :const:`PAX_FORMAT` that are\n   defined at module level. When reading, format will be automatically detected, even\n   if different formats are present in a single archive.\n\n   The *tarinfo* argument can be used to replace the default :class:`TarInfo` class\n   with a different one.\n\n   If *dereference* is :const:`False`, add symbolic and hard links to the archive. If it\n   is :const:`True`, add the content of the target files to the archive. This has no\n   effect on systems that do not support symbolic links.\n\n   If *ignore_zeros* is :const:`False`, treat an empty block as the end of the archive.\n   If it is :const:`True`, skip empty (and invalid) blocks and try to get as many members\n   as possible. This is only useful for reading concatenated or damaged archives.\n\n   *debug* can be set from ``0`` (no debug messages) up to ``3`` (all debug\n   messages). The messages are written to ``sys.stderr``.\n\n   *errorlevel* controls how extraction errors are handled,\n   see :attr:`the corresponding attribute <TarFile.errorlevel>`.\n\n   The *encoding* and *errors* arguments define the character encoding to be\n   used for reading or writing the archive and how conversion errors are going\n   to be handled. The default settings will work for most users.\n   See section :ref:`tar-unicode` for in-depth information.\n\n   The *pax_headers* argument is an optional dictionary of strings which\n   will be added as a pax global header if *format* is :const:`PAX_FORMAT`.\n\n   If *stream* is set to :const:`True` then while reading the archive info about files\n   in the archive are not cached, saving memory.\n\n   .. versionchanged:: 3.2\n      Use ``'surrogateescape'`` as the default for the *errors* argument.\n\n   .. versionchanged:: 3.5\n      The ``'x'`` (exclusive creation) mode was added.\n\n   .. versionchanged:: 3.6\n      The *name* parameter accepts a :term:`path-like object`.\n\n   .. versionchanged:: 3.13\n      Add the *stream* parameter.\n\n.. classmethod:: TarFile.open(...)\n\n   Alternative constructor. The :func:`tarfile.open` function is actually a\n   shortcut to this classmethod.\n\n\n.. method:: TarFile.getmember(name)\n\n   Return a :class:`TarInfo` object for member *name*. If *name* can not be found\n   in the archive, :exc:`KeyError` is raised.\n\n   .. note::\n\n      If a member occurs more than once in the archive, its last occurrence is assumed\n      to be the most up-to-date version.\n\n\n.. method:: TarFile.getmembers()\n\n   Return the members of the archive as a list of :class:`TarInfo` objects. The\n   list has the same order as the members in the archive.\n\n\n.. method:: TarFile.getnames()\n\n   Return the members as a list of their names. It has the same order as the list\n   returned by :meth:`getmembers`.\n\n\n.. method:: TarFile.list(verbose=True, *, members=None)\n\n   Print a table of contents to ``sys.stdout``. If *verbose* is :const:`False`,\n   only the names of the members are printed. If it is :const:`True`, output\n   similar to that of :program:`ls -l` is produced. If optional *members* is\n   given, it must be a subset of the list returned by :meth:`getmembers`.\n\n   .. versionchanged:: 3.5\n      Added the *members* parameter.\n\n\n.. method:: TarFile.next()\n\n   Return the next member of the archive as a :class:`TarInfo` object, when\n   :class:`TarFile` is opened for reading. Return :const:`None` if there is no more\n   available.\n\n\n.. method:: TarFile.extractall(path=\".\", members=None, *, numeric_owner=False, filter=None)\n\n   Extract all members from the archive to the current working directory or\n   directory *path*. If optional *members* is given, it must be a subset of the\n   list returned by :meth:`getmembers`. Directory information like owner,\n   modification time and permissions are set after all members have been extracted.\n   This is done to work around two problems: A directory's modification time is\n   reset each time a file is created in it. And, if a directory's permissions do\n   not allow writing, extracting files to it will fail.\n\n   If *numeric_owner* is :const:`True`, the uid and gid numbers from the tarfile\n   are used to set the owner/group for the extracted files. Otherwise, the named\n   values from the tarfile are used.\n\n   The *filter* argument specifies how ``members`` are modified or rejected\n   before extraction.\n   See :ref:`tarfile-extraction-filter` for details.\n   It is recommended to set this explicitly only if specific *tar* features\n   are required, or as ``filter='data'`` to support Python versions with a less\n   secure default (3.13 and lower).\n\n   .. warning::\n\n      Never extract archives from untrusted sources without prior inspection.\n\n      Since Python 3.14, the default (:func:`data <data_filter>`) will prevent\n      the most dangerous security issues.\n      However, it will not prevent *all* unintended or insecure behavior.\n      Read the :ref:`tarfile-extraction-filter` section for details.\n\n   .. versionchanged:: 3.5\n      Added the *numeric_owner* parameter.\n\n   .. versionchanged:: 3.6\n      The *path* parameter accepts a :term:`path-like object`.\n\n   .. versionchanged:: 3.12\n      Added the *filter* parameter.\n\n   .. versionchanged:: 3.14\n      The *filter* parameter now defaults to ``'data'``.\n\n\n.. method:: TarFile.extract(member, path=\"\", set_attrs=True, *, numeric_owner=False, filter=None)\n\n   Extract a member from the archive to the current working directory, using its\n   full name. Its file information is extracted as accurately as possible. *member*\n   may be a filename or a :class:`TarInfo` object. You can specify a different\n   directory using *path*. *path* may be a :term:`path-like object`.\n   File attributes (owner, mtime, mode) are set unless *set_attrs* is false.\n\n   The *numeric_owner* and *filter* arguments are the same as\n   for :meth:`extractall`.\n\n   .. note::\n\n      The :meth:`extract` method does not take care of several extraction issues.\n      In most cases you should consider using the :meth:`extractall` method.\n\n   .. warning::\n\n      Never extract archives from untrusted sources without prior inspection.\n      See the warning for :meth:`extractall` for details.\n\n   .. versionchanged:: 3.2\n      Added the *set_attrs* parameter.\n\n   .. versionchanged:: 3.5\n      Added the *numeric_owner* parameter.\n\n   .. versionchanged:: 3.6\n      The *path* parameter accepts a :term:`path-like object`.\n\n   .. versionchanged:: 3.12\n      Added the *filter* parameter.\n\n\n.. method:: TarFile.extractfile(member)\n\n   Extract a member from the archive as a file object. *member* may be\n   a filename or a :class:`TarInfo` object. If *member* is a regular file or\n   a link, an :class:`io.BufferedReader` object is returned. For all other\n   existing members, :const:`None` is returned. If *member* does not appear\n   in the archive, :exc:`KeyError` is raised.\n\n   .. versionchanged:: 3.3\n      Return an :class:`io.BufferedReader` object.\n\n   .. versionchanged:: 3.13\n      The returned :class:`io.BufferedReader` object has the :attr:`!mode`\n      attribute which is always equal to ``'rb'``.\n\n.. attribute:: TarFile.errorlevel\n   :type: int\n\n   If *errorlevel* is ``0``, errors are ignored when using :meth:`TarFile.extract`\n   and :meth:`TarFile.extractall`.\n   Nevertheless, they appear as error messages in the debug output when\n   *debug* is greater than 0.\n   If ``1`` (the default), all *fatal* errors are raised as :exc:`OSError` or\n   :exc:`FilterError` exceptions. If ``2``, all *non-fatal* errors are raised\n   as :exc:`TarError` exceptions as well.\n\n   Some exceptions, e.g. ones caused by wrong argument types or data\n   corruption, are always raised.\n\n   Custom :ref:`extraction filters <tarfile-extraction-filter>`\n   should raise :exc:`FilterError` for *fatal* errors\n   and :exc:`ExtractError` for *non-fatal* ones.\n\n   Note that when an exception is raised, the archive may be partially\n   extracted. It is the user’s responsibility to clean up.\n\n.. attribute:: TarFile.extraction_filter\n\n   .. versionadded:: 3.12\n\n   The :ref:`extraction filter <tarfile-extraction-filter>` used\n   as a default for the *filter* argument of :meth:`~TarFile.extract`\n   and :meth:`~TarFile.extractall`.\n\n   The attribute may be ``None`` or a callable.\n   String names are not allowed for this attribute, unlike the *filter*\n   argument to :meth:`~TarFile.extract`.\n\n   If ``extraction_filter`` is ``None`` (the default), extraction methods\n   will use the :func:`data <data_filter>` filter by default.\n\n   The attribute may be set on instances or overridden in subclasses.\n   It also is possible to set it on the ``TarFile`` class itself to set a\n   global default, although, since it affects all uses of *tarfile*,\n   it is best practice to only do so in top-level applications or\n   :mod:`site configuration <site>`.\n   To set a global default this way, a filter function needs to be wrapped in\n   :func:`staticmethod` to prevent injection of a ``self`` argument.\n\n   .. versionchanged:: 3.14\n\n      The default filter is set to :func:`data <data_filter>`,\n      which disallows some dangerous features such as links to absolute paths\n      or paths outside of the destination.\n      Previously, the default was equivalent to\n      :func:`fully_trusted <fully_trusted_filter>`.\n\n.. method:: TarFile.add(name, arcname=None, recursive=True, *, filter=None)\n\n   Add the file *name* to the archive. *name* may be any type of file\n   (directory, fifo, symbolic link, etc.). If given, *arcname* specifies an\n   alternative name for the file in the archive. Directories are added\n   recursively by default. This can be avoided by setting *recursive* to\n   :const:`False`. Recursion adds entries in sorted order.\n   If *filter* is given, it\n   should be a function that takes a :class:`TarInfo` object argument and\n   returns the changed :class:`TarInfo` object. If it instead returns\n   :const:`None` the :class:`TarInfo` object will be excluded from the\n   archive. See :ref:`tar-examples` for an example.\n\n   .. versionchanged:: 3.2\n      Added the *filter* parameter.\n\n   .. versionchanged:: 3.7\n      Recursion adds entries in sorted order.\n\n\n.. method:: TarFile.addfile(tarinfo, fileobj=None)\n\n   Add the :class:`TarInfo` object *tarinfo* to the archive. If *tarinfo* represents\n   a non zero-size regular file, the *fileobj* argument should be a :term:`binary file`,\n   and ``tarinfo.size`` bytes are read from it and added to the archive.  You can\n   create :class:`TarInfo` objects directly, or by using :meth:`gettarinfo`.\n\n   .. versionchanged:: 3.13\n\n      *fileobj* must be given for non-zero-sized regular files.\n\n\n.. method:: TarFile.gettarinfo(name=None, arcname=None, fileobj=None)\n\n   Create a :class:`TarInfo` object from the result of :func:`os.stat` or\n   equivalent on an existing file.  The file is either named by *name*, or\n   specified as a :term:`file object` *fileobj* with a file descriptor.\n   *name* may be a :term:`path-like object`.  If\n   given, *arcname* specifies an alternative name for the file in the\n   archive, otherwise, the name is taken from *fileobj*’s\n   :attr:`~io.FileIO.name` attribute, or the *name* argument.  The name\n   should be a text string.\n\n   You can modify\n   some of the :class:`TarInfo`’s attributes before you add it using :meth:`addfile`.\n   If the file object is not an ordinary file object positioned at the\n   beginning of the file, attributes such as :attr:`~TarInfo.size` may need\n   modifying.  This is the case for objects such as :class:`~gzip.GzipFile`.\n   The :attr:`~TarInfo.name` may also be modified, in which case *arcname*\n   could be a dummy string.\n\n   .. versionchanged:: 3.6\n      The *name* parameter accepts a :term:`path-like object`.\n\n\n.. method:: TarFile.close()\n\n   Close the :class:`TarFile`. In write mode, two finishing zero blocks are\n   appended to the archive.\n\n\n.. attribute:: TarFile.pax_headers\n   :type: dict\n\n   A dictionary containing key-value pairs of pax global headers.\n\n\n\n.. _tarinfo-objects:\n\nTarInfo Objects\n---------------\n\nA :class:`TarInfo` object represents one member in a :class:`TarFile`. Aside\nfrom storing all required attributes of a file (like file type, size, time,\npermissions, owner etc.), it provides some useful methods to determine its type.\nIt does *not* contain the file's data itself.\n\n:class:`TarInfo` objects are returned by :class:`TarFile`'s methods\n:meth:`~TarFile.getmember`, :meth:`~TarFile.getmembers` and\n:meth:`~TarFile.gettarinfo`.\n\nModifying the objects returned by :meth:`~TarFile.getmember` or\n:meth:`~TarFile.getmembers` will affect all subsequent\noperations on the archive.\nFor cases where this is unwanted, you can use :mod:`copy.copy() <copy>` or\ncall the :meth:`~TarInfo.replace` method to create a modified copy in one step.\n\nSeveral attributes can be set to ``None`` to indicate that a piece of metadata\nis unused or unknown.\nDifferent :class:`TarInfo` methods handle ``None`` differently:\n\n- The :meth:`~TarFile.extract` or :meth:`~TarFile.extractall` methods will\n  ignore the corresponding metadata, leaving it set to a default.\n- :meth:`~TarFile.addfile` will fail.\n- :meth:`~TarFile.list` will print a placeholder string.\n\n.. class:: TarInfo(name=\"\")\n\n   Create a :class:`TarInfo` object.\n\n\n.. classmethod:: TarInfo.frombuf(buf, encoding, errors)\n\n   Create and return a :class:`TarInfo` object from string buffer *buf*.\n\n   Raises :exc:`HeaderError` if the buffer is invalid.\n\n\n.. classmethod:: TarInfo.fromtarfile(tarfile)\n\n   Read the next member from the :class:`TarFile` object *tarfile* and return it as\n   a :class:`TarInfo` object.\n\n\n.. method:: TarInfo.tobuf(format=DEFAULT_FORMAT, encoding=ENCODING, errors='surrogateescape')\n\n   Create a string buffer from a :class:`TarInfo` object. For information on the\n   arguments see the constructor of the :class:`TarFile` class.\n\n   .. versionchanged:: 3.2\n      Use ``'surrogateescape'`` as the default for the *errors* argument.\n\n\nA ``TarInfo`` object has the following public data attributes:\n\n\n.. attribute:: TarInfo.name\n   :type: str\n\n   Name of the archive member.\n\n\n.. attribute:: TarInfo.size\n   :type: int\n\n   Size in bytes.\n\n\n.. attribute:: TarInfo.mtime\n   :type: int | float\n\n   Time of last modification in seconds since the :ref:`epoch <epoch>`,\n   as in :attr:`os.stat_result.st_mtime`.\n\n   .. versionchanged:: 3.12\n\n      Can be set to ``None`` for :meth:`~TarFile.extract` and\n      :meth:`~TarFile.extractall`, causing extraction to skip applying this\n      attribute.\n\n.. attribute:: TarInfo.mode\n   :type: int\n\n   Permission bits, as for :func:`os.chmod`.\n\n   .. versionchanged:: 3.12\n\n      Can be set to ``None`` for :meth:`~TarFile.extract` and\n      :meth:`~TarFile.extractall`, causing extraction to skip applying this\n      attribute.\n\n.. attribute:: TarInfo.type\n\n   File type.  *type* is usually one of these constants: :const:`REGTYPE`,\n   :const:`AREGTYPE`, :const:`LNKTYPE`, :const:`SYMTYPE`, :const:`DIRTYPE`,\n   :const:`FIFOTYPE`, :const:`CONTTYPE`, :const:`CHRTYPE`, :const:`BLKTYPE`,\n   :const:`GNUTYPE_SPARSE`.  To determine the type of a :class:`TarInfo` object\n   more conveniently, use the ``is*()`` methods below.\n\n\n.. attribute:: TarInfo.linkname\n   :type: str\n\n   Name of the target file name, which is only present in :class:`TarInfo` objects\n   of type :const:`LNKTYPE` and :const:`SYMTYPE`.\n\n   For symbolic links (``SYMTYPE``), the *linkname* is relative to the directory\n   that contains the link.\n   For hard links (``LNKTYPE``), the *linkname* is relative to the root of\n   the archive.\n\n\n.. attribute:: TarInfo.uid\n   :type: int\n\n   User ID of the user who originally stored this member.\n\n   .. versionchanged:: 3.12\n\n      Can be set to ``None`` for :meth:`~TarFile.extract` and\n      :meth:`~TarFile.extractall`, causing extraction to skip applying this\n      attribute.\n\n.. attribute:: TarInfo.gid\n   :type: int\n\n   Group ID of the user who originally stored this member.\n\n   .. versionchanged:: 3.12\n\n      Can be set to ``None`` for :meth:`~TarFile.extract` and\n      :meth:`~TarFile.extractall`, causing extraction to skip applying this\n      attribute.\n\n.. attribute:: TarInfo.uname\n   :type: str\n\n   User name.\n\n   .. versionchanged:: 3.12\n\n      Can be set to ``None`` for :meth:`~TarFile.extract` and\n      :meth:`~TarFile.extractall`, causing extraction to skip applying this\n      attribute.\n\n.. attribute:: TarInfo.gname\n   :type: str\n\n   Group name.\n\n   .. versionchanged:: 3.12\n\n      Can be set to ``None`` for :meth:`~TarFile.extract` and\n      :meth:`~TarFile.extractall`, causing extraction to skip applying this\n      attribute.\n\n.. attribute:: TarInfo.chksum\n   :type: int\n\n   Header checksum.\n\n\n.. attribute:: TarInfo.devmajor\n   :type: int\n\n   Device major number.\n\n\n.. attribute:: TarInfo.devminor\n   :type: int\n\n   Device minor number.\n\n\n.. attribute:: TarInfo.offset\n   :type: int\n\n   The tar header starts here.\n\n\n.. attribute:: TarInfo.offset_data\n   :type: int\n\n   The file's data starts here.\n\n\n.. attribute:: TarInfo.sparse\n\n   Sparse member information.\n\n\n.. attribute:: TarInfo.pax_headers\n   :type: dict\n\n   A dictionary containing key-value pairs of an associated pax extended header.\n\n.. method:: TarInfo.replace(name=..., mtime=..., mode=..., linkname=..., \\\n                            uid=..., gid=..., uname=..., gname=..., \\\n                            deep=True)\n\n   .. versionadded:: 3.12\n\n   Return a *new* copy of the :class:`!TarInfo` object with the given attributes\n   changed. For example, to return a ``TarInfo`` with the group name set to\n   ``'staff'``, use::\n\n       new_tarinfo = old_tarinfo.replace(gname='staff')\n\n   By default, a deep copy is made.\n   If *deep* is false, the copy is shallow, i.e. ``pax_headers``\n   and any custom attributes are shared with the original ``TarInfo`` object.\n\nA :class:`TarInfo` object also provides some convenient query methods:\n\n\n.. method:: TarInfo.isfile()\n\n   Return :const:`True` if the :class:`TarInfo` object is a regular file.\n\n\n.. method:: TarInfo.isreg()\n\n   Same as :meth:`isfile`.\n\n\n.. method:: TarInfo.isdir()\n\n   Return :const:`True` if it is a directory.\n\n\n.. method:: TarInfo.issym()\n\n   Return :const:`True` if it is a symbolic link.\n\n\n.. method:: TarInfo.islnk()\n\n   Return :const:`True` if it is a hard link.\n\n\n.. method:: TarInfo.ischr()\n\n   Return :const:`True` if it is a character device.\n\n\n.. method:: TarInfo.isblk()\n\n   Return :const:`True` if it is a block device.\n\n\n.. method:: TarInfo.isfifo()\n\n   Return :const:`True` if it is a FIFO.\n\n\n.. method:: TarInfo.isdev()\n\n   Return :const:`True` if it is one of character device, block device or FIFO.\n\n\n.. _tarfile-extraction-filter:\n\nExtraction filters\n------------------\n\n.. versionadded:: 3.12\n\nThe *tar* format is designed to capture all details of a UNIX-like filesystem,\nwhich makes it very powerful.\nUnfortunately, the features make it easy to create tar files that have\nunintended -- and possibly malicious -- effects when extracted.\nFor example, extracting a tar file can overwrite arbitrary files in various\nways (e.g.  by using absolute paths, ``..`` path components, or symlinks that\naffect later members).\n\nIn most cases, the full functionality is not needed.\nTherefore, *tarfile* supports extraction filters: a mechanism to limit\nfunctionality, and thus mitigate some of the security issues.\n\n.. warning::\n\n   None of the available filters blocks *all* dangerous archive features.\n   Never extract archives from untrusted sources without prior inspection.\n   See also :ref:`tarfile-further-verification`.\n\n.. seealso::\n\n   :pep:`706`\n      Contains further motivation and rationale behind the design.\n\nThe *filter* argument to :meth:`TarFile.extract` or :meth:`~TarFile.extractall`\ncan be:\n\n* the string ``'fully_trusted'``: Honor all metadata as specified in the\n  archive.\n  Should be used if the user trusts the archive completely, or implements\n  their own complex verification.\n\n* the string ``'tar'``: Honor most *tar*-specific features (i.e. features of\n  UNIX-like filesystems), but block features that are very likely to be\n  surprising or malicious. See :func:`tar_filter` for details.\n\n* the string ``'data'``: Ignore or block most features specific to UNIX-like\n  filesystems. Intended for extracting cross-platform data archives.\n  See :func:`data_filter` for details.\n\n* ``None`` (default): Use :attr:`TarFile.extraction_filter`.\n\n  If that is also ``None`` (the default), the ``'data'`` filter will be used.\n\n   .. versionchanged:: 3.14\n\n      The default filter is set to :func:`data <data_filter>`.\n      Previously, the default was equivalent to\n      :func:`fully_trusted <fully_trusted_filter>`.\n\n* A callable which will be called for each extracted member with a\n  :ref:`TarInfo <tarinfo-objects>` describing the member and the destination\n  path to where the archive is extracted (i.e. the same path is used for all\n  members)::\n\n      filter(member: TarInfo, path: str, /) -> TarInfo | None\n\n  The callable is called just before each member is extracted, so it can\n  take the current state of the disk into account.\n  It can:\n\n  - return a :class:`TarInfo` object which will be used instead of the metadata\n    in the archive, or\n  - return ``None``, in which case the member will be skipped, or\n  - raise an exception to abort the operation or skip the member,\n    depending on :attr:`~TarFile.errorlevel`.\n    Note that when extraction is aborted, :meth:`~TarFile.extractall` may leave\n    the archive partially extracted. It does not attempt to clean up.\n\nDefault named filters\n~~~~~~~~~~~~~~~~~~~~~\n\nThe pre-defined, named filters are available as functions, so they can be\nreused in custom filters:\n\n.. function:: fully_trusted_filter(member, path)\n\n   Return *member* unchanged.\n\n   This implements the ``'fully_trusted'`` filter.\n\n.. function:: tar_filter(member, path)\n\n  Implements the ``'tar'`` filter.\n\n  - Strip leading slashes (``/`` and :data:`os.sep`) from filenames.\n  - :ref:`Refuse <tarfile-extraction-refuse>` to extract files with absolute\n    paths (in case the name is absolute\n    even after stripping slashes, e.g. ``C:/foo`` on Windows).\n    This raises :class:`~tarfile.AbsolutePathError`.\n  - :ref:`Refuse <tarfile-extraction-refuse>` to extract files whose absolute\n    path (after following symlinks) would end up outside the destination.\n    This raises :class:`~tarfile.OutsideDestinationError`.\n  - Clear high mode bits (setuid, setgid, sticky) and group/other write bits\n    (:const:`~stat.S_IWGRP` | :const:`~stat.S_IWOTH`).\n\n  Return the modified ``TarInfo`` member.\n\n.. function:: data_filter(member, path)\n\n  Implements the ``'data'`` filter.\n  In addition to what ``tar_filter`` does:\n\n  - Normalize link targets (:attr:`TarInfo.linkname`) using\n    :func:`os.path.normpath`.\n    Note that this removes internal ``..`` components, which may change the\n    meaning of the link if the path in :attr:`!TarInfo.linkname` traverses\n    symbolic links.\n\n  - :ref:`Refuse <tarfile-extraction-refuse>` to extract links (hard or soft)\n    that link to absolute paths, or ones that link outside the destination.\n\n    This raises :class:`~tarfile.AbsoluteLinkError` or\n    :class:`~tarfile.LinkOutsideDestinationError`.\n\n    Note that such files are refused even on platforms that do not support\n    symbolic links.\n\n  - :ref:`Refuse <tarfile-extraction-refuse>` to extract device files\n    (including pipes).\n    This raises :class:`~tarfile.SpecialFileError`.\n\n  - For regular files, including hard links:\n\n    - Set the owner read and write permissions\n      (:const:`~stat.S_IRUSR` | :const:`~stat.S_IWUSR`).\n    - Remove the group & other executable permission\n      (:const:`~stat.S_IXGRP` | :const:`~stat.S_IXOTH`)\n      if the owner doesn’t have it (:const:`~stat.S_IXUSR`).\n\n  - For other files (directories), set ``mode`` to ``None``, so\n    that extraction methods skip applying permission bits.\n  - Set user and group info (``uid``, ``gid``, ``uname``, ``gname``)\n    to ``None``, so that extraction methods skip setting it.\n\n  Return the modified ``TarInfo`` member.\n\n  Note that this filter does not block *all* dangerous archive features.\n  See :ref:`tarfile-further-verification`  for details.\n\n  .. versionchanged:: 3.14\n\n     Link targets are now normalized.\n\n\n.. _tarfile-extraction-refuse:\n\nFilter errors\n~~~~~~~~~~~~~\n\nWhen a filter refuses to extract a file, it will raise an appropriate exception,\na subclass of :class:`~tarfile.FilterError`.\nThis will abort the extraction if :attr:`TarFile.errorlevel` is 1 or more.\nWith ``errorlevel=0`` the error will be logged and the member will be skipped,\nbut extraction will continue.\n\n\n.. _tarfile-further-verification:\n\nHints for further verification\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nEven with ``filter='data'``, *tarfile* is not suited for extracting untrusted\nfiles without prior inspection.\nAmong other issues, the pre-defined filters do not prevent denial-of-service\nattacks. Users should do additional checks.\n\nHere is an incomplete list of things to consider:\n\n* Extract to a :func:`new temporary directory <tempfile.mkdtemp>`\n  to prevent e.g. exploiting pre-existing links, and to make it easier to\n  clean up after a failed extraction.\n* Disallow symbolic links if you do not need the functionality.\n* When working with untrusted data, use external (e.g. OS-level) limits on\n  disk, memory and CPU usage.\n* Check filenames against an allow-list of characters\n  (to filter out control characters, confusables, foreign path separators,\n  and so on).\n* Check that filenames have expected extensions (discouraging files that\n  execute when you “click on them”, or extension-less files like Windows\n  special device names).\n* Limit the number of extracted files, total size of extracted data,\n  filename length (including symlink length), and size of individual files.\n* Check for files that would be shadowed on case-insensitive filesystems.\n\nAlso note that:\n\n* Tar files may contain multiple versions of the same file.\n  Later ones are expected to overwrite any earlier ones.\n  This feature is crucial to allow updating tape archives, but can be abused\n  maliciously.\n* *tarfile* does not protect against issues with “live” data,\n  e.g. an attacker tinkering with the destination (or source) directory while\n  extraction (or archiving) is in progress.\n\n\nSupporting older Python versions\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nExtraction filters were added to Python 3.12, but may be backported to older\nversions as security updates.\nTo check whether the feature is available, use e.g.\n``hasattr(tarfile, 'data_filter')`` rather than checking the Python version.\n\nThe following examples show how to support Python versions with and without\nthe feature.\nNote that setting ``extraction_filter`` will affect any subsequent operations.\n\n* Fully trusted archive::\n\n    my_tarfile.extraction_filter = (lambda member, path: member)\n    my_tarfile.extractall()\n\n* Use the ``'data'`` filter if available, but revert to Python 3.11 behavior\n  (``'fully_trusted'``) if this feature is not available::\n\n    my_tarfile.extraction_filter = getattr(tarfile, 'data_filter',\n                                           (lambda member, path: member))\n    my_tarfile.extractall()\n\n* Use the ``'data'`` filter; *fail* if it is not available::\n\n    my_tarfile.extractall(filter=tarfile.data_filter)\n\n  or::\n\n    my_tarfile.extraction_filter = tarfile.data_filter\n    my_tarfile.extractall()\n\n* Use the ``'data'`` filter; *warn* if it is not available::\n\n   if hasattr(tarfile, 'data_filter'):\n       my_tarfile.extractall(filter='data')\n   else:\n       # remove this when no longer needed\n       warn_the_user('Extracting may be unsafe; consider updating Python')\n       my_tarfile.extractall()\n\n\nStateful extraction filter example\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nWhile *tarfile*'s extraction methods take a simple *filter* callable,\ncustom filters may be more complex objects with an internal state.\nIt may be useful to write these as context managers, to be used like this::\n\n    with StatefulFilter() as filter_func:\n        tar.extractall(path, filter=filter_func)\n\nSuch a filter can be written as, for example::\n\n    class StatefulFilter:\n        def __init__(self):\n            self.file_count = 0\n\n        def __enter__(self):\n            return self\n\n        def __call__(self, member, path):\n            self.file_count += 1\n            return member\n\n        def __exit__(self, *exc_info):\n            print(f'{self.file_count} files extracted')\n\n\n.. _tarfile-commandline:\n.. program:: tarfile\n\n\nCommand-Line Interface\n----------------------\n\n.. versionadded:: 3.4\n\nThe :mod:`tarfile` module provides a simple command-line interface to interact\nwith tar archives.\n\nIf you want to create a new tar archive, specify its name after the :option:`-c`\noption and then list the filename(s) that should be included:\n\n.. code-block:: shell-session\n\n    $ python -m tarfile -c monty.tar  spam.txt eggs.txt\n\nPassing a directory is also acceptable:\n\n.. code-block:: shell-session\n\n    $ python -m tarfile -c monty.tar life-of-brian_1979/\n\nIf you want to extract a tar archive into the current directory, use\nthe :option:`-e` option:\n\n.. code-block:: shell-session\n\n    $ python -m tarfile -e monty.tar\n\nYou can also extract a tar archive into a different directory by passing the\ndirectory's name:\n\n.. code-block:: shell-session\n\n    $ python -m tarfile -e monty.tar  other-dir/\n\nFor a list of the files in a tar archive, use the :option:`-l` option:\n\n.. code-block:: shell-session\n\n    $ python -m tarfile -l monty.tar\n\n\nCommand-line options\n~~~~~~~~~~~~~~~~~~~~\n\n.. option:: -l <tarfile>\n            --list <tarfile>\n\n   List files in a tarfile.\n\n.. option:: -c <tarfile> <source1> ... <sourceN>\n            --create <tarfile> <source1> ... <sourceN>\n\n   Create tarfile from source files.\n\n.. option:: -e <tarfile> [<output_dir>]\n            --extract <tarfile> [<output_dir>]\n\n   Extract tarfile into the current directory if *output_dir* is not specified.\n\n.. option:: -t <tarfile>\n            --test <tarfile>\n\n   Test whether the tarfile is valid or not.\n\n.. option:: -v, --verbose\n\n   Verbose output.\n\n.. option:: --filter <filtername>\n\n   Specifies the *filter* for ``--extract``.\n   See :ref:`tarfile-extraction-filter` for details.\n   Only string names are accepted (that is, ``fully_trusted``, ``tar``,\n   and ``data``).\n\n.. _tar-examples:\n\nExamples\n--------\n\nReading examples\n~~~~~~~~~~~~~~~~~~~\n\nHow to extract an entire tar archive to the current working directory::\n\n   import tarfile\n   tar = tarfile.open(\"sample.tar.gz\")\n   tar.extractall(filter='data')\n   tar.close()\n\nHow to extract a subset of a tar archive with :meth:`TarFile.extractall` using\na generator function instead of a list::\n\n   import os\n   import tarfile\n\n   def py_files(members):\n       for tarinfo in members:\n           if os.path.splitext(tarinfo.name)[1] == \".py\":\n               yield tarinfo\n\n   tar = tarfile.open(\"sample.tar.gz\")\n   tar.extractall(members=py_files(tar))\n   tar.close()\n\nHow to read a gzip compressed tar archive and display some member information::\n\n   import tarfile\n   tar = tarfile.open(\"sample.tar.gz\", \"r:gz\")\n   for tarinfo in tar:\n       print(tarinfo.name, \"is\", tarinfo.size, \"bytes in size and is \", end=\"\")\n       if tarinfo.isreg():\n           print(\"a regular file.\")\n       elif tarinfo.isdir():\n           print(\"a directory.\")\n       else:\n           print(\"something else.\")\n   tar.close()\n\nWriting examples\n~~~~~~~~~~~~~~~~\n\nHow to create an uncompressed tar archive from a list of filenames::\n\n   import tarfile\n   tar = tarfile.open(\"sample.tar\", \"w\")\n   for name in [\"foo\", \"bar\", \"quux\"]:\n       tar.add(name)\n   tar.close()\n\nThe same example using the :keyword:`with` statement::\n\n    import tarfile\n    with tarfile.open(\"sample.tar\", \"w\") as tar:\n        for name in [\"foo\", \"bar\", \"quux\"]:\n            tar.add(name)\n\nHow to create and write an archive to stdout using\n:data:`sys.stdout.buffer <sys.stdout>` in the *fileobj* parameter\nin :meth:`TarFile.add`::\n\n    import sys\n    import tarfile\n    with tarfile.open(\"sample.tar.gz\", \"w|gz\", fileobj=sys.stdout.buffer) as tar:\n        for name in [\"foo\", \"bar\", \"quux\"]:\n            tar.add(name)\n\nHow to create an archive and reset the user information using the *filter*\nparameter in :meth:`TarFile.add`::\n\n    import tarfile\n    def reset(tarinfo):\n        tarinfo.uid = tarinfo.gid = 0\n        tarinfo.uname = tarinfo.gname = \"root\"\n        return tarinfo\n    tar = tarfile.open(\"sample.tar.gz\", \"w:gz\")\n    tar.add(\"foo\", filter=reset)\n    tar.close()\n\n\n.. _tar-formats:\n\nSupported tar formats\n---------------------\n\nThere are three tar formats that can be created with the :mod:`tarfile` module:\n\n* The POSIX.1-1988 ustar format (:const:`USTAR_FORMAT`). It supports filenames\n  up to a length of at best 256 characters and linknames up to 100 characters.\n  The maximum file size is 8 GiB. This is an old and limited but widely\n  supported format.\n\n* The GNU tar format (:const:`GNU_FORMAT`). It supports long filenames and\n  linknames, files bigger than 8 GiB and sparse files. It is the de facto\n  standard on GNU/Linux systems. :mod:`tarfile` fully supports the GNU tar\n  extensions for long names, sparse file support is read-only.\n\n* The POSIX.1-2001 pax format (:const:`PAX_FORMAT`). It is the most flexible\n  format with virtually no limits. It supports long filenames and linknames, large\n  files and stores pathnames in a portable way. Modern tar implementations,\n  including GNU tar, bsdtar/libarchive and star, fully support extended *pax*\n  features; some old or unmaintained libraries may not, but should treat\n  *pax* archives as if they were in the universally supported *ustar* format.\n  It is the current default format for new archives.\n\n  It extends the existing *ustar* format with extra headers for information\n  that cannot be stored otherwise. There are two flavours of pax headers:\n  Extended headers only affect the subsequent file header, global\n  headers are valid for the complete archive and affect all following files.\n  All the data in a pax header is encoded in *UTF-8* for portability reasons.\n\nThere are some more variants of the tar format which can be read, but not\ncreated:\n\n* The ancient V7 format. This is the first tar format from Unix Seventh Edition,\n  storing only regular files and directories. Names must not be longer than 100\n  characters, there is no user/group name information. Some archives have\n  miscalculated header checksums in case of fields with non-ASCII characters.\n\n* The SunOS tar extended format. This format is a variant of the POSIX.1-2001\n  pax format, but is not compatible.\n\n.. _tar-unicode:\n\nUnicode issues\n--------------\n\nThe tar format was originally conceived to make backups on tape drives with the\nmain focus on preserving file system information. Nowadays tar archives are\ncommonly used for file distribution and exchanging archives over networks. One\nproblem of the original format (which is the basis of all other formats) is\nthat there is no concept of supporting different character encodings. For\nexample, an ordinary tar archive created on a *UTF-8* system cannot be read\ncorrectly on a *Latin-1* system if it contains non-*ASCII* characters. Textual\nmetadata (like filenames, linknames, user/group names) will appear damaged.\nUnfortunately, there is no way to autodetect the encoding of an archive. The\npax format was designed to solve this problem. It stores non-ASCII metadata\nusing the universal character encoding *UTF-8*.\n\nThe details of character conversion in :mod:`tarfile` are controlled by the\n*encoding* and *errors* keyword arguments of the :class:`TarFile` class.\n\n*encoding* defines the character encoding to use for the metadata in the\narchive. The default value is :func:`sys.getfilesystemencoding` or ``'ascii'``\nas a fallback. Depending on whether the archive is read or written, the\nmetadata must be either decoded or encoded. If *encoding* is not set\nappropriately, this conversion may fail.\n\nThe *errors* argument defines how characters are treated that cannot be\nconverted. Possible values are listed in section :ref:`error-handlers`.\nThe default scheme is ``'surrogateescape'`` which Python also uses for its\nfile system calls, see :ref:`os-filenames`.\n\nFor :const:`PAX_FORMAT` archives (the default), *encoding* is generally not needed\nbecause all the metadata is stored using *UTF-8*. *encoding* is only used in\nthe rare cases when binary pax headers are decoded or when strings with\nsurrogate characters are stored.\n",
      "rights": "Copyright (c) 2001 Python Software Foundation; All Rights Reserved. Raw RST unchanged. This reading aid adds selected quotations and agent-authored interpretation; no change to Python and no PSF endorsement. Complete license from the same release follows.\n\nA. HISTORY OF THE SOFTWARE\n==========================\n\nPython was created in the early 1990s by Guido van Rossum at Stichting\nMathematisch Centrum (CWI, see https://www.cwi.nl) in the Netherlands\nas a successor of a language called ABC.  Guido remains Python's\nprincipal author, although it includes many contributions from others.\n\nIn 1995, Guido continued his work on Python at the Corporation for\nNational Research Initiatives (CNRI, see https://www.cnri.reston.va.us)\nin Reston, Virginia where he released several versions of the\nsoftware.\n\nIn May 2000, Guido and the Python core development team moved to\nBeOpen.com to form the BeOpen PythonLabs team.  In October of the same\nyear, the PythonLabs team moved to Digital Creations, which became\nZope Corporation.  In 2001, the Python Software Foundation (PSF, see\nhttps://www.python.org/psf/) was formed, a non-profit organization\ncreated specifically to own Python-related Intellectual Property.\nZope Corporation was a sponsoring member of the PSF.\n\nAll Python releases are Open Source (see https://opensource.org for\nthe Open Source Definition).  Historically, most, but not all, Python\nreleases have also been GPL-compatible; the table below summarizes\nthe various releases.\n\n    Release         Derived     Year        Owner       GPL-\n                    from                                compatible? (1)\n\n    0.9.0 thru 1.2              1991-1995   CWI         yes\n    1.3 thru 1.5.2  1.2         1995-1999   CNRI        yes\n    1.6             1.5.2       2000        CNRI        no\n    2.0             1.6         2000        BeOpen.com  no\n    1.6.1           1.6         2001        CNRI        yes (2)\n    2.1             2.0+1.6.1   2001        PSF         no\n    2.0.1           2.0+1.6.1   2001        PSF         yes\n    2.1.1           2.1+2.0.1   2001        PSF         yes\n    2.1.2           2.1.1       2002        PSF         yes\n    2.1.3           2.1.2       2002        PSF         yes\n    2.2 and above   2.1.1       2001-now    PSF         yes\n\nFootnotes:\n\n(1) GPL-compatible doesn't mean that we're distributing Python under\n    the GPL.  All Python licenses, unlike the GPL, let you distribute\n    a modified version without making your changes open source.  The\n    GPL-compatible licenses make it possible to combine Python with\n    other software that is released under the GPL; the others don't.\n\n(2) According to Richard Stallman, 1.6.1 is not GPL-compatible,\n    because its license has a choice of law clause.  According to\n    CNRI, however, Stallman's lawyer has told CNRI's lawyer that 1.6.1\n    is \"not incompatible\" with the GPL.\n\nThanks to the many outside volunteers who have worked under Guido's\ndirection to make these releases possible.\n\n\nB. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON\n===============================================================\n\nPython software and documentation are licensed under the\nPython Software Foundation License Version 2.\n\nStarting with Python 3.8.6, examples, recipes, and other code in\nthe documentation are dual licensed under the PSF License Version 2\nand the Zero-Clause BSD license.\n\nSome software incorporated into Python is under different licenses.\nThe licenses are listed with code falling under that license.\n\n\nPYTHON SOFTWARE FOUNDATION LICENSE VERSION 2\n--------------------------------------------\n\n1. This LICENSE AGREEMENT is between the Python Software Foundation\n(\"PSF\"), and the Individual or Organization (\"Licensee\") accessing and\notherwise using this software (\"Python\") in source or binary form and\nits associated documentation.\n\n2. Subject to the terms and conditions of this License Agreement, PSF hereby\ngrants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,\nanalyze, test, perform and/or display publicly, prepare derivative works,\ndistribute, and otherwise use Python alone or in any derivative version,\nprovided, however, that PSF's License Agreement and PSF's notice of copyright,\ni.e., \"Copyright (c) 2001 Python Software Foundation; All Rights Reserved\"\nare retained in Python alone or in any derivative version prepared by Licensee.\n\n3. In the event Licensee prepares a derivative work that is based on\nor incorporates Python or any part thereof, and wants to make\nthe derivative work available to others as provided herein, then\nLicensee hereby agrees to include in any such work a brief summary of\nthe changes made to Python.\n\n4. PSF is making Python available to Licensee on an \"AS IS\"\nbasis.  PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR\nIMPLIED.  BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND\nDISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS\nFOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT\nINFRINGE ANY THIRD PARTY RIGHTS.\n\n5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON\nFOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS\nA RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,\nOR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.\n\n6. This License Agreement will automatically terminate upon a material\nbreach of its terms and conditions.\n\n7. Nothing in this License Agreement shall be deemed to create any\nrelationship of agency, partnership, or joint venture between PSF and\nLicensee.  This License Agreement does not grant permission to use PSF\ntrademarks or trade name in a trademark sense to endorse or promote\nproducts or services of Licensee, or any third party.\n\n8. By copying, installing or otherwise using Python, Licensee\nagrees to be bound by the terms and conditions of this License\nAgreement.\n\n\nBEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0\n-------------------------------------------\n\nBEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1\n\n1. This LICENSE AGREEMENT is between BeOpen.com (\"BeOpen\"), having an\noffice at 160 Saratoga Avenue, Santa Clara, CA 95051, and the\nIndividual or Organization (\"Licensee\") accessing and otherwise using\nthis software in source or binary form and its associated\ndocumentation (\"the Software\").\n\n2. Subject to the terms and conditions of this BeOpen Python License\nAgreement, BeOpen hereby grants Licensee a non-exclusive,\nroyalty-free, world-wide license to reproduce, analyze, test, perform\nand/or display publicly, prepare derivative works, distribute, and\notherwise use the Software alone or in any derivative version,\nprovided, however, that the BeOpen Python License is retained in the\nSoftware, alone or in any derivative version prepared by Licensee.\n\n3. BeOpen is making the Software available to Licensee on an \"AS IS\"\nbasis.  BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR\nIMPLIED.  BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND\nDISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS\nFOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT\nINFRINGE ANY THIRD PARTY RIGHTS.\n\n4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE\nSOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS\nAS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY\nDERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.\n\n5. This License Agreement will automatically terminate upon a material\nbreach of its terms and conditions.\n\n6. This License Agreement shall be governed by and interpreted in all\nrespects by the law of the State of California, excluding conflict of\nlaw provisions.  Nothing in this License Agreement shall be deemed to\ncreate any relationship of agency, partnership, or joint venture\nbetween BeOpen and Licensee.  This License Agreement does not grant\npermission to use BeOpen trademarks or trade names in a trademark\nsense to endorse or promote products or services of Licensee, or any\nthird party.  As an exception, the \"BeOpen Python\" logos available at\nhttp://www.pythonlabs.com/logos.html may be used according to the\npermissions granted on that web page.\n\n7. By copying, installing or otherwise using the software, Licensee\nagrees to be bound by the terms and conditions of this License\nAgreement.\n\n\nCNRI LICENSE AGREEMENT FOR PYTHON 1.6.1\n---------------------------------------\n\n1. This LICENSE AGREEMENT is between the Corporation for National\nResearch Initiatives, having an office at 1895 Preston White Drive,\nReston, VA 20191 (\"CNRI\"), and the Individual or Organization\n(\"Licensee\") accessing and otherwise using Python 1.6.1 software in\nsource or binary form and its associated documentation.\n\n2. Subject to the terms and conditions of this License Agreement, CNRI\nhereby grants Licensee a nonexclusive, royalty-free, world-wide\nlicense to reproduce, analyze, test, perform and/or display publicly,\nprepare derivative works, distribute, and otherwise use Python 1.6.1\nalone or in any derivative version, provided, however, that CNRI's\nLicense Agreement and CNRI's notice of copyright, i.e., \"Copyright (c)\n1995-2001 Corporation for National Research Initiatives; All Rights\nReserved\" are retained in Python 1.6.1 alone or in any derivative\nversion prepared by Licensee.  Alternately, in lieu of CNRI's License\nAgreement, Licensee may substitute the following text (omitting the\nquotes): \"Python 1.6.1 is made available subject to the terms and\nconditions in CNRI's License Agreement.  This Agreement together with\nPython 1.6.1 may be located on the internet using the following\nunique, persistent identifier (known as a handle): 1895.22/1013.  This\nAgreement may also be obtained from a proxy server on the internet\nusing the following URL: http://hdl.handle.net/1895.22/1013\".\n\n3. In the event Licensee prepares a derivative work that is based on\nor incorporates Python 1.6.1 or any part thereof, and wants to make\nthe derivative work available to others as provided herein, then\nLicensee hereby agrees to include in any such work a brief summary of\nthe changes made to Python 1.6.1.\n\n4. CNRI is making Python 1.6.1 available to Licensee on an \"AS IS\"\nbasis.  CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR\nIMPLIED.  BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND\nDISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS\nFOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT\nINFRINGE ANY THIRD PARTY RIGHTS.\n\n5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON\n1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS\nA RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1,\nOR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.\n\n6. This License Agreement will automatically terminate upon a material\nbreach of its terms and conditions.\n\n7. This License Agreement shall be governed by the federal\nintellectual property law of the United States, including without\nlimitation the federal copyright law, and, to the extent such\nU.S. federal law does not apply, by the law of the Commonwealth of\nVirginia, excluding Virginia's conflict of law provisions.\nNotwithstanding the foregoing, with regard to derivative works based\non Python 1.6.1 that incorporate non-separable material that was\npreviously distributed under the GNU General Public License (GPL), the\nlaw of the Commonwealth of Virginia shall govern this License\nAgreement only as to issues arising under or with respect to\nParagraphs 4, 5, and 7 of this License Agreement.  Nothing in this\nLicense Agreement shall be deemed to create any relationship of\nagency, partnership, or joint venture between CNRI and Licensee.  This\nLicense Agreement does not grant permission to use CNRI trademarks or\ntrade name in a trademark sense to endorse or promote products or\nservices of Licensee, or any third party.\n\n8. By clicking on the \"ACCEPT\" button where indicated, or by copying,\ninstalling or otherwise using Python 1.6.1, Licensee agrees to be\nbound by the terms and conditions of this License Agreement.\n\n        ACCEPT\n\n\nCWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2\n--------------------------------------------------\n\nCopyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam,\nThe Netherlands.  All rights reserved.\n\nPermission to use, copy, modify, and distribute this software and its\ndocumentation for any purpose and without fee is hereby granted,\nprovided that the above copyright notice appear in all copies and that\nboth that copyright notice and this permission notice appear in\nsupporting documentation, and that the name of Stichting Mathematisch\nCentrum or CWI not be used in advertising or publicity pertaining to\ndistribution of the software without specific, written prior\npermission.\n\nSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO\nTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\nFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE\nFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\nWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\nACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT\nOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n\nZERO-CLAUSE BSD LICENSE FOR CODE IN THE PYTHON DOCUMENTATION\n----------------------------------------------------------------------\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.\n"
    }
  ],
  "response": "{\n  \"claims\": [\n    {\n      \"id\": \"C1\",\n      \"text\": \"In this documented release, leaving both the filter argument and extraction_filter at None emits a DeprecationWarning and falls back to fully_trusted. The documentation schedules a change to data in Python 3.14; do not treat the old default as a cross-version contract.\",\n      \"citations\": [\n        {\n          \"source\": \"S1\",\n          \"quote\": \"If that is also ``None`` (the default), raise a ``DeprecationWarning``,\\n  and fall back to the ``'fully_trusted'`` filter, whose dangerous behavior\\n  matches previous versions of Python.\\n\\n  In Python 3.14, the ``'data'`` filter will become the default instead.\"\n        }\n      ]\n    },\n    {\n      \"id\": \"C2\",\n      \"text\": \"A refusal/abort can leave a partially extracted archive; extractall does not clean that up. Application cleanup must be considered separately.\",\n      \"citations\": [\n        {\n          \"source\": \"S1\",\n          \"quote\": \"Note that when extraction is aborted, :meth:`~TarFile.extractall` may leave\\n    the archive partially extracted. It does not attempt to clean up.\"\n        }\n      ]\n    },\n    {\n      \"id\": \"C3\",\n      \"text\": \"The data filter is not sufficient for uninspected untrusted files. The documentation explicitly says the predefined filters do not prevent denial-of-service attacks and calls for additional checks.\",\n      \"citations\": [\n        {\n          \"source\": \"S1\",\n          \"quote\": \"Even with ``filter='data'``, *tarfile* is not suited for extracting untrusted\\nfiles without prior inspection.\\nAmong other issues, the pre-defined filters do not prevent denial-of-service\\nattacks. Users should do additional checks.\"\n        }\n      ]\n    }\n  ],\n  \"questions\": [\n    \"Which Python implementations and patched versions must the application support? The pinned document is not an inventory of deployed runtimes.\",\n    \"Does the application inspect archives and clean up a partially extracted destination? Documentation is not a security review of that application.\"\n  ]\n}",
  "notes": "Initial same-agent editorial review of real, pinned Python3.12.0 documentation. C1–C3 are supported under that source/version scope; no runtime execution is claimed. Keep this historical evidence before replacing S1 with the3.14.0 document. This is not an independent model sample, independent reviewer or production security audit.",
  "snapshots": [
    {
      "label": "Python 3.12 source review",
      "savedAt": "2026-11-04T10:57:09.181Z",
      "evidence": {
        "format": "promptkb-evidence-brief",
        "version": 1,
        "title": "Tar extraction: Python 3.12 documentation review",
        "question": "For an application maintainer, what does the documented release say about tar extraction defaults, cleanup after a refusal, and the remaining security limits? Keep documented behavior separate from actual runtime observations; do not imply that a filter makes arbitrary uploads safe.",
        "sources": [
          {
            "id": "S1",
            "title": "CPython 3.12.0 tarfile documentation (raw RST)",
            "locator": "https://raw.githubusercontent.com/python/cpython/0fb18b02c8ad56299d6a2910be0bab8ad601ef24/Doc/library/tarfile.rst",
            "text": ":mod:`tarfile` --- Read and write tar archive files\n===================================================\n\n.. module:: tarfile\n   :synopsis: Read and write tar-format archive files.\n\n.. moduleauthor:: Lars Gustäbel <lars@gustaebel.de>\n.. sectionauthor:: Lars Gustäbel <lars@gustaebel.de>\n\n**Source code:** :source:`Lib/tarfile.py`\n\n--------------\n\nThe :mod:`tarfile` module makes it possible to read and write tar\narchives, including those using gzip, bz2 and lzma compression.\nUse the :mod:`zipfile` module to read or write :file:`.zip` files, or the\nhigher-level functions in :ref:`shutil <archiving-operations>`.\n\nSome facts and figures:\n\n* reads and writes :mod:`gzip`, :mod:`bz2` and :mod:`lzma` compressed archives\n  if the respective modules are available.\n\n* read/write support for the POSIX.1-1988 (ustar) format.\n\n* read/write support for the GNU tar format including *longname* and *longlink*\n  extensions, read-only support for all variants of the *sparse* extension\n  including restoration of sparse files.\n\n* read/write support for the POSIX.1-2001 (pax) format.\n\n* handles directories, regular files, hardlinks, symbolic links, fifos,\n  character devices and block devices and is able to acquire and restore file\n  information like timestamp, access permissions and owner.\n\n.. versionchanged:: 3.3\n   Added support for :mod:`lzma` compression.\n\n.. versionchanged:: 3.12\n   Archives are extracted using a :ref:`filter <tarfile-extraction-filter>`,\n   which makes it possible to either limit surprising/dangerous features,\n   or to acknowledge that they are expected and the archive is fully trusted.\n   By default, archives are fully trusted, but this default is deprecated\n   and slated to change in Python 3.14.\n\n\n.. function:: open(name=None, mode='r', fileobj=None, bufsize=10240, **kwargs)\n\n   Return a :class:`TarFile` object for the pathname *name*. For detailed\n   information on :class:`TarFile` objects and the keyword arguments that are\n   allowed, see :ref:`tarfile-objects`.\n\n   *mode* has to be a string of the form ``'filemode[:compression]'``, it defaults\n   to ``'r'``. Here is a full list of mode combinations:\n\n   +------------------+---------------------------------------------+\n   | mode             | action                                      |\n   +==================+=============================================+\n   | ``'r' or 'r:*'`` | Open for reading with transparent           |\n   |                  | compression (recommended).                  |\n   +------------------+---------------------------------------------+\n   | ``'r:'``         | Open for reading exclusively without        |\n   |                  | compression.                                |\n   +------------------+---------------------------------------------+\n   | ``'r:gz'``       | Open for reading with gzip compression.     |\n   +------------------+---------------------------------------------+\n   | ``'r:bz2'``      | Open for reading with bzip2 compression.    |\n   +------------------+---------------------------------------------+\n   | ``'r:xz'``       | Open for reading with lzma compression.     |\n   +------------------+---------------------------------------------+\n   | ``'x'`` or       | Create a tarfile exclusively without        |\n   | ``'x:'``         | compression.                                |\n   |                  | Raise a :exc:`FileExistsError` exception    |\n   |                  | if it already exists.                       |\n   +------------------+---------------------------------------------+\n   | ``'x:gz'``       | Create a tarfile with gzip compression.     |\n   |                  | Raise a :exc:`FileExistsError` exception    |\n   |                  | if it already exists.                       |\n   +------------------+---------------------------------------------+\n   | ``'x:bz2'``      | Create a tarfile with bzip2 compression.    |\n   |                  | Raise a :exc:`FileExistsError` exception    |\n   |                  | if it already exists.                       |\n   +------------------+---------------------------------------------+\n   | ``'x:xz'``       | Create a tarfile with lzma compression.     |\n   |                  | Raise a :exc:`FileExistsError` exception    |\n   |                  | if it already exists.                       |\n   +------------------+---------------------------------------------+\n   | ``'a' or 'a:'``  | Open for appending with no compression. The |\n   |                  | file is created if it does not exist.       |\n   +------------------+---------------------------------------------+\n   | ``'w' or 'w:'``  | Open for uncompressed writing.              |\n   +------------------+---------------------------------------------+\n   | ``'w:gz'``       | Open for gzip compressed writing.           |\n   +------------------+---------------------------------------------+\n   | ``'w:bz2'``      | Open for bzip2 compressed writing.          |\n   +------------------+---------------------------------------------+\n   | ``'w:xz'``       | Open for lzma compressed writing.           |\n   +------------------+---------------------------------------------+\n\n   Note that ``'a:gz'``, ``'a:bz2'`` or ``'a:xz'`` is not possible. If *mode*\n   is not suitable to open a certain (compressed) file for reading,\n   :exc:`ReadError` is raised. Use *mode* ``'r'`` to avoid this.  If a\n   compression method is not supported, :exc:`CompressionError` is raised.\n\n   If *fileobj* is specified, it is used as an alternative to a :term:`file object`\n   opened in binary mode for *name*. It is supposed to be at position 0.\n\n   For modes ``'w:gz'``, ``'x:gz'``, ``'w|gz'``, ``'w:bz2'``, ``'x:bz2'``,\n   ``'w|bz2'``, :func:`tarfile.open` accepts the keyword argument\n   *compresslevel* (default ``9``) to specify the compression level of the file.\n\n   For modes ``'w:xz'`` and ``'x:xz'``, :func:`tarfile.open` accepts the\n   keyword argument *preset* to specify the compression level of the file.\n\n   For special purposes, there is a second format for *mode*:\n   ``'filemode|[compression]'``.  :func:`tarfile.open` will return a :class:`TarFile`\n   object that processes its data as a stream of blocks.  No random seeking will\n   be done on the file. If given, *fileobj* may be any object that has a\n   :meth:`read` or :meth:`write` method (depending on the *mode*). *bufsize*\n   specifies the blocksize and defaults to ``20 * 512`` bytes. Use this variant\n   in combination with e.g. ``sys.stdin``, a socket :term:`file object` or a tape\n   device. However, such a :class:`TarFile` object is limited in that it does\n   not allow random access, see :ref:`tar-examples`.  The currently\n   possible modes:\n\n   +-------------+--------------------------------------------+\n   | Mode        | Action                                     |\n   +=============+============================================+\n   | ``'r|*'``   | Open a *stream* of tar blocks for reading  |\n   |             | with transparent compression.              |\n   +-------------+--------------------------------------------+\n   | ``'r|'``    | Open a *stream* of uncompressed tar blocks |\n   |             | for reading.                               |\n   +-------------+--------------------------------------------+\n   | ``'r|gz'``  | Open a gzip compressed *stream* for        |\n   |             | reading.                                   |\n   +-------------+--------------------------------------------+\n   | ``'r|bz2'`` | Open a bzip2 compressed *stream* for       |\n   |             | reading.                                   |\n   +-------------+--------------------------------------------+\n   | ``'r|xz'``  | Open an lzma compressed *stream* for       |\n   |             | reading.                                   |\n   +-------------+--------------------------------------------+\n   | ``'w|'``    | Open an uncompressed *stream* for writing. |\n   +-------------+--------------------------------------------+\n   | ``'w|gz'``  | Open a gzip compressed *stream* for        |\n   |             | writing.                                   |\n   +-------------+--------------------------------------------+\n   | ``'w|bz2'`` | Open a bzip2 compressed *stream* for       |\n   |             | writing.                                   |\n   +-------------+--------------------------------------------+\n   | ``'w|xz'``  | Open an lzma compressed *stream* for       |\n   |             | writing.                                   |\n   +-------------+--------------------------------------------+\n\n   .. versionchanged:: 3.5\n      The ``'x'`` (exclusive creation) mode was added.\n\n   .. versionchanged:: 3.6\n      The *name* parameter accepts a :term:`path-like object`.\n\n   .. versionchanged:: 3.12\n      The *compresslevel* keyword argument also works for streams.\n\n\n.. class:: TarFile\n   :noindex:\n\n   Class for reading and writing tar archives. Do not use this class directly:\n   use :func:`tarfile.open` instead. See :ref:`tarfile-objects`.\n\n\n.. function:: is_tarfile(name)\n\n   Return :const:`True` if *name* is a tar archive file, that the :mod:`tarfile`\n   module can read. *name* may be a :class:`str`, file, or file-like object.\n\n   .. versionchanged:: 3.9\n      Support for file and file-like objects.\n\n\nThe :mod:`tarfile` module defines the following exceptions:\n\n\n.. exception:: TarError\n\n   Base class for all :mod:`tarfile` exceptions.\n\n\n.. exception:: ReadError\n\n   Is raised when a tar archive is opened, that either cannot be handled by the\n   :mod:`tarfile` module or is somehow invalid.\n\n\n.. exception:: CompressionError\n\n   Is raised when a compression method is not supported or when the data cannot be\n   decoded properly.\n\n\n.. exception:: StreamError\n\n   Is raised for the limitations that are typical for stream-like :class:`TarFile`\n   objects.\n\n\n.. exception:: ExtractError\n\n   Is raised for *non-fatal* errors when using :meth:`TarFile.extract`, but only if\n   :attr:`TarFile.errorlevel`\\ ``== 2``.\n\n\n.. exception:: HeaderError\n\n   Is raised by :meth:`TarInfo.frombuf` if the buffer it gets is invalid.\n\n\n.. exception:: FilterError\n\n   Base class for members :ref:`refused <tarfile-extraction-refuse>` by\n   filters.\n\n   .. attribute:: tarinfo\n\n      Information about the member that the filter refused to extract,\n      as :ref:`TarInfo <tarinfo-objects>`.\n\n.. exception:: AbsolutePathError\n\n   Raised to refuse extracting a member with an absolute path.\n\n.. exception:: OutsideDestinationError\n\n   Raised to refuse extracting a member outside the destination directory.\n\n.. exception:: SpecialFileError\n\n   Raised to refuse extracting a special file (e.g. a device or pipe).\n\n.. exception:: AbsoluteLinkError\n\n   Raised to refuse extracting a symbolic link with an absolute path.\n\n.. exception:: LinkOutsideDestinationError\n\n   Raised to refuse extracting a symbolic link pointing outside the destination\n   directory.\n\n\nThe following constants are available at the module level:\n\n.. data:: ENCODING\n\n   The default character encoding: ``'utf-8'`` on Windows, the value returned by\n   :func:`sys.getfilesystemencoding` otherwise.\n\n\nEach of the following constants defines a tar archive format that the\n:mod:`tarfile` module is able to create. See section :ref:`tar-formats` for\ndetails.\n\n\n.. data:: USTAR_FORMAT\n\n   POSIX.1-1988 (ustar) format.\n\n\n.. data:: GNU_FORMAT\n\n   GNU tar format.\n\n\n.. data:: PAX_FORMAT\n\n   POSIX.1-2001 (pax) format.\n\n\n.. data:: DEFAULT_FORMAT\n\n   The default format for creating archives. This is currently :const:`PAX_FORMAT`.\n\n   .. versionchanged:: 3.8\n      The default format for new archives was changed to\n      :const:`PAX_FORMAT` from :const:`GNU_FORMAT`.\n\n\n.. seealso::\n\n   Module :mod:`zipfile`\n      Documentation of the :mod:`zipfile` standard module.\n\n   :ref:`archiving-operations`\n      Documentation of the higher-level archiving facilities provided by the\n      standard :mod:`shutil` module.\n\n   `GNU tar manual, Basic Tar Format <https://www.gnu.org/software/tar/manual/html_node/Standard.html>`_\n      Documentation for tar archive files, including GNU tar extensions.\n\n\n.. _tarfile-objects:\n\nTarFile Objects\n---------------\n\nThe :class:`TarFile` object provides an interface to a tar archive. A tar\narchive is a sequence of blocks. An archive member (a stored file) is made up of\na header block followed by data blocks. It is possible to store a file in a tar\narchive several times. Each archive member is represented by a :class:`TarInfo`\nobject, see :ref:`tarinfo-objects` for details.\n\nA :class:`TarFile` object can be used as a context manager in a :keyword:`with`\nstatement. It will automatically be closed when the block is completed. Please\nnote that in the event of an exception an archive opened for writing will not\nbe finalized; only the internally used file object will be closed. See the\n:ref:`tar-examples` section for a use case.\n\n.. versionadded:: 3.2\n   Added support for the context management protocol.\n\n.. class:: TarFile(name=None, mode='r', fileobj=None, format=DEFAULT_FORMAT, tarinfo=TarInfo, dereference=False, ignore_zeros=False, encoding=ENCODING, errors='surrogateescape', pax_headers=None, debug=0, errorlevel=1)\n\n   All following arguments are optional and can be accessed as instance attributes\n   as well.\n\n   *name* is the pathname of the archive. *name* may be a :term:`path-like object`.\n   It can be omitted if *fileobj* is given.\n   In this case, the file object's :attr:`name` attribute is used if it exists.\n\n   *mode* is either ``'r'`` to read from an existing archive, ``'a'`` to append\n   data to an existing file, ``'w'`` to create a new file overwriting an existing\n   one, or ``'x'`` to create a new file only if it does not already exist.\n\n   If *fileobj* is given, it is used for reading or writing data. If it can be\n   determined, *mode* is overridden by *fileobj*'s mode. *fileobj* will be used\n   from position 0.\n\n   .. note::\n\n      *fileobj* is not closed, when :class:`TarFile` is closed.\n\n   *format* controls the archive format for writing. It must be one of the constants\n   :const:`USTAR_FORMAT`, :const:`GNU_FORMAT` or :const:`PAX_FORMAT` that are\n   defined at module level. When reading, format will be automatically detected, even\n   if different formats are present in a single archive.\n\n   The *tarinfo* argument can be used to replace the default :class:`TarInfo` class\n   with a different one.\n\n   If *dereference* is :const:`False`, add symbolic and hard links to the archive. If it\n   is :const:`True`, add the content of the target files to the archive. This has no\n   effect on systems that do not support symbolic links.\n\n   If *ignore_zeros* is :const:`False`, treat an empty block as the end of the archive.\n   If it is :const:`True`, skip empty (and invalid) blocks and try to get as many members\n   as possible. This is only useful for reading concatenated or damaged archives.\n\n   *debug* can be set from ``0`` (no debug messages) up to ``3`` (all debug\n   messages). The messages are written to ``sys.stderr``.\n\n   *errorlevel* controls how extraction errors are handled,\n   see :attr:`the corresponding attribute <~TarFile.errorlevel>`.\n\n   The *encoding* and *errors* arguments define the character encoding to be\n   used for reading or writing the archive and how conversion errors are going\n   to be handled. The default settings will work for most users.\n   See section :ref:`tar-unicode` for in-depth information.\n\n   The *pax_headers* argument is an optional dictionary of strings which\n   will be added as a pax global header if *format* is :const:`PAX_FORMAT`.\n\n   .. versionchanged:: 3.2\n      Use ``'surrogateescape'`` as the default for the *errors* argument.\n\n   .. versionchanged:: 3.5\n      The ``'x'`` (exclusive creation) mode was added.\n\n   .. versionchanged:: 3.6\n      The *name* parameter accepts a :term:`path-like object`.\n\n\n.. classmethod:: TarFile.open(...)\n\n   Alternative constructor. The :func:`tarfile.open` function is actually a\n   shortcut to this classmethod.\n\n\n.. method:: TarFile.getmember(name)\n\n   Return a :class:`TarInfo` object for member *name*. If *name* can not be found\n   in the archive, :exc:`KeyError` is raised.\n\n   .. note::\n\n      If a member occurs more than once in the archive, its last occurrence is assumed\n      to be the most up-to-date version.\n\n\n.. method:: TarFile.getmembers()\n\n   Return the members of the archive as a list of :class:`TarInfo` objects. The\n   list has the same order as the members in the archive.\n\n\n.. method:: TarFile.getnames()\n\n   Return the members as a list of their names. It has the same order as the list\n   returned by :meth:`getmembers`.\n\n\n.. method:: TarFile.list(verbose=True, *, members=None)\n\n   Print a table of contents to ``sys.stdout``. If *verbose* is :const:`False`,\n   only the names of the members are printed. If it is :const:`True`, output\n   similar to that of :program:`ls -l` is produced. If optional *members* is\n   given, it must be a subset of the list returned by :meth:`getmembers`.\n\n   .. versionchanged:: 3.5\n      Added the *members* parameter.\n\n\n.. method:: TarFile.next()\n\n   Return the next member of the archive as a :class:`TarInfo` object, when\n   :class:`TarFile` is opened for reading. Return :const:`None` if there is no more\n   available.\n\n\n.. method:: TarFile.extractall(path=\".\", members=None, *, numeric_owner=False, filter=None)\n\n   Extract all members from the archive to the current working directory or\n   directory *path*. If optional *members* is given, it must be a subset of the\n   list returned by :meth:`getmembers`. Directory information like owner,\n   modification time and permissions are set after all members have been extracted.\n   This is done to work around two problems: A directory's modification time is\n   reset each time a file is created in it. And, if a directory's permissions do\n   not allow writing, extracting files to it will fail.\n\n   If *numeric_owner* is :const:`True`, the uid and gid numbers from the tarfile\n   are used to set the owner/group for the extracted files. Otherwise, the named\n   values from the tarfile are used.\n\n   The *filter* argument specifies how ``members`` are modified or rejected\n   before extraction.\n   See :ref:`tarfile-extraction-filter` for details.\n   It is recommended to set this explicitly depending on which *tar* features\n   you need to support.\n\n   .. warning::\n\n      Never extract archives from untrusted sources without prior inspection.\n      It is possible that files are created outside of *path*, e.g. members\n      that have absolute filenames starting with ``\"/\"`` or filenames with two\n      dots ``\"..\"``.\n\n      Set ``filter='data'`` to prevent the most dangerous security issues,\n      and read the :ref:`tarfile-extraction-filter` section for details.\n\n   .. versionchanged:: 3.5\n      Added the *numeric_owner* parameter.\n\n   .. versionchanged:: 3.6\n      The *path* parameter accepts a :term:`path-like object`.\n\n   .. versionchanged:: 3.12\n      Added the *filter* parameter.\n\n\n.. method:: TarFile.extract(member, path=\"\", set_attrs=True, *, numeric_owner=False, filter=None)\n\n   Extract a member from the archive to the current working directory, using its\n   full name. Its file information is extracted as accurately as possible. *member*\n   may be a filename or a :class:`TarInfo` object. You can specify a different\n   directory using *path*. *path* may be a :term:`path-like object`.\n   File attributes (owner, mtime, mode) are set unless *set_attrs* is false.\n\n   The *numeric_owner* and *filter* arguments are the same as\n   for :meth:`extractall`.\n\n   .. note::\n\n      The :meth:`extract` method does not take care of several extraction issues.\n      In most cases you should consider using the :meth:`extractall` method.\n\n   .. warning::\n\n      See the warning for :meth:`extractall`.\n\n      Set ``filter='data'`` to prevent the most dangerous security issues,\n      and read the :ref:`tarfile-extraction-filter` section for details.\n\n   .. versionchanged:: 3.2\n      Added the *set_attrs* parameter.\n\n   .. versionchanged:: 3.5\n      Added the *numeric_owner* parameter.\n\n   .. versionchanged:: 3.6\n      The *path* parameter accepts a :term:`path-like object`.\n\n   .. versionchanged:: 3.12\n      Added the *filter* parameter.\n\n\n.. method:: TarFile.extractfile(member)\n\n   Extract a member from the archive as a file object. *member* may be\n   a filename or a :class:`TarInfo` object. If *member* is a regular file or\n   a link, an :class:`io.BufferedReader` object is returned. For all other\n   existing members, :const:`None` is returned. If *member* does not appear\n   in the archive, :exc:`KeyError` is raised.\n\n   .. versionchanged:: 3.3\n      Return an :class:`io.BufferedReader` object.\n\n.. attribute:: TarFile.errorlevel\n   :type: int\n\n   If *errorlevel* is ``0``, errors are ignored when using :meth:`TarFile.extract`\n   and :meth:`TarFile.extractall`.\n   Nevertheless, they appear as error messages in the debug output when\n   *debug* is greater than 0.\n   If ``1`` (the default), all *fatal* errors are raised as :exc:`OSError` or\n   :exc:`FilterError` exceptions. If ``2``, all *non-fatal* errors are raised\n   as :exc:`TarError` exceptions as well.\n\n   Some exceptions, e.g. ones caused by wrong argument types or data\n   corruption, are always raised.\n\n   Custom :ref:`extraction filters <tarfile-extraction-filter>`\n   should raise :exc:`FilterError` for *fatal* errors\n   and :exc:`ExtractError` for *non-fatal* ones.\n\n   Note that when an exception is raised, the archive may be partially\n   extracted. It is the user’s responsibility to clean up.\n\n.. attribute:: TarFile.extraction_filter\n\n   .. versionadded:: 3.12\n\n   The :ref:`extraction filter <tarfile-extraction-filter>` used\n   as a default for the *filter* argument of :meth:`~TarFile.extract`\n   and :meth:`~TarFile.extractall`.\n\n   The attribute may be ``None`` or a callable.\n   String names are not allowed for this attribute, unlike the *filter*\n   argument to :meth:`~TarFile.extract`.\n\n   If ``extraction_filter`` is ``None`` (the default),\n   calling an extraction method without a *filter* argument will raise a\n   ``DeprecationWarning``,\n   and fall back to the :func:`fully_trusted <fully_trusted_filter>` filter,\n   whose dangerous behavior matches previous versions of Python.\n\n   In Python 3.14+, leaving ``extraction_filter=None`` will cause\n   extraction methods to use the :func:`data <data_filter>` filter by default.\n\n   The attribute may be set on instances or overridden in subclasses.\n   It also is possible to set it on the ``TarFile`` class itself to set a\n   global default, although, since it affects all uses of *tarfile*,\n   it is best practice to only do so in top-level applications or\n   :mod:`site configuration <site>`.\n   To set a global default this way, a filter function needs to be wrapped in\n   :func:`staticmethod()` to prevent injection of a ``self`` argument.\n\n.. method:: TarFile.add(name, arcname=None, recursive=True, *, filter=None)\n\n   Add the file *name* to the archive. *name* may be any type of file\n   (directory, fifo, symbolic link, etc.). If given, *arcname* specifies an\n   alternative name for the file in the archive. Directories are added\n   recursively by default. This can be avoided by setting *recursive* to\n   :const:`False`. Recursion adds entries in sorted order.\n   If *filter* is given, it\n   should be a function that takes a :class:`TarInfo` object argument and\n   returns the changed :class:`TarInfo` object. If it instead returns\n   :const:`None` the :class:`TarInfo` object will be excluded from the\n   archive. See :ref:`tar-examples` for an example.\n\n   .. versionchanged:: 3.2\n      Added the *filter* parameter.\n\n   .. versionchanged:: 3.7\n      Recursion adds entries in sorted order.\n\n\n.. method:: TarFile.addfile(tarinfo, fileobj=None)\n\n   Add the :class:`TarInfo` object *tarinfo* to the archive. If *fileobj* is given,\n   it should be a :term:`binary file`, and\n   ``tarinfo.size`` bytes are read from it and added to the archive.  You can\n   create :class:`TarInfo` objects directly, or by using :meth:`gettarinfo`.\n\n\n.. method:: TarFile.gettarinfo(name=None, arcname=None, fileobj=None)\n\n   Create a :class:`TarInfo` object from the result of :func:`os.stat` or\n   equivalent on an existing file.  The file is either named by *name*, or\n   specified as a :term:`file object` *fileobj* with a file descriptor.\n   *name* may be a :term:`path-like object`.  If\n   given, *arcname* specifies an alternative name for the file in the\n   archive, otherwise, the name is taken from *fileobj*’s\n   :attr:`~io.FileIO.name` attribute, or the *name* argument.  The name\n   should be a text string.\n\n   You can modify\n   some of the :class:`TarInfo`’s attributes before you add it using :meth:`addfile`.\n   If the file object is not an ordinary file object positioned at the\n   beginning of the file, attributes such as :attr:`~TarInfo.size` may need\n   modifying.  This is the case for objects such as :class:`~gzip.GzipFile`.\n   The :attr:`~TarInfo.name` may also be modified, in which case *arcname*\n   could be a dummy string.\n\n   .. versionchanged:: 3.6\n      The *name* parameter accepts a :term:`path-like object`.\n\n\n.. method:: TarFile.close()\n\n   Close the :class:`TarFile`. In write mode, two finishing zero blocks are\n   appended to the archive.\n\n\n.. attribute:: TarFile.pax_headers\n\n   A dictionary containing key-value pairs of pax global headers.\n\n\n\n.. _tarinfo-objects:\n\nTarInfo Objects\n---------------\n\nA :class:`TarInfo` object represents one member in a :class:`TarFile`. Aside\nfrom storing all required attributes of a file (like file type, size, time,\npermissions, owner etc.), it provides some useful methods to determine its type.\nIt does *not* contain the file's data itself.\n\n:class:`TarInfo` objects are returned by :class:`TarFile`'s methods\n:meth:`~TarFile.getmember`, :meth:`~TarFile.getmembers` and\n:meth:`~TarFile.gettarinfo`.\n\nModifying the objects returned by :meth:`~!TarFile.getmember` or\n:meth:`~!TarFile.getmembers` will affect all subsequent\noperations on the archive.\nFor cases where this is unwanted, you can use :mod:`copy.copy() <copy>` or\ncall the :meth:`~TarInfo.replace` method to create a modified copy in one step.\n\nSeveral attributes can be set to ``None`` to indicate that a piece of metadata\nis unused or unknown.\nDifferent :class:`TarInfo` methods handle ``None`` differently:\n\n- The :meth:`~TarFile.extract` or :meth:`~TarFile.extractall` methods will\n  ignore the corresponding metadata, leaving it set to a default.\n- :meth:`~TarFile.addfile` will fail.\n- :meth:`~TarFile.list` will print a placeholder string.\n\n.. class:: TarInfo(name=\"\")\n\n   Create a :class:`TarInfo` object.\n\n\n.. classmethod:: TarInfo.frombuf(buf, encoding, errors)\n\n   Create and return a :class:`TarInfo` object from string buffer *buf*.\n\n   Raises :exc:`HeaderError` if the buffer is invalid.\n\n\n.. classmethod:: TarInfo.fromtarfile(tarfile)\n\n   Read the next member from the :class:`TarFile` object *tarfile* and return it as\n   a :class:`TarInfo` object.\n\n\n.. method:: TarInfo.tobuf(format=DEFAULT_FORMAT, encoding=ENCODING, errors='surrogateescape')\n\n   Create a string buffer from a :class:`TarInfo` object. For information on the\n   arguments see the constructor of the :class:`TarFile` class.\n\n   .. versionchanged:: 3.2\n      Use ``'surrogateescape'`` as the default for the *errors* argument.\n\n\nA ``TarInfo`` object has the following public data attributes:\n\n\n.. attribute:: TarInfo.name\n   :type: str\n\n   Name of the archive member.\n\n\n.. attribute:: TarInfo.size\n   :type: int\n\n   Size in bytes.\n\n\n.. attribute:: TarInfo.mtime\n   :type: int | float\n\n   Time of last modification in seconds since the :ref:`epoch <epoch>`,\n   as in :attr:`os.stat_result.st_mtime`.\n\n   .. versionchanged:: 3.12\n\n      Can be set to ``None`` for :meth:`~TarFile.extract` and\n      :meth:`~TarFile.extractall`, causing extraction to skip applying this\n      attribute.\n\n.. attribute:: TarInfo.mode\n   :type: int\n\n   Permission bits, as for :func:`os.chmod`.\n\n   .. versionchanged:: 3.12\n\n      Can be set to ``None`` for :meth:`~TarFile.extract` and\n      :meth:`~TarFile.extractall`, causing extraction to skip applying this\n      attribute.\n\n.. attribute:: TarInfo.type\n\n   File type.  *type* is usually one of these constants: :const:`REGTYPE`,\n   :const:`AREGTYPE`, :const:`LNKTYPE`, :const:`SYMTYPE`, :const:`DIRTYPE`,\n   :const:`FIFOTYPE`, :const:`CONTTYPE`, :const:`CHRTYPE`, :const:`BLKTYPE`,\n   :const:`GNUTYPE_SPARSE`.  To determine the type of a :class:`TarInfo` object\n   more conveniently, use the ``is*()`` methods below.\n\n\n.. attribute:: TarInfo.linkname\n   :type: str\n\n   Name of the target file name, which is only present in :class:`TarInfo` objects\n   of type :const:`LNKTYPE` and :const:`SYMTYPE`.\n\n   For symbolic links (``SYMTYPE``), the *linkname* is relative to the directory\n   that contains the link.\n   For hard links (``LNKTYPE``), the *linkname* is relative to the root of\n   the archive.\n\n\n.. attribute:: TarInfo.uid\n   :type: int\n\n   User ID of the user who originally stored this member.\n\n   .. versionchanged:: 3.12\n\n      Can be set to ``None`` for :meth:`~TarFile.extract` and\n      :meth:`~TarFile.extractall`, causing extraction to skip applying this\n      attribute.\n\n.. attribute:: TarInfo.gid\n   :type: int\n\n   Group ID of the user who originally stored this member.\n\n   .. versionchanged:: 3.12\n\n      Can be set to ``None`` for :meth:`~TarFile.extract` and\n      :meth:`~TarFile.extractall`, causing extraction to skip applying this\n      attribute.\n\n.. attribute:: TarInfo.uname\n   :type: str\n\n   User name.\n\n   .. versionchanged:: 3.12\n\n      Can be set to ``None`` for :meth:`~TarFile.extract` and\n      :meth:`~TarFile.extractall`, causing extraction to skip applying this\n      attribute.\n\n.. attribute:: TarInfo.gname\n   :type: str\n\n   Group name.\n\n   .. versionchanged:: 3.12\n\n      Can be set to ``None`` for :meth:`~TarFile.extract` and\n      :meth:`~TarFile.extractall`, causing extraction to skip applying this\n      attribute.\n\n.. attribute:: TarInfo.pax_headers\n   :type: dict\n\n   A dictionary containing key-value pairs of an associated pax extended header.\n\n.. method:: TarInfo.replace(name=..., mtime=..., mode=..., linkname=...,\n                            uid=..., gid=..., uname=..., gname=...,\n                            deep=True)\n\n   .. versionadded:: 3.12\n\n   Return a *new* copy of the :class:`!TarInfo` object with the given attributes\n   changed. For example, to return a ``TarInfo`` with the group name set to\n   ``'staff'``, use::\n\n       new_tarinfo = old_tarinfo.replace(gname='staff')\n\n   By default, a deep copy is made.\n   If *deep* is false, the copy is shallow, i.e. ``pax_headers``\n   and any custom attributes are shared with the original ``TarInfo`` object.\n\nA :class:`TarInfo` object also provides some convenient query methods:\n\n\n.. method:: TarInfo.isfile()\n\n   Return :const:`True` if the :class:`Tarinfo` object is a regular file.\n\n\n.. method:: TarInfo.isreg()\n\n   Same as :meth:`isfile`.\n\n\n.. method:: TarInfo.isdir()\n\n   Return :const:`True` if it is a directory.\n\n\n.. method:: TarInfo.issym()\n\n   Return :const:`True` if it is a symbolic link.\n\n\n.. method:: TarInfo.islnk()\n\n   Return :const:`True` if it is a hard link.\n\n\n.. method:: TarInfo.ischr()\n\n   Return :const:`True` if it is a character device.\n\n\n.. method:: TarInfo.isblk()\n\n   Return :const:`True` if it is a block device.\n\n\n.. method:: TarInfo.isfifo()\n\n   Return :const:`True` if it is a FIFO.\n\n\n.. method:: TarInfo.isdev()\n\n   Return :const:`True` if it is one of character device, block device or FIFO.\n\n\n.. _tarfile-extraction-filter:\n\nExtraction filters\n------------------\n\n.. versionadded:: 3.12\n\nThe *tar* format is designed to capture all details of a UNIX-like filesystem,\nwhich makes it very powerful.\nUnfortunately, the features make it easy to create tar files that have\nunintended -- and possibly malicious -- effects when extracted.\nFor example, extracting a tar file can overwrite arbitrary files in various\nways (e.g.  by using absolute paths, ``..`` path components, or symlinks that\naffect later members).\n\nIn most cases, the full functionality is not needed.\nTherefore, *tarfile* supports extraction filters: a mechanism to limit\nfunctionality, and thus mitigate some of the security issues.\n\n.. seealso::\n\n   :pep:`706`\n      Contains further motivation and rationale behind the design.\n\nThe *filter* argument to :meth:`TarFile.extract` or :meth:`~TarFile.extractall`\ncan be:\n\n* the string ``'fully_trusted'``: Honor all metadata as specified in the\n  archive.\n  Should be used if the user trusts the archive completely, or implements\n  their own complex verification.\n\n* the string ``'tar'``: Honor most *tar*-specific features (i.e. features of\n  UNIX-like filesystems), but block features that are very likely to be\n  surprising or malicious. See :func:`tar_filter` for details.\n\n* the string ``'data'``: Ignore or block most features specific to UNIX-like\n  filesystems. Intended for extracting cross-platform data archives.\n  See :func:`data_filter` for details.\n\n* ``None`` (default): Use :attr:`TarFile.extraction_filter`.\n\n  If that is also ``None`` (the default), raise a ``DeprecationWarning``,\n  and fall back to the ``'fully_trusted'`` filter, whose dangerous behavior\n  matches previous versions of Python.\n\n  In Python 3.14, the ``'data'`` filter will become the default instead.\n  It's possible to switch earlier; see :attr:`TarFile.extraction_filter`.\n\n* A callable which will be called for each extracted member with a\n  :ref:`TarInfo <tarinfo-objects>` describing the member and the destination\n  path to where the archive is extracted (i.e. the same path is used for all\n  members)::\n\n      filter(member: TarInfo, path: str, /) -> TarInfo | None\n\n  The callable is called just before each member is extracted, so it can\n  take the current state of the disk into account.\n  It can:\n\n  - return a :class:`TarInfo` object which will be used instead of the metadata\n    in the archive, or\n  - return ``None``, in which case the member will be skipped, or\n  - raise an exception to abort the operation or skip the member,\n    depending on :attr:`~TarFile.errorlevel`.\n    Note that when extraction is aborted, :meth:`~TarFile.extractall` may leave\n    the archive partially extracted. It does not attempt to clean up.\n\nDefault named filters\n~~~~~~~~~~~~~~~~~~~~~\n\nThe pre-defined, named filters are available as functions, so they can be\nreused in custom filters:\n\n.. function:: fully_trusted_filter(member, path)\n\n   Return *member* unchanged.\n\n   This implements the ``'fully_trusted'`` filter.\n\n.. function:: tar_filter(member, path)\n\n  Implements the ``'tar'`` filter.\n\n  - Strip leading slashes (``/`` and :data:`os.sep`) from filenames.\n  - :ref:`Refuse <tarfile-extraction-refuse>` to extract files with absolute\n    paths (in case the name is absolute\n    even after stripping slashes, e.g. ``C:/foo`` on Windows).\n    This raises :class:`~tarfile.AbsolutePathError`.\n  - :ref:`Refuse <tarfile-extraction-refuse>` to extract files whose absolute\n    path (after following symlinks) would end up outside the destination.\n    This raises :class:`~tarfile.OutsideDestinationError`.\n  - Clear high mode bits (setuid, setgid, sticky) and group/other write bits\n    (:const:`~stat.S_IWGRP`|:const:`~stat.S_IWOTH`).\n\n  Return the modified ``TarInfo`` member.\n\n.. function:: data_filter(member, path)\n\n  Implements the ``'data'`` filter.\n  In addition to what ``tar_filter`` does:\n\n  - :ref:`Refuse <tarfile-extraction-refuse>` to extract links (hard or soft)\n    that link to absolute paths, or ones that link outside the destination.\n\n    This raises :class:`~tarfile.AbsoluteLinkError` or\n    :class:`~tarfile.LinkOutsideDestinationError`.\n\n    Note that such files are refused even on platforms that do not support\n    symbolic links.\n\n  - :ref:`Refuse <tarfile-extraction-refuse>` to extract device files\n    (including pipes).\n    This raises :class:`~tarfile.SpecialFileError`.\n\n  - For regular files, including hard links:\n\n    - Set the owner read and write permissions\n      (:const:`~stat.S_IRUSR`|:const:`~stat.S_IWUSR`).\n    - Remove the group & other executable permission\n      (:const:`~stat.S_IXGRP`|:const:`~stat.S_IXOTH`)\n      if the owner doesn’t have it (:const:`~stat.S_IXUSR`).\n\n  - For other files (directories), set ``mode`` to ``None``, so\n    that extraction methods skip applying permission bits.\n  - Set user and group info (``uid``, ``gid``, ``uname``, ``gname``)\n    to ``None``, so that extraction methods skip setting it.\n\n  Return the modified ``TarInfo`` member.\n\n\n.. _tarfile-extraction-refuse:\n\nFilter errors\n~~~~~~~~~~~~~\n\nWhen a filter refuses to extract a file, it will raise an appropriate exception,\na subclass of :class:`~tarfile.FilterError`.\nThis will abort the extraction if :attr:`TarFile.errorlevel` is 1 or more.\nWith ``errorlevel=0`` the error will be logged and the member will be skipped,\nbut extraction will continue.\n\n\nHints for further verification\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nEven with ``filter='data'``, *tarfile* is not suited for extracting untrusted\nfiles without prior inspection.\nAmong other issues, the pre-defined filters do not prevent denial-of-service\nattacks. Users should do additional checks.\n\nHere is an incomplete list of things to consider:\n\n* Extract to a :func:`new temporary directory <tempfile.mkdtemp>`\n  to prevent e.g. exploiting pre-existing links, and to make it easier to\n  clean up after a failed extraction.\n* When working with untrusted data, use external (e.g. OS-level) limits on\n  disk, memory and CPU usage.\n* Check filenames against an allow-list of characters\n  (to filter out control characters, confusables, foreign path separators,\n  etc.).\n* Check that filenames have expected extensions (discouraging files that\n  execute when you “click on them”, or extension-less files like Windows special device names).\n* Limit the number of extracted files, total size of extracted data,\n  filename length (including symlink length), and size of individual files.\n* Check for files that would be shadowed on case-insensitive filesystems.\n\nAlso note that:\n\n* Tar files may contain multiple versions of the same file.\n  Later ones are expected to overwrite any earlier ones.\n  This feature is crucial to allow updating tape archives, but can be abused\n  maliciously.\n* *tarfile* does not protect against issues with “live” data,\n  e.g. an attacker tinkering with the destination (or source) directory while\n  extraction (or archiving) is in progress.\n\n\nSupporting older Python versions\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nExtraction filters were added to Python 3.12, but may be backported to older\nversions as security updates.\nTo check whether the feature is available, use e.g.\n``hasattr(tarfile, 'data_filter')`` rather than checking the Python version.\n\nThe following examples show how to support Python versions with and without\nthe feature.\nNote that setting ``extraction_filter`` will affect any subsequent operations.\n\n* Fully trusted archive::\n\n    my_tarfile.extraction_filter = (lambda member, path: member)\n    my_tarfile.extractall()\n\n* Use the ``'data'`` filter if available, but revert to Python 3.11 behavior\n  (``'fully_trusted'``) if this feature is not available::\n\n    my_tarfile.extraction_filter = getattr(tarfile, 'data_filter',\n                                           (lambda member, path: member))\n    my_tarfile.extractall()\n\n* Use the ``'data'`` filter; *fail* if it is not available::\n\n    my_tarfile.extractall(filter=tarfile.data_filter)\n\n  or::\n\n    my_tarfile.extraction_filter = tarfile.data_filter\n    my_tarfile.extractall()\n\n* Use the ``'data'`` filter; *warn* if it is not available::\n\n   if hasattr(tarfile, 'data_filter'):\n       my_tarfile.extractall(filter='data')\n   else:\n       # remove this when no longer needed\n       warn_the_user('Extracting may be unsafe; consider updating Python')\n       my_tarfile.extractall()\n\n\nStateful extraction filter example\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nWhile *tarfile*'s extraction methods take a simple *filter* callable,\ncustom filters may be more complex objects with an internal state.\nIt may be useful to write these as context managers, to be used like this::\n\n    with StatefulFilter() as filter_func:\n        tar.extractall(path, filter=filter_func)\n\nSuch a filter can be written as, for example::\n\n    class StatefulFilter:\n        def __init__(self):\n            self.file_count = 0\n\n        def __enter__(self):\n            return self\n\n        def __call__(self, member, path):\n            self.file_count += 1\n            return member\n\n        def __exit__(self, *exc_info):\n            print(f'{self.file_count} files extracted')\n\n\n.. _tarfile-commandline:\n.. program:: tarfile\n\n\nCommand-Line Interface\n----------------------\n\n.. versionadded:: 3.4\n\nThe :mod:`tarfile` module provides a simple command-line interface to interact\nwith tar archives.\n\nIf you want to create a new tar archive, specify its name after the :option:`-c`\noption and then list the filename(s) that should be included:\n\n.. code-block:: shell-session\n\n    $ python -m tarfile -c monty.tar  spam.txt eggs.txt\n\nPassing a directory is also acceptable:\n\n.. code-block:: shell-session\n\n    $ python -m tarfile -c monty.tar life-of-brian_1979/\n\nIf you want to extract a tar archive into the current directory, use\nthe :option:`-e` option:\n\n.. code-block:: shell-session\n\n    $ python -m tarfile -e monty.tar\n\nYou can also extract a tar archive into a different directory by passing the\ndirectory's name:\n\n.. code-block:: shell-session\n\n    $ python -m tarfile -e monty.tar  other-dir/\n\nFor a list of the files in a tar archive, use the :option:`-l` option:\n\n.. code-block:: shell-session\n\n    $ python -m tarfile -l monty.tar\n\n\nCommand-line options\n~~~~~~~~~~~~~~~~~~~~\n\n.. cmdoption:: -l <tarfile>\n               --list <tarfile>\n\n   List files in a tarfile.\n\n.. cmdoption:: -c <tarfile> <source1> ... <sourceN>\n               --create <tarfile> <source1> ... <sourceN>\n\n   Create tarfile from source files.\n\n.. cmdoption:: -e <tarfile> [<output_dir>]\n               --extract <tarfile> [<output_dir>]\n\n   Extract tarfile into the current directory if *output_dir* is not specified.\n\n.. cmdoption:: -t <tarfile>\n               --test <tarfile>\n\n   Test whether the tarfile is valid or not.\n\n.. cmdoption:: -v, --verbose\n\n   Verbose output.\n\n.. cmdoption:: --filter <filtername>\n\n   Specifies the *filter* for ``--extract``.\n   See :ref:`tarfile-extraction-filter` for details.\n   Only string names are accepted (that is, ``fully_trusted``, ``tar``,\n   and ``data``).\n\n.. _tar-examples:\n\nExamples\n--------\n\nHow to extract an entire tar archive to the current working directory::\n\n   import tarfile\n   tar = tarfile.open(\"sample.tar.gz\")\n   tar.extractall(filter='data')\n   tar.close()\n\nHow to extract a subset of a tar archive with :meth:`TarFile.extractall` using\na generator function instead of a list::\n\n   import os\n   import tarfile\n\n   def py_files(members):\n       for tarinfo in members:\n           if os.path.splitext(tarinfo.name)[1] == \".py\":\n               yield tarinfo\n\n   tar = tarfile.open(\"sample.tar.gz\")\n   tar.extractall(members=py_files(tar))\n   tar.close()\n\nHow to create an uncompressed tar archive from a list of filenames::\n\n   import tarfile\n   tar = tarfile.open(\"sample.tar\", \"w\")\n   for name in [\"foo\", \"bar\", \"quux\"]:\n       tar.add(name)\n   tar.close()\n\nThe same example using the :keyword:`with` statement::\n\n    import tarfile\n    with tarfile.open(\"sample.tar\", \"w\") as tar:\n        for name in [\"foo\", \"bar\", \"quux\"]:\n            tar.add(name)\n\nHow to read a gzip compressed tar archive and display some member information::\n\n   import tarfile\n   tar = tarfile.open(\"sample.tar.gz\", \"r:gz\")\n   for tarinfo in tar:\n       print(tarinfo.name, \"is\", tarinfo.size, \"bytes in size and is \", end=\"\")\n       if tarinfo.isreg():\n           print(\"a regular file.\")\n       elif tarinfo.isdir():\n           print(\"a directory.\")\n       else:\n           print(\"something else.\")\n   tar.close()\n\nHow to create an archive and reset the user information using the *filter*\nparameter in :meth:`TarFile.add`::\n\n    import tarfile\n    def reset(tarinfo):\n        tarinfo.uid = tarinfo.gid = 0\n        tarinfo.uname = tarinfo.gname = \"root\"\n        return tarinfo\n    tar = tarfile.open(\"sample.tar.gz\", \"w:gz\")\n    tar.add(\"foo\", filter=reset)\n    tar.close()\n\n\n.. _tar-formats:\n\nSupported tar formats\n---------------------\n\nThere are three tar formats that can be created with the :mod:`tarfile` module:\n\n* The POSIX.1-1988 ustar format (:const:`USTAR_FORMAT`). It supports filenames\n  up to a length of at best 256 characters and linknames up to 100 characters.\n  The maximum file size is 8 GiB. This is an old and limited but widely\n  supported format.\n\n* The GNU tar format (:const:`GNU_FORMAT`). It supports long filenames and\n  linknames, files bigger than 8 GiB and sparse files. It is the de facto\n  standard on GNU/Linux systems. :mod:`tarfile` fully supports the GNU tar\n  extensions for long names, sparse file support is read-only.\n\n* The POSIX.1-2001 pax format (:const:`PAX_FORMAT`). It is the most flexible\n  format with virtually no limits. It supports long filenames and linknames, large\n  files and stores pathnames in a portable way. Modern tar implementations,\n  including GNU tar, bsdtar/libarchive and star, fully support extended *pax*\n  features; some old or unmaintained libraries may not, but should treat\n  *pax* archives as if they were in the universally supported *ustar* format.\n  It is the current default format for new archives.\n\n  It extends the existing *ustar* format with extra headers for information\n  that cannot be stored otherwise. There are two flavours of pax headers:\n  Extended headers only affect the subsequent file header, global\n  headers are valid for the complete archive and affect all following files.\n  All the data in a pax header is encoded in *UTF-8* for portability reasons.\n\nThere are some more variants of the tar format which can be read, but not\ncreated:\n\n* The ancient V7 format. This is the first tar format from Unix Seventh Edition,\n  storing only regular files and directories. Names must not be longer than 100\n  characters, there is no user/group name information. Some archives have\n  miscalculated header checksums in case of fields with non-ASCII characters.\n\n* The SunOS tar extended format. This format is a variant of the POSIX.1-2001\n  pax format, but is not compatible.\n\n.. _tar-unicode:\n\nUnicode issues\n--------------\n\nThe tar format was originally conceived to make backups on tape drives with the\nmain focus on preserving file system information. Nowadays tar archives are\ncommonly used for file distribution and exchanging archives over networks. One\nproblem of the original format (which is the basis of all other formats) is\nthat there is no concept of supporting different character encodings. For\nexample, an ordinary tar archive created on a *UTF-8* system cannot be read\ncorrectly on a *Latin-1* system if it contains non-*ASCII* characters. Textual\nmetadata (like filenames, linknames, user/group names) will appear damaged.\nUnfortunately, there is no way to autodetect the encoding of an archive. The\npax format was designed to solve this problem. It stores non-ASCII metadata\nusing the universal character encoding *UTF-8*.\n\nThe details of character conversion in :mod:`tarfile` are controlled by the\n*encoding* and *errors* keyword arguments of the :class:`TarFile` class.\n\n*encoding* defines the character encoding to use for the metadata in the\narchive. The default value is :func:`sys.getfilesystemencoding` or ``'ascii'``\nas a fallback. Depending on whether the archive is read or written, the\nmetadata must be either decoded or encoded. If *encoding* is not set\nappropriately, this conversion may fail.\n\nThe *errors* argument defines how characters are treated that cannot be\nconverted. Possible values are listed in section :ref:`error-handlers`.\nThe default scheme is ``'surrogateescape'`` which Python also uses for its\nfile system calls, see :ref:`os-filenames`.\n\nFor :const:`PAX_FORMAT` archives (the default), *encoding* is generally not needed\nbecause all the metadata is stored using *UTF-8*. *encoding* is only used in\nthe rare cases when binary pax headers are decoded or when strings with\nsurrogate characters are stored.\n",
            "rights": "Copyright (c) 2001 Python Software Foundation; All Rights Reserved. Raw RST unchanged. This reading aid adds selected quotations and agent-authored interpretation; no change to Python and no PSF endorsement. Complete license from the same release follows.\n\nA. HISTORY OF THE SOFTWARE\n==========================\n\nPython was created in the early 1990s by Guido van Rossum at Stichting\nMathematisch Centrum (CWI, see https://www.cwi.nl) in the Netherlands\nas a successor of a language called ABC.  Guido remains Python's\nprincipal author, although it includes many contributions from others.\n\nIn 1995, Guido continued his work on Python at the Corporation for\nNational Research Initiatives (CNRI, see https://www.cnri.reston.va.us)\nin Reston, Virginia where he released several versions of the\nsoftware.\n\nIn May 2000, Guido and the Python core development team moved to\nBeOpen.com to form the BeOpen PythonLabs team.  In October of the same\nyear, the PythonLabs team moved to Digital Creations, which became\nZope Corporation.  In 2001, the Python Software Foundation (PSF, see\nhttps://www.python.org/psf/) was formed, a non-profit organization\ncreated specifically to own Python-related Intellectual Property.\nZope Corporation was a sponsoring member of the PSF.\n\nAll Python releases are Open Source (see https://opensource.org for\nthe Open Source Definition).  Historically, most, but not all, Python\nreleases have also been GPL-compatible; the table below summarizes\nthe various releases.\n\n    Release         Derived     Year        Owner       GPL-\n                    from                                compatible? (1)\n\n    0.9.0 thru 1.2              1991-1995   CWI         yes\n    1.3 thru 1.5.2  1.2         1995-1999   CNRI        yes\n    1.6             1.5.2       2000        CNRI        no\n    2.0             1.6         2000        BeOpen.com  no\n    1.6.1           1.6         2001        CNRI        yes (2)\n    2.1             2.0+1.6.1   2001        PSF         no\n    2.0.1           2.0+1.6.1   2001        PSF         yes\n    2.1.1           2.1+2.0.1   2001        PSF         yes\n    2.1.2           2.1.1       2002        PSF         yes\n    2.1.3           2.1.2       2002        PSF         yes\n    2.2 and above   2.1.1       2001-now    PSF         yes\n\nFootnotes:\n\n(1) GPL-compatible doesn't mean that we're distributing Python under\n    the GPL.  All Python licenses, unlike the GPL, let you distribute\n    a modified version without making your changes open source.  The\n    GPL-compatible licenses make it possible to combine Python with\n    other software that is released under the GPL; the others don't.\n\n(2) According to Richard Stallman, 1.6.1 is not GPL-compatible,\n    because its license has a choice of law clause.  According to\n    CNRI, however, Stallman's lawyer has told CNRI's lawyer that 1.6.1\n    is \"not incompatible\" with the GPL.\n\nThanks to the many outside volunteers who have worked under Guido's\ndirection to make these releases possible.\n\n\nB. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON\n===============================================================\n\nPython software and documentation are licensed under the\nPython Software Foundation License Version 2.\n\nStarting with Python 3.8.6, examples, recipes, and other code in\nthe documentation are dual licensed under the PSF License Version 2\nand the Zero-Clause BSD license.\n\nSome software incorporated into Python is under different licenses.\nThe licenses are listed with code falling under that license.\n\n\nPYTHON SOFTWARE FOUNDATION LICENSE VERSION 2\n--------------------------------------------\n\n1. This LICENSE AGREEMENT is between the Python Software Foundation\n(\"PSF\"), and the Individual or Organization (\"Licensee\") accessing and\notherwise using this software (\"Python\") in source or binary form and\nits associated documentation.\n\n2. Subject to the terms and conditions of this License Agreement, PSF hereby\ngrants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,\nanalyze, test, perform and/or display publicly, prepare derivative works,\ndistribute, and otherwise use Python alone or in any derivative version,\nprovided, however, that PSF's License Agreement and PSF's notice of copyright,\ni.e., \"Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,\n2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Python Software Foundation;\nAll Rights Reserved\" are retained in Python alone or in any derivative version\nprepared by Licensee.\n\n3. In the event Licensee prepares a derivative work that is based on\nor incorporates Python or any part thereof, and wants to make\nthe derivative work available to others as provided herein, then\nLicensee hereby agrees to include in any such work a brief summary of\nthe changes made to Python.\n\n4. PSF is making Python available to Licensee on an \"AS IS\"\nbasis.  PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR\nIMPLIED.  BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND\nDISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS\nFOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT\nINFRINGE ANY THIRD PARTY RIGHTS.\n\n5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON\nFOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS\nA RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,\nOR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.\n\n6. This License Agreement will automatically terminate upon a material\nbreach of its terms and conditions.\n\n7. Nothing in this License Agreement shall be deemed to create any\nrelationship of agency, partnership, or joint venture between PSF and\nLicensee.  This License Agreement does not grant permission to use PSF\ntrademarks or trade name in a trademark sense to endorse or promote\nproducts or services of Licensee, or any third party.\n\n8. By copying, installing or otherwise using Python, Licensee\nagrees to be bound by the terms and conditions of this License\nAgreement.\n\n\nBEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0\n-------------------------------------------\n\nBEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1\n\n1. This LICENSE AGREEMENT is between BeOpen.com (\"BeOpen\"), having an\noffice at 160 Saratoga Avenue, Santa Clara, CA 95051, and the\nIndividual or Organization (\"Licensee\") accessing and otherwise using\nthis software in source or binary form and its associated\ndocumentation (\"the Software\").\n\n2. Subject to the terms and conditions of this BeOpen Python License\nAgreement, BeOpen hereby grants Licensee a non-exclusive,\nroyalty-free, world-wide license to reproduce, analyze, test, perform\nand/or display publicly, prepare derivative works, distribute, and\notherwise use the Software alone or in any derivative version,\nprovided, however, that the BeOpen Python License is retained in the\nSoftware, alone or in any derivative version prepared by Licensee.\n\n3. BeOpen is making the Software available to Licensee on an \"AS IS\"\nbasis.  BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR\nIMPLIED.  BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND\nDISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS\nFOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT\nINFRINGE ANY THIRD PARTY RIGHTS.\n\n4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE\nSOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS\nAS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY\nDERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.\n\n5. This License Agreement will automatically terminate upon a material\nbreach of its terms and conditions.\n\n6. This License Agreement shall be governed by and interpreted in all\nrespects by the law of the State of California, excluding conflict of\nlaw provisions.  Nothing in this License Agreement shall be deemed to\ncreate any relationship of agency, partnership, or joint venture\nbetween BeOpen and Licensee.  This License Agreement does not grant\npermission to use BeOpen trademarks or trade names in a trademark\nsense to endorse or promote products or services of Licensee, or any\nthird party.  As an exception, the \"BeOpen Python\" logos available at\nhttp://www.pythonlabs.com/logos.html may be used according to the\npermissions granted on that web page.\n\n7. By copying, installing or otherwise using the software, Licensee\nagrees to be bound by the terms and conditions of this License\nAgreement.\n\n\nCNRI LICENSE AGREEMENT FOR PYTHON 1.6.1\n---------------------------------------\n\n1. This LICENSE AGREEMENT is between the Corporation for National\nResearch Initiatives, having an office at 1895 Preston White Drive,\nReston, VA 20191 (\"CNRI\"), and the Individual or Organization\n(\"Licensee\") accessing and otherwise using Python 1.6.1 software in\nsource or binary form and its associated documentation.\n\n2. Subject to the terms and conditions of this License Agreement, CNRI\nhereby grants Licensee a nonexclusive, royalty-free, world-wide\nlicense to reproduce, analyze, test, perform and/or display publicly,\nprepare derivative works, distribute, and otherwise use Python 1.6.1\nalone or in any derivative version, provided, however, that CNRI's\nLicense Agreement and CNRI's notice of copyright, i.e., \"Copyright (c)\n1995-2001 Corporation for National Research Initiatives; All Rights\nReserved\" are retained in Python 1.6.1 alone or in any derivative\nversion prepared by Licensee.  Alternately, in lieu of CNRI's License\nAgreement, Licensee may substitute the following text (omitting the\nquotes): \"Python 1.6.1 is made available subject to the terms and\nconditions in CNRI's License Agreement.  This Agreement together with\nPython 1.6.1 may be located on the internet using the following\nunique, persistent identifier (known as a handle): 1895.22/1013.  This\nAgreement may also be obtained from a proxy server on the internet\nusing the following URL: http://hdl.handle.net/1895.22/1013\".\n\n3. In the event Licensee prepares a derivative work that is based on\nor incorporates Python 1.6.1 or any part thereof, and wants to make\nthe derivative work available to others as provided herein, then\nLicensee hereby agrees to include in any such work a brief summary of\nthe changes made to Python 1.6.1.\n\n4. CNRI is making Python 1.6.1 available to Licensee on an \"AS IS\"\nbasis.  CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR\nIMPLIED.  BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND\nDISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS\nFOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT\nINFRINGE ANY THIRD PARTY RIGHTS.\n\n5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON\n1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS\nA RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1,\nOR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.\n\n6. This License Agreement will automatically terminate upon a material\nbreach of its terms and conditions.\n\n7. This License Agreement shall be governed by the federal\nintellectual property law of the United States, including without\nlimitation the federal copyright law, and, to the extent such\nU.S. federal law does not apply, by the law of the Commonwealth of\nVirginia, excluding Virginia's conflict of law provisions.\nNotwithstanding the foregoing, with regard to derivative works based\non Python 1.6.1 that incorporate non-separable material that was\npreviously distributed under the GNU General Public License (GPL), the\nlaw of the Commonwealth of Virginia shall govern this License\nAgreement only as to issues arising under or with respect to\nParagraphs 4, 5, and 7 of this License Agreement.  Nothing in this\nLicense Agreement shall be deemed to create any relationship of\nagency, partnership, or joint venture between CNRI and Licensee.  This\nLicense Agreement does not grant permission to use CNRI trademarks or\ntrade name in a trademark sense to endorse or promote products or\nservices of Licensee, or any third party.\n\n8. By clicking on the \"ACCEPT\" button where indicated, or by copying,\ninstalling or otherwise using Python 1.6.1, Licensee agrees to be\nbound by the terms and conditions of this License Agreement.\n\n        ACCEPT\n\n\nCWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2\n--------------------------------------------------\n\nCopyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam,\nThe Netherlands.  All rights reserved.\n\nPermission to use, copy, modify, and distribute this software and its\ndocumentation for any purpose and without fee is hereby granted,\nprovided that the above copyright notice appear in all copies and that\nboth that copyright notice and this permission notice appear in\nsupporting documentation, and that the name of Stichting Mathematisch\nCentrum or CWI not be used in advertising or publicity pertaining to\ndistribution of the software without specific, written prior\npermission.\n\nSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO\nTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\nFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE\nFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\nWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\nACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT\nOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n\nZERO-CLAUSE BSD LICENSE FOR CODE IN THE PYTHON DOCUMENTATION\n----------------------------------------------------------------------\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.\n"
          }
        ],
        "response": "{\n  \"claims\": [\n    {\n      \"id\": \"C1\",\n      \"text\": \"In this documented release, leaving both the filter argument and extraction_filter at None emits a DeprecationWarning and falls back to fully_trusted. The documentation schedules a change to data in Python 3.14; do not treat the old default as a cross-version contract.\",\n      \"citations\": [\n        {\n          \"source\": \"S1\",\n          \"quote\": \"If that is also ``None`` (the default), raise a ``DeprecationWarning``,\\n  and fall back to the ``'fully_trusted'`` filter, whose dangerous behavior\\n  matches previous versions of Python.\\n\\n  In Python 3.14, the ``'data'`` filter will become the default instead.\"\n        }\n      ]\n    },\n    {\n      \"id\": \"C2\",\n      \"text\": \"A refusal/abort can leave a partially extracted archive; extractall does not clean that up. Application cleanup must be considered separately.\",\n      \"citations\": [\n        {\n          \"source\": \"S1\",\n          \"quote\": \"Note that when extraction is aborted, :meth:`~TarFile.extractall` may leave\\n    the archive partially extracted. It does not attempt to clean up.\"\n        }\n      ]\n    },\n    {\n      \"id\": \"C3\",\n      \"text\": \"The data filter is not sufficient for uninspected untrusted files. The documentation explicitly says the predefined filters do not prevent denial-of-service attacks and calls for additional checks.\",\n      \"citations\": [\n        {\n          \"source\": \"S1\",\n          \"quote\": \"Even with ``filter='data'``, *tarfile* is not suited for extracting untrusted\\nfiles without prior inspection.\\nAmong other issues, the pre-defined filters do not prevent denial-of-service\\nattacks. Users should do additional checks.\"\n        }\n      ]\n    }\n  ],\n  \"questions\": [\n    \"Which Python implementations and patched versions must the application support? The pinned document is not an inventory of deployed runtimes.\",\n    \"Does the application inspect archives and clean up a partially extracted destination? Documentation is not a security review of that application.\"\n  ]\n}",
        "notes": "Initial same-agent editorial review of real, pinned Python3.12.0 documentation. C1–C3 are supported under that source/version scope; no runtime execution is claimed. Keep this historical evidence before replacing S1 with the3.14.0 document. This is not an independent model sample, independent reviewer or production security audit."
      },
      "decisions": [
        {
          "id": "C1",
          "decision": "approve"
        },
        {
          "id": "C2",
          "decision": "approve"
        },
        {
          "id": "C3",
          "decision": "approve"
        }
      ]
    }
  ]
}
