Mercurial > ~astiob > upreckon > hgweb
changeset 132:cdd0f970d112
Fixed several small bugs in the files module
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Thu, 19 May 2011 02:55:36 +0100 |
parents | 7923faf392fe |
children | a9d2aa6810c7 |
files | files.py |
diffstat | 1 files changed, 12 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/files.py Thu May 19 02:24:59 2011 +0100 +++ b/files.py Thu May 19 02:55:36 2011 +0100 @@ -45,7 +45,10 @@ def extract(self, name, target): raise NotImplementedError def __del__(self): - del self.file + try: + del self.file + except NameError: + pass try: import tarfile @@ -53,7 +56,7 @@ TarArchive = None else: class TarArchive(Archive): - __slots__ = '__namelist' + __slots__ = '_namelist' def __init__(self, path): self.file = tarfile.open(path) @@ -68,15 +71,15 @@ return self.file.extractfile(name) def exists(self, queried_name): - if not hasattr(self, '__namelist'): + if not hasattr(self, '_namelist'): names = set() for name in self.file.getnames(): cutname = name while cutname: names.add(cutname) cutname = cutname.rpartition('/')[0] - self.__namelist = frozenset(names) - return queried_name in self.__namelist + self._namelist = frozenset(names) + return queried_name in self._namelist def __enter__(self): if hasattr(self.file, '__enter__'): @@ -102,7 +105,7 @@ ZipArchive = None else: class ZipArchive(Archive): - __slots__ = '__namelist' + __slots__ = '_namelist' def __init__(self, path): self.file = zipfile.ZipFile(path) @@ -123,15 +126,15 @@ return self.file.open(name, 'rU') def exists(self, queried_name): - if not hasattr(self, '__namelist'): + if not hasattr(self, '_namelist'): names = set() for name in self.file.namelist(): cutname = name while cutname: names.add(cutname) cutname = cutname.rpartition('/')[0] - self.__namelist = frozenset(names) - return queried_name in self.__namelist + self._namelist = frozenset(names) + return queried_name in self._namelist def __enter__(self): if hasattr(self.file, '__enter__'):