I was thinking about the new IOStack and could not come up with an use case requiring both a line-oriented and a record-oriented read/write functionality -- the general case is the record-oriented, lines are just new-line terminated records. Perhaps this has already been dropped, but I seem to recall the original spec having a readrec, writerec? Similarly, readline/writeline aren't needed. For example...
<br><br>class InputStream(Stream):<br> def read(self): # Reads 1 byte<br> return os.stdin.read(1)<br> <br> def readline(self):<br>
ret = self.readrec('\n') # or whatever constant represents the EOL<br>
return ret<br>
<br>class Stream(object):<br> def read(self): <br> raise Exception, 'cannot read'<br><br> def readrec(self,terminator):<br>
ret = ''<br>
while ret != terminator: ret = ret + self.read()<br>
return ret<br><br> def write(self):<br>
raise Exception, 'cannot write'<br>
<br> def writeRec(self, terminator):<br> ''' writeRec returns self as a list split by terminator '''<br> ret = str(self)<br> return str(ret).split(terminator)<br>-- <br>Cheers,<br>Hasan Diwan <<a href="mailto:hasan.diwan@gmail.com">
hasan.diwan@gmail.com</a>>