[Python-3000] iostack, second revision

Hasan Diwan hasan.diwan at gmail.com
Fri Sep 8 02:41:30 CEST 2006


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...

class InputStream(Stream):
   def read(self): # Reads 1 byte
       return os.stdin.read(1)

   def readline(self):
       ret = self.readrec('\n') # or whatever constant represents the EOL
       return ret

class Stream(object):
   def read(self):
       raise Exception, 'cannot read'

   def readrec(self,terminator):
       ret = ''
       while ret != terminator: ret = ret + self.read()
       return ret

   def write(self):
       raise Exception, 'cannot write'

   def writeRec(self, terminator):
       ''' writeRec returns self as a list split by terminator '''
       ret = str(self)
       return str(ret).split(terminator)
-- 
Cheers,
Hasan Diwan <hasan.diwan at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20060907/2769816f/attachment.htm 


More information about the Python-3000 mailing list