Show More
@@ -139,15 +139,22 b' class abstractopener(object):' | |||||
139 | '''Prevent instantiation; don't call this from subclasses.''' |
|
139 | '''Prevent instantiation; don't call this from subclasses.''' | |
140 | raise NotImplementedError('attempted instantiating ' + str(type(self))) |
|
140 | raise NotImplementedError('attempted instantiating ' + str(type(self))) | |
141 |
|
141 | |||
142 |
def read(self, |
|
142 | def read(self, path): | |
143 |
fp = self( |
|
143 | fp = self(path, 'rb') | |
144 | try: |
|
144 | try: | |
145 | return fp.read() |
|
145 | return fp.read() | |
146 | finally: |
|
146 | finally: | |
147 | fp.close() |
|
147 | fp.close() | |
148 |
|
148 | |||
149 |
def write(self, |
|
149 | def write(self, path, data): | |
150 |
fp = self( |
|
150 | fp = self(path, 'wb') | |
|
151 | try: | |||
|
152 | return fp.write(data) | |||
|
153 | finally: | |||
|
154 | fp.close() | |||
|
155 | ||||
|
156 | def append(self, path, data): | |||
|
157 | fp = self(path, 'ab') | |||
151 | try: |
|
158 | try: | |
152 | return fp.write(data) |
|
159 | return fp.write(data) | |
153 | finally: |
|
160 | finally: |
@@ -778,8 +778,15 b' def readfile(path):' | |||||
778 | finally: |
|
778 | finally: | |
779 | fp.close() |
|
779 | fp.close() | |
780 |
|
780 | |||
781 |
def writefile(path, |
|
781 | def writefile(path, text): | |
782 |
fp = open(path, |
|
782 | fp = open(path, 'wb') | |
|
783 | try: | |||
|
784 | fp.write(text) | |||
|
785 | finally: | |||
|
786 | fp.close() | |||
|
787 | ||||
|
788 | def appendfile(path, text): | |||
|
789 | fp = open(path, 'ab') | |||
783 | try: |
|
790 | try: | |
784 | fp.write(text) |
|
791 | fp.write(text) | |
785 | finally: |
|
792 | finally: |
General Comments 0
You need to be logged in to leave comments.
Login now