Package logilab-common-0 :: Package 39 :: Package 0 :: Module fileutils :: Class ProtectedFile
[frames] | no frames]

Class ProtectedFile

source code

object --+    
         |    
      file --+
             |
            ProtectedFile

A special file-object class that automatically 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 obejct

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

Instance Methods
file object
__init__(self, filepath, mode)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
None or (perhaps) an integer
close(self)
restore mode before closing
source code
 
__del__(self) source code

Inherited from file: __delattr__, __enter__, __exit__, __getattribute__, __iter__, __new__, __repr__, __setattr__, fileno, flush, isatty, next, read, readinto, readline, readlines, seek, tell, truncate, write, writelines, xreadlines

Inherited from object: __format__, __hash__, __reduce__, __reduce_ex__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from file: closed, encoding, errors, mode, name, newlines, softspace

Inherited from object: __class__

Method Details

__init__(self, filepath, mode)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Returns: file object
Overrides: object.__init__
(inherited documentation)

close(self)

source code 
restore mode before closing

Returns: None or (perhaps) an integer
Overrides: file.close