Update of /cvsroot/docstring/dps/dps/writers
In directory usw-pr-cvs1:/tmp/cvs-serv8841/dps/dps/writers
Modified Files:
__init__.py
Log Message:
progress
Index: __init__.py
===================================================================
RCS file: /cvsroot/docstring/dps/dps/writers/__init__.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** __init__.py 2002/02/06 02:56:21 1.1
--- __init__.py 2002/02/07 01:58:29 1.2
***************
*** 16,19 ****
--- 16,22 ----
+ import sys
+
+
class Writer:
***************
*** 24,27 ****
--- 27,62 ----
"""
+ def write(self, document, destination):
+ self.document = document
+ self.destination = destination
+ self.transform()
+ self.record(self.document, self.destination)
+
+ def transform(self):
+ """Override to run document tree transforms."""
+ raise NotImplementedError('subclass must override this method')
+
+ def record(self, document, destination):
+ """Override to record `document` to `destination`."""
+ raise NotImplementedError('subclass must override this method')
+
+ def recordfile(self, output, destination):
+ """
+ Write `output` to a single file.
+
+ Parameters:
+ - `output`: Data to write.
+ - `destination`: one of:
+
+ (a) a file-like object, which is written directly;
+ (b) a path to a file, which is opened and then written; or
+ (c) `None`, which implies `sys.stdout`.
+ """
+ if hasattr(self.destination, 'write'):
+ destination.write(output)
+ elif self.destination:
+ open(self.destination, 'w').write(output)
+ else:
+ sys.stdout.write(output)
pass
|