]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/py/document.py
'[1219035] cleanup: miscellaneous' and minor source cleaning.
[wxWidgets.git] / wxPython / wx / py / document.py
CommitLineData
d14a1e28 1"""Document class."""
1fded56b 2
d14a1e28
RD
3__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
4__cvsid__ = "$Id$"
5__revision__ = "$Revision$"[11:-2]
1fded56b 6
d14a1e28
RD
7import os
8
d14a1e28
RD
9
10class Document:
11 """Document class."""
12
13 def __init__(self, filename=None):
14 """Create a Document instance."""
15 self.filename = filename
16 self.filepath = None
17 self.filedir = None
18 self.filebase = None
19 self.fileext = None
20 if self.filename:
21 self.filepath = os.path.realpath(self.filename)
22 self.filedir, self.filename = os.path.split(self.filepath)
23 self.filebase, self.fileext = os.path.splitext(self.filename)
24
25 def read(self):
26 """Return contents of file."""
27 if self.filepath and os.path.exists(self.filepath):
28 f = file(self.filepath, 'rb')
29 try:
30 return f.read()
31 finally:
32 f.close()
33 else:
34 return ''
35
36 def write(self, text):
37 """Write text to file."""
38 try:
39 f = file(self.filepath, 'wb')
40 f.write(text)
41 finally:
42 if f:
43 f.close()