[Python-checkins] CVS: python/dist/src/Lib StringIO.py,1.12,1.13

Barry Warsaw python-dev@python.org
Tue, 12 Dec 2000 15:12:26 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv18874

Modified Files:
	StringIO.py 
Log Message:
Accept Finn Bock's patch #102208 to hardcode EINVAL to 22 when errno
can't be imported.  This makes StringIO.py work with Jython.

Also, get rid of the string module by converting to string methods.

Shorten some lines by using augmented assignment where appropriate.


Index: StringIO.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/StringIO.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** StringIO.py	2000/10/12 16:45:37	1.12
--- StringIO.py	2000/12/12 23:12:23	1.13
***************
*** 30,36 ****
  """
  
! import errno
! import string
  
  class StringIO:
  	def __init__(self, buf = ''):
--- 30,40 ----
  """
  
! try:
! 	from errno import EINVAL
! except ImportError:
! 	EINVAL = 22
  
+ EMPTYSTRING = ''
+ 
  class StringIO:
  	def __init__(self, buf = ''):
***************
*** 53,62 ****
  			raise ValueError, "I/O operation on closed file"
  		if self.buflist:
! 			self.buf = self.buf + string.joinfields(self.buflist, '')
  			self.buflist = []
  		if mode == 1:
! 			pos = pos + self.pos
  		elif mode == 2:
! 			pos = pos + self.len
  		self.pos = max(0, pos)
  	def tell(self):
--- 57,66 ----
  			raise ValueError, "I/O operation on closed file"
  		if self.buflist:
! 			self.buf += EMPTYSTRING.join(self.buflist)
  			self.buflist = []
  		if mode == 1:
! 			pos += self.pos
  		elif mode == 2:
! 			pos += self.len
  		self.pos = max(0, pos)
  	def tell(self):
***************
*** 68,72 ****
  			raise ValueError, "I/O operation on closed file"
  		if self.buflist:
! 			self.buf = self.buf + string.joinfields(self.buflist, '')
  			self.buflist = []
  		if n < 0:
--- 72,76 ----
  			raise ValueError, "I/O operation on closed file"
  		if self.buflist:
! 			self.buf += EMPTYSTRING.join(self.buflist)
  			self.buflist = []
  		if n < 0:
***************
*** 81,87 ****
  			raise ValueError, "I/O operation on closed file"
  		if self.buflist:
! 			self.buf = self.buf + string.joinfields(self.buflist, '')
  			self.buflist = []
! 		i = string.find(self.buf, '\n', self.pos)
  		if i < 0:
  			newpos = self.len
--- 85,91 ----
  			raise ValueError, "I/O operation on closed file"
  		if self.buflist:
! 			self.buf += EMPTYSTRING.join(self.buflist)
  			self.buflist = []
! 		i = self.buf.find('\n', self.pos)
  		if i < 0:
  			newpos = self.len
***************
*** 111,116 ****
  			size = self.pos
  		elif size < 0:
! 			raise IOError(errno.EINVAL,
!                                       "Negative size not allowed")
  		elif size < self.pos:
  			self.pos = size
--- 115,119 ----
  			size = self.pos
  		elif size < 0:
! 			raise IOError(EINVAL, "Negative size not allowed")
  		elif size < self.pos:
  			self.pos = size
***************
*** 126,130 ****
  		if self.pos < self.len:
  			if self.buflist:
! 				self.buf = self.buf + string.joinfields(self.buflist, '')
  				self.buflist = []
  			self.buflist = [self.buf[:self.pos], s, self.buf[newpos:]]
--- 129,133 ----
  		if self.pos < self.len:
  			if self.buflist:
! 				self.buf += EMPTYSTRING.join(self.buflist)
  				self.buflist = []
  			self.buflist = [self.buf[:self.pos], s, self.buf[newpos:]]
***************
*** 137,141 ****
  		self.pos = newpos
  	def writelines(self, list):
! 		self.write(string.joinfields(list, ''))
  	def flush(self):
  		if self.closed:
--- 140,144 ----
  		self.pos = newpos
  	def writelines(self, list):
! 		self.write(EMPTYSTRING.join(list))
  	def flush(self):
  		if self.closed:
***************
*** 143,147 ****
  	def getvalue(self):
  		if self.buflist:
! 			self.buf = self.buf + string.joinfields(self.buflist, '')
  			self.buflist = []
  		return self.buf
--- 146,150 ----
  	def getvalue(self):
  		if self.buflist:
! 			self.buf += EMPTYSTRING.join(self.buflist)
  			self.buflist = []
  		return self.buf