diff options
author | Emile Anclin <emile.anclin@logilab.fr> | 2010-09-21 15:15:12 +0200 |
---|---|---|
committer | Emile Anclin <emile.anclin@logilab.fr> | 2010-09-21 15:15:12 +0200 |
commit | a0eda8dbc8e3f35facfcdebde8af7bd15ac95ec0 (patch) | |
tree | bd32ac03b244f3c2d63fcffe7962c6a104f3cece | |
parent | d23c7d3b2c27ab14a821ebe4aed8095d6a0fdeaa (diff) | |
download | logilab-common-a0eda8dbc8e3f35facfcdebde8af7bd15ac95ec0.tar.gz |
[py3k] file is replaced in 3k by some io class
-rw-r--r-- | compat.py | 7 | ||||
-rw-r--r-- | fileutils.py | 12 |
2 files changed, 14 insertions, 5 deletions
@@ -43,6 +43,13 @@ if sys.version_info < (3, 0): else: raw_input = input +if sys.version_info < (3, 0): + FileIO = file +else: + import io + FileIO = io.FileIO + del io + try: set = set frozenset = frozenset diff --git a/fileutils.py b/fileutils.py index 86a83a4..807f2b5 100644 --- a/fileutils.py +++ b/fileutils.py @@ -36,6 +36,7 @@ from cStringIO import StringIO from logilab.common import STD_BLACKLIST as BASE_BLACKLIST, IGNORED_EXTENSIONS from logilab.common.shellutils import find +from logilab.common.compat import FileIO def first_level_directory(path): """Return the first level directory of a path. @@ -123,9 +124,10 @@ def ensure_fs_mode(filepath, desired_mode=S_IWRITE): chmod(filepath, mode | desired_mode) -class ProtectedFile(file): - """A special file-object class that automatically that automatically - does a 'chmod +w' when needed. +# XXX (syt) unused? kill? +class ProtectedFile(FileIO): + """A special file-object class that automatically does a 'chmod +w' when + needed. XXX: for now, the way it is done allows 'normal file-objects' to be created during the ProtectedFile object lifetime. @@ -150,7 +152,7 @@ class ProtectedFile(file): if not self.original_mode & S_IWRITE: chmod(filepath, self.original_mode | S_IWRITE) self.mode_changed = True - file.__init__(self, filepath, mode) + FileIO.__init__(self, filepath, mode) def _restore_mode(self): """restores the original mode if needed""" @@ -162,7 +164,7 @@ class ProtectedFile(file): def close(self): """restore mode before closing""" self._restore_mode() - file.close(self) + FileIO.close(self) def __del__(self): if not self.closed: |