[Python-3000] socket GC worries

Bill Janssen janssen at parc.com
Mon Oct 29 20:46:14 CET 2007


> Actually, I'm still up for tweaks to the I/O model if it solves a real
> problem, as long as most of the high-level APIs stay the same (there
> simply is too much code that expects those to behave a certain way).
>
> I don't quite understand what you mean by inverted though.

I'm actually thinking more in terms of avoiding future problems.  I
thought we'd discussed this a few months ago, but here it is again:

I'd break up the BaseIO class into a small set of base classes, so that
we can be more explicit about what a particular kind of I/O channel is
or is not:

(Please excuse typos, I'm generating this off-the-cuff -- does
@abstract actually exist?)

-------------------------------------------------------------

class IOStream:

   @abstract
   def close(self):

   @property
   def closed(self):

class InputIOStream (IOStream):

   @abstract
   def read(self, buffer=None, nbytes=None):

class OutputIOStream (IOStream):

   @abstract
   def write(self, bytes):

   @abstract
   def flush(self):

class SeekableIOStream (IOStream):

   @abstract
   def tell(self):

   @abstract
   def seek(self):

   @abstract
   def truncate(self):

class SystemIOStream (IOStream):

   @property
   def fileno(self):

   @property
   def isatty (self):

class TextInputStream (InputIOStream):

   @abstract
   def readline(self):

   @abstract
   def readlines(self):

class TextOutputStream (InputIOStream):

   @abstract
   def readline(self):

   @abstract
   def readlines(self):

class FileStream (SystemIOStream, SeekableIOStream):

   @property
   name

   @property
   mode

# note that open() would return FileStream mixed with one or both of
# {Text}InputStream and {Text}OutputStream, depending on the "mode".

class StringIO (SeekableIOStream):

# again, mixed with IO modes, depending on "mode".

-------------------------------------------------------------

I think of this as inverted, because it puts primitives like "read"
and "write" at the lowest layers, not above things like "fileno" or
"truncate", which are very specialized and should only apply to a
subset of I/O channels.

I realize that there are some practical problems with this; such as
making _fileio.FileIO inherit from (multiple) Python base classes.

Bill





More information about the Python-3000 mailing list