commit: fe073c81f8b5826740a1a6e922f004aa8e79a8e6
Author: Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Wed Dec 10 10:08:04 2025 +0000
Commit: Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Wed Dec 10 11:10:59 2025 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=fe073c81
chore: deprecate tarfile, and drop tarfile.TarInfo since it's upstream already.
Now, this module only exists to add the .handler_exceptions field
that snakeoil.data_sources use, something that will be removed.
Signed-off-by: Brian Harring <ferringb <AT> gmail.com>
src/snakeoil/tar.py | 121 ++++++----------------------------------------------
1 file changed, 14 insertions(+), 107 deletions(-)
diff --git a/src/snakeoil/tar.py b/src/snakeoil/tar.py
index 9cae35b..0dc739c 100644
--- a/src/snakeoil/tar.py
+++ b/src/snakeoil/tar.py
@@ -1,125 +1,32 @@
-"""
-fixed up Tarfile implementation
-
-Specifically this grabs a copy of :py:mod:`tarfile` and applies a set of
-modifications- roughly a 33% memory reduction in usage
-
-Note that this modules initial setup semantics are technically racy- if the
-python implementation allows for the GIL to be swapped to a different thread
-during tarfile import (at literally the exact right moment) this version
-can bleed through. Extremely unlikely chance (haven't managed to even trigger
-it once yet), but the potential seems to be there.
+"""Version of tarfile modified strictly for snakeoil.data_sources usage.
-In usage, instead of importing tarfile you should just import this module
-instead. It's intended to be a drop in replacement.
+This is deprecated. Use the actual python tarfile module, what this fixed is
now in upstream.
"""
-import sys
-
-t = sys.modules.pop("tarfile", None)
-tarfile = __import__("tarfile")
-if t is not None:
- sys.modules["tarfile"] = t
-else:
- del sys.modules["tarfile"]
-del t
-# ok, we now have our own local copy to monkey patch
-
-
-class TarInfo(tarfile.TarInfo):
- """
- Customized TarInfo implementation.
-
- Note that this implementation has a locked down set of __slots__. The
slotting
- doesn't remove the underlying Dict being created (which we still pay
memory for),
- but via using __slots__ we no longer pay the overallocation cost of dicts
per
- TarInfo instance.
-
- :ivar buf: deletion and setting are disallowed in this implementation.
- This is done primarily to avoid having to have >512 bytes per TarInfo
- object.
- :ivar gname: same as TarInfo.gname, just interned via a property.
- :ivar uname: same as TarInfo.uname, just interned via a property.
- """
-
- if not hasattr(tarfile.TarInfo, "__slots__"):
- __slots__ = (
- "name",
- "mode",
- "uid",
- "gid",
- "size",
- "mtime",
- "chksum",
- "type",
- "linkname",
- "_uname",
- "_gname",
- "devmajor",
- "devminor",
- "prefix",
- "offset",
- "offset_data",
- "_buf",
- "sparse",
- "_link_target",
- )
- else:
- __slots__ = ("_buf", "_uname", "_gname")
-
- def get_buf(self):
- return self.tobuf()
+from snakeoil._internals import deprecated
+from snakeoil.python_namespaces import protect_imports
- def set_buf(self, val):
- """
- the ability to set the buffer is disabled in this
- patched version
- """
+deprecated.module(
+ "This is fully deprecated. Use pkgcore.fs.tar functionality",
+ qualname="snakeoil.tar",
+)
- def del_buf(self):
- """
- the ability to delete the buffer is disabled in this
- patched version
- """
- buf = property(get_buf, set_buf, del_buf)
-
- def get_gname(self):
- return self._gname
-
- def set_gname(self, val):
- self._gname = sys.intern(val)
-
- def del_gname(self):
- del self._gname
-
- gname = property(get_gname, set_gname)
-
- def get_uname(self):
- return self._uname
-
- def set_uname(self, val):
- self._uname = sys.intern(val)
-
- def del_uname(self):
- del self._uname
-
- uname = property(get_uname, set_uname)
+# force a fresh module import of tarfile that is ours to monkey patch.
+with protect_imports() as (_paths, modules):
+ modules.pop("tarfile", None)
+ tarfile = __import__("tarfile")
# add in a tweaked ExFileObject that is usable by snakeoil.data_source
class ExFileObject(tarfile.ExFileObject):
+ __slots__ = ()
exceptions = (EnvironmentError,)
tarfile.fileobject = ExFileObject
-
-tarfile.TarInfo = TarInfo
# finished monkey patching. now to lift things out of our tarfile
# module into this scope so from/import behaves properly.
-for x in tarfile.__all__:
- locals()[x] = getattr(tarfile, x)
-# pylint: disable=undefined-loop-variable
-del x
+locals().update((k, getattr(tarfile, k)) for k in tarfile.__all__)