Python Glossary Русский

Python 3.12+tarfileexception

tarfile.AbsolutePathError

exceptions

The extraction filter exception for a member with an absolute path that cannot be made relative.

Syntax

except tarfile.AbsolutePathError:

On Linux and macOS you will hardly ever see it: the 'data' and 'tar' filters silently strip a leading '/' and extract '/etc/x' as 'etc/x' inside the target folder. The exception remains for names still absolute after stripping — for example 'C:/x' on Windows. It is a FilterError subclass.

Examples

import tarfile
m = tarfile.TarInfo('/etc/app.conf')
print(tarfile.data_filter(m, 'out').name)  # → etc/app.conf — '/' срезан
err = tarfile.AbsolutePathError(tarfile.TarInfo('C:/x'))
print(err)  # → member 'C:/x' has an absolute path
print(issubclass(tarfile.AbsolutePathError, tarfile.FilterError))  # → True

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy