File whose text can be manipulated, transactionally
Example:
myfile = EditableFile(self, filename="something")
print myfile.text # prints current contents of file
# Edit the file
storage.beginTransaction(self)
myfile.text = myfile.text.replace('foo','bar')
storage.commitTransaction(self)
Values assigned to text will be converted to strings. Setting text
to an empty string truncates the file; deleting text (i.e.
del myfile.text ) deletes the file. text will be None whenever the
file is nonexistent, but do not set it to None unless you want to replace
the file's contents with the string "None" !
By default, files are read and written in "text" mode; be sure to supply
a fileType="b" keyword argument if you are editing a binary file. Note
that under Python 2.3 you can also specify fileType="U" to use "universal
newline" mode.
EditableFile subclasses TxnFile , but does not use autocommit mode,
because it wants to support "safe" alterations to existing files.
|