[Python-checkins] python/dist/src/Lib StringIO.py,1.29,1.30

loewis at users.sourceforge.net loewis at users.sourceforge.net
Sat Oct 18 06:20:44 EDT 2003


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv18545/Lib

Modified Files:
	StringIO.py 
Log Message:
Patch #822994: Consolidate tests for self.closed.


Index: StringIO.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/StringIO.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** StringIO.py	31 Jan 2003 16:04:15 -0000	1.29
--- StringIO.py	18 Oct 2003 10:20:42 -0000	1.30
***************
*** 36,39 ****
--- 36,43 ----
  __all__ = ["StringIO"]
  
+ def _complain_ifclosed(closed):
+     if closed:
+         raise ValueError, "I/O operation on closed file"
+ 
  class StringIO:
      """class StringIO([buffer])
***************
*** 56,60 ****
          self.buflist = []
          self.pos = 0
!         self.closed = 0
          self.softspace = 0
  
--- 60,64 ----
          self.buflist = []
          self.pos = 0
!         self.closed = False
          self.softspace = 0
  
***************
*** 74,88 ****
          """
          if not self.closed:
!             self.closed = 1
              del self.buf, self.pos
  
      def isatty(self):
!         if self.closed:
!             raise ValueError, "I/O operation on closed file"
          return False
  
      def seek(self, pos, mode = 0):
!         if self.closed:
!             raise ValueError, "I/O operation on closed file"
          if self.buflist:
              self.buf += ''.join(self.buflist)
--- 78,90 ----
          """
          if not self.closed:
!             self.closed = True
              del self.buf, self.pos
  
      def isatty(self):
!         _complain_ifclosed(self.closed)
          return False
  
      def seek(self, pos, mode = 0):
!         _complain_ifclosed(self.closed)
          if self.buflist:
              self.buf += ''.join(self.buflist)
***************
*** 95,105 ****
  
      def tell(self):
!         if self.closed:
!             raise ValueError, "I/O operation on closed file"
          return self.pos
  
      def read(self, n = -1):
!         if self.closed:
!             raise ValueError, "I/O operation on closed file"
          if self.buflist:
              self.buf += ''.join(self.buflist)
--- 97,105 ----
  
      def tell(self):
!         _complain_ifclosed(self.closed)
          return self.pos
  
      def read(self, n = -1):
!         _complain_ifclosed(self.closed)
          if self.buflist:
              self.buf += ''.join(self.buflist)
***************
*** 114,119 ****
  
      def readline(self, length=None):
!         if self.closed:
!             raise ValueError, "I/O operation on closed file"
          if self.buflist:
              self.buf += ''.join(self.buflist)
--- 114,118 ----
  
      def readline(self, length=None):
!         _complain_ifclosed(self.closed)
          if self.buflist:
              self.buf += ''.join(self.buflist)
***************
*** 144,149 ****
  
      def truncate(self, size=None):
!         if self.closed:
!             raise ValueError, "I/O operation on closed file"
          if size is None:
              size = self.pos
--- 143,147 ----
  
      def truncate(self, size=None):
!         _complain_ifclosed(self.closed) 
          if size is None:
              size = self.pos
***************
*** 155,160 ****
  
      def write(self, s):
!         if self.closed:
!             raise ValueError, "I/O operation on closed file"
          if not s: return
          # Force s to be a string or unicode
--- 153,157 ----
  
      def write(self, s):
!         _complain_ifclosed(self.closed)
          if not s: return
          # Force s to be a string or unicode
***************
*** 186,191 ****
  
      def flush(self):
!         if self.closed:
!             raise ValueError, "I/O operation on closed file"
  
      def getvalue(self):
--- 183,187 ----
  
      def flush(self):
!         _complain_ifclosed(self.closed)
  
      def getvalue(self):





More information about the Python-checkins mailing list