python-xattr-compat: portable Python module to query and set POSIX extended attributes of files

This blog post is an announcement of python-xattr-compat, a portable Python 2.x module to query and set POSIX extended attributes of files.

python-xattr-compat is a wrapper around the xattr Python package, but if xattr is not available, python-xattr-compat provides compatible replacement implementations (using the dl or ctypes modules) for some systems (currently Linux), so we have a pure Python implementation for extended attribute manipulations.

How it works: Many scripting languages have a syscall function to call arbitrary system calls (like lsetxattr(2)). Python doesn't have syscall built in, but it has the dl and ctypes modules, which let the programmer call functions in any C library, lincluding libc. Since libc on Linux has wrappers for syscall and lsetxattr etc., we can call these to get system-specific extended attribute manipulation without installing non-built-in Python extensions like xattr.

No comments: