Python Glossary Русский

Python 3.12+tarfileexception

tarfile.SpecialFileError

exceptions

The 'data' filter exception for a member that is a special file (a device or a named pipe).

Syntax

except tarfile.SpecialFileError:

Devices and FIFOs have no business in a data archive, and an extracted pipe can hang any program that tries to read it. The 'tar' filter lets such members through (only root can create a device anyway), while 'data' refuses them with this exception.

Examples

import tarfile
fifo = tarfile.TarInfo('pipe')
fifo.type = tarfile.FIFOTYPE
print(tarfile.tar_filter(fifo, 'out').name)  # → pipe — 'tar' пропускает
try:
    tarfile.data_filter(fifo, 'out')
except tarfile.SpecialFileError as e:
    print(e)  # → 'pipe' is a special file

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy