~ubuntu-dev/wxwidgets2.6/upstream-debian

« back to all changes in this revision

Viewing changes to wxPython/wx/py/document.py

  • Committer: Daniel T Chen
  • Date: 2006-06-26 10:15:11 UTC
  • Revision ID: crimsun@ubuntu.com-20060626101511-a4436cec4c6d9b35
ImportĀ DebianĀ 2.6.3.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Document class."""
 
2
 
 
3
__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
 
4
__cvsid__ = "$Id: document.py,v 1.5 2004/02/13 02:47:58 PKO Exp $"
 
5
__revision__ = "$Revision: 1.5 $"[11:-2]
 
6
 
 
7
import os
 
8
 
 
9
 
 
10
class 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()