root/masterdriverz/snakeoil-formatters/snakeoil/tar.py @ ferringb%2540gmail.com-20070211125906-1gj7u78ll14fnaut

Revision ferringb%2540gmail.com-20070211125906-1gj7u78ll14fnaut, 1.0 kB (checked in by Brian Harring <ferringb@…>, 2 years ago)

fresh reimport, dropping history from pkgcore (no point in lugging around 10+ mb of unrelated bzr history)

Line 
1# Copyright: 2006 Brian Harring <ferringb@gmail.com>
2# License: GPL2
3
4"""
5tar file access
6
7monkey patching of stdlib tarfile to reduce mem usage (33% reduction).
8
9note this is also racey; N threads trying an import, if they're after
10the *original* tarfile, they may inadvertantly get ours.
11"""
12
13import sys
14t = sys.modules.pop("tarfile", None)
15tarfile = __import__("tarfile")
16if t is not None:
17    sys.modules["tarfile"] = t
18else:
19    del sys.modules["tarfile"]
20del t
21# ok, we now have our own local copy to monkey patch
22
23class TarInfo(tarfile.TarInfo):
24    __slots__ = (
25        "name", "mode", "uid", "gid", "size", "mtime", "chksum", "type",
26        "linkname", "uname", "gname", "devmajor", "devminor", "prefix",
27        "offset", "offset_data", "buf", "sparse", "_link_target")
28
29tarfile.TarInfo = TarInfo
30# finished monkey patching. now to lift things out of our tarfile
31# module into this scope so from/import behaves properly.
32
33for x in tarfile.__all__:
34    locals()[x] = getattr(tarfile, x)
35del x
Note: See TracBrowser for help on using the browser.