Package logilab :: Package common :: Module fileutils :: Class ProtectedFile

[frames] | no frames]

# Class ProtectedFile

source code

    compat.FileIO --+
                    |
                   ProtectedFile

    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.
    One way to circumvent this would be to chmod / unchmod on each
    write operation.

    One other way would be to :

    - catch the IOError in the __init__

    - if IOError, then create a StringIO object

    - each write operation writes in this StringIO object

    - on close()/del(), write/append the StringIO content to the file and
      do the chmod only once

Instance Methods

__init__(self, filepath, mode) | source code

close(self) restore mode before closing | source code

__del__(self) | source code