[Python-checkins] python/dist/src/Lib/lib-old Para.py, 1.7, 1.8 addpack.py, 1.1, 1.2 codehack.py, 1.6, 1.7 dump.py, 1.2, 1.3 find.py, 1.1, 1.2 fmt.py, 1.6, 1.7 grep.py, 1.10, 1.11 lockfile.py, 1.2, 1.3 newdir.py, 1.5, 1.6 packmail.py, 1.10, 1.11 poly.py, 1.2, 1.3 rand.py, 1.2, 1.3 tb.py, 1.9, 1.10 util.py, 1.4, 1.5 zmod.py, 1.2, 1.3

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Sun Jul 18 08:15:18 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib/lib-old
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31286/lib-old

Modified Files:
	Para.py addpack.py codehack.py dump.py find.py fmt.py grep.py 
	lockfile.py newdir.py packmail.py poly.py rand.py tb.py 
	util.py zmod.py 
Log Message:
Whitespace normalization, via reindent.py.


Index: Para.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/Para.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** Para.py	12 Dec 2000 23:11:41 -0000	1.7
--- Para.py	18 Jul 2004 06:14:43 -0000	1.8
***************
*** 1,3 ****
! # Text formatting abstractions 
  # Note -- this module is obsolete, it's too slow anyway
  
--- 1,3 ----
! # Text formatting abstractions
  # Note -- this module is obsolete, it's too slow anyway
  
***************
*** 15,343 ****
  # for mouse hits, and parts of the text can be highlighted
  class Para:
! 	#
! 	def __init__(self):
! 		self.words = [] # The words
! 		self.just = 'l' # Justification: 'l', 'r', 'lr' or 'c'
! 		self.indent_left = self.indent_right = self.indent_hang = 0
! 		# Final lay-out parameters, may change
! 		self.left = self.top = self.right = self.bottom = \
! 			self.width = self.height = self.lines = None
! 	#
! 	# Add a word, computing size information for it.
! 	# Words may also be added manually by appending to self.words
! 	# Each word should be a 7-tuple:
! 	# (font, text, width, space, stretch, ascent, descent)
! 	def addword(self, d, font, text, space, stretch):
! 		if font is not None:
! 			d.setfont(font)
! 		width = d.textwidth(text)
! 		ascent = d.baseline()
! 		descent = d.lineheight() - ascent
! 		spw = d.textwidth(' ')
! 		space = space * spw
! 		stretch = stretch * spw
! 		tuple = (font, text, width, space, stretch, ascent, descent)
! 		self.words.append(tuple)
! 	#
! 	# Hooks to begin and end anchors -- insert numbers in the word list!
! 	def bgn_anchor(self, id):
! 		self.words.append(id)
! 	#
! 	def end_anchor(self, id):
! 		self.words.append(0)
! 	#
! 	# Return the total length (width) of the text added so far, in pixels
! 	def getlength(self):
! 		total = 0
! 		for word in self.words:
! 			if type(word) is not Int:
! 				total = total + word[2] + word[3]
! 		return total
! 	#
! 	# Tab to a given position (relative to the current left indent):
! 	# remove all stretch, add fixed space up to the new indent.
! 	# If the current position is already at the tab stop,
! 	# don't add any new space (but still remove the stretch)
! 	def tabto(self, tab):
! 		total = 0
! 		as, de = 1, 0
! 		for i in range(len(self.words)):
! 			word = self.words[i]
! 			if type(word) is Int: continue
! 			(fo, te, wi, sp, st, as, de) = word
! 			self.words[i] = (fo, te, wi, sp, 0, as, de)
! 			total = total + wi + sp
! 		if total < tab:
! 			self.words.append((None, '', 0, tab-total, 0, as, de))
! 	#
! 	# Make a hanging tag: tab to hang, increment indent_left by hang,
! 	# and reset indent_hang to -hang
! 	def makehangingtag(self, hang):
! 		self.tabto(hang)
! 		self.indent_left = self.indent_left + hang
! 		self.indent_hang = -hang
! 	#
! 	# Decide where the line breaks will be given some screen width
! 	def layout(self, linewidth):
! 		self.width = linewidth
! 		height = 0
! 		self.lines = lines = []
! 		avail1 = self.width - self.indent_left - self.indent_right
! 		avail = avail1 - self.indent_hang
! 		words = self.words
! 		i = 0
! 		n = len(words)
! 		lastfont = None
! 		while i < n:
! 			firstfont = lastfont
! 			charcount = 0
! 			width = 0
! 			stretch = 0
! 			ascent = 0
! 			descent = 0
! 			lsp = 0
! 			j = i
! 			while i < n:
! 				word = words[i]
! 				if type(word) is Int:
! 					if word > 0 and width >= avail:
! 						break
! 					i = i+1
! 					continue
! 				fo, te, wi, sp, st, as, de = word
! 				if width + wi > avail and width > 0 and wi > 0:
! 					break
! 				if fo is not None:
! 					lastfont = fo
! 					if width == 0:
! 						firstfont = fo
! 				charcount = charcount + len(te) + (sp > 0)
! 				width = width + wi + sp
! 				lsp = sp
! 				stretch = stretch + st
! 				lst = st
! 				ascent = max(ascent, as)
! 				descent = max(descent, de)
! 				i = i+1
! 			while i > j and type(words[i-1]) is Int and \
! 				words[i-1] > 0: i = i-1
! 			width = width - lsp
! 			if i < n:
! 				stretch = stretch - lst
! 			else:
! 				stretch = 0
! 			tuple = i-j, firstfont, charcount, width, stretch, \
! 				ascent, descent
! 			lines.append(tuple)
! 			height = height + ascent + descent
! 			avail = avail1
! 		self.height = height
! 	#
! 	# Call a function for all words in a line
! 	def visit(self, wordfunc, anchorfunc):
! 		avail1 = self.width - self.indent_left - self.indent_right
! 		avail = avail1 - self.indent_hang
! 		v = self.top
! 		i = 0
! 		for tuple in self.lines:
! 			wordcount, firstfont, charcount, width, stretch, \
! 				ascent, descent = tuple
! 			h = self.left + self.indent_left
! 			if i == 0: h = h + self.indent_hang
! 			extra = 0
! 			if self.just == 'r': h = h + avail - width
! 			elif self.just == 'c': h = h + (avail - width) / 2
! 			elif self.just == 'lr' and stretch > 0:
! 				extra = avail - width
! 			v2 = v + ascent + descent
! 			for j in range(i, i+wordcount):
! 				word = self.words[j]
! 				if type(word) is Int:
! 					ok = anchorfunc(self, tuple, word, \
! 							h, v)
! 					if ok is not None: return ok
! 					continue
! 				fo, te, wi, sp, st, as, de = word
! 				if extra > 0 and stretch > 0:
! 					ex = extra * st / stretch
! 					extra = extra - ex
! 					stretch = stretch - st
! 				else:
! 					ex = 0
! 				h2 = h + wi + sp + ex
! 				ok = wordfunc(self, tuple, word, h, v, \
! 					h2, v2, (j==i), (j==i+wordcount-1))
! 				if ok is not None: return ok
! 				h = h2
! 			v = v2
! 			i = i + wordcount
! 			avail = avail1
! 	#
! 	# Render a paragraph in "drawing object" d, using the rectangle
! 	# given by (left, top, right) with an unspecified bottom.
! 	# Return the computed bottom of the text.
! 	def render(self, d, left, top, right):
! 		if self.width != right-left:
! 			self.layout(right-left)
! 		self.left = left
! 		self.top = top
! 		self.right = right
! 		self.bottom = self.top + self.height
! 		self.anchorid = 0
! 		try:
! 			self.d = d
! 			self.visit(self.__class__._renderword, \
! 				   self.__class__._renderanchor)
! 		finally:
! 			self.d = None
! 		return self.bottom
! 	#
! 	def _renderword(self, tuple, word, h, v, h2, v2, isfirst, islast):
! 		if word[0] is not None: self.d.setfont(word[0])
! 		baseline = v + tuple[5]
! 		self.d.text((h, baseline - word[5]), word[1])
! 		if self.anchorid > 0:
! 			self.d.line((h, baseline+2), (h2, baseline+2))
! 	#
! 	def _renderanchor(self, tuple, word, h, v):
! 		self.anchorid = word
! 	#
! 	# Return which anchor(s) was hit by the mouse
! 	def hitcheck(self, mouseh, mousev):
! 		self.mouseh = mouseh
! 		self.mousev = mousev
! 		self.anchorid = 0
! 		self.hits = []
! 		self.visit(self.__class__._hitcheckword, \
! 			   self.__class__._hitcheckanchor)
! 		return self.hits
! 	#
! 	def _hitcheckword(self, tuple, word, h, v, h2, v2, isfirst, islast):
! 		if self.anchorid > 0 and h <= self.mouseh <= h2 and \
! 			v <= self.mousev <= v2:
! 			self.hits.append(self.anchorid)
! 	#
! 	def _hitcheckanchor(self, tuple, word, h, v):
! 		self.anchorid = word
! 	#
! 	# Return whether the given anchor id is present
! 	def hasanchor(self, id):
! 		return id in self.words or -id in self.words
! 	#
! 	# Extract the raw text from the word list, substituting one space
! 	# for non-empty inter-word space, and terminating with '\n'
! 	def extract(self):
! 		text = ''
! 		for w in self.words:
! 			if type(w) is not Int:
! 				word = w[1]
! 				if w[3]: word = word + ' '
! 				text = text + word
! 		return text + '\n'
! 	#
! 	# Return which character position was hit by the mouse, as
! 	# an offset in the entire text as returned by extract().
! 	# Return None if the mouse was not in this paragraph
! 	def whereis(self, d, mouseh, mousev):
! 		if mousev < self.top or mousev > self.bottom:
! 			return None
! 		self.mouseh = mouseh
! 		self.mousev = mousev
! 		self.lastfont = None
! 		self.charcount = 0
! 		try:
! 			self.d = d
! 			return self.visit(self.__class__._whereisword, \
! 					  self.__class__._whereisanchor)
! 		finally:
! 			self.d = None
! 	#
! 	def _whereisword(self, tuple, word, h1, v1, h2, v2, isfirst, islast):
! 		fo, te, wi, sp, st, as, de = word
! 		if fo is not None: self.lastfont = fo
! 		h = h1
! 		if isfirst: h1 = 0
! 		if islast: h2 = 999999
! 		if not (v1 <= self.mousev <= v2 and h1 <= self.mouseh <= h2):
! 			self.charcount = self.charcount + len(te) + (sp > 0)
! 			return
! 		if self.lastfont is not None:
! 			self.d.setfont(self.lastfont)
! 		cc = 0
! 		for c in te:
! 			cw = self.d.textwidth(c)
! 			if self.mouseh <= h + cw/2:
! 				return self.charcount + cc
! 			cc = cc+1
! 			h = h+cw
! 		self.charcount = self.charcount + cc
! 		if self.mouseh <= (h+h2) / 2:
! 			return self.charcount
! 		else:
! 			return self.charcount + 1
! 	#
! 	def _whereisanchor(self, tuple, word, h, v):
! 		pass
! 	#
! 	# Return screen position corresponding to position in paragraph.
! 	# Return tuple (h, vtop, vbaseline, vbottom).
! 	# This is more or less the inverse of whereis()
! 	def screenpos(self, d, pos):
! 		if pos < 0:
! 			ascent, descent = self.lines[0][5:7]
! 			return self.left, self.top, self.top + ascent, \
! 				self.top + ascent + descent
! 		self.pos = pos
! 		self.lastfont = None
! 		try:
! 			self.d = d
! 			ok = self.visit(self.__class__._screenposword, \
! 					self.__class__._screenposanchor)
! 		finally:
! 			self.d = None
! 		if ok is None:
! 			ascent, descent = self.lines[-1][5:7]
! 			ok = self.right, self.bottom - ascent - descent, \
! 				self.bottom - descent, self.bottom
! 		return ok
! 	#
! 	def _screenposword(self, tuple, word, h1, v1, h2, v2, isfirst, islast):
! 		fo, te, wi, sp, st, as, de = word
! 		if fo is not None: self.lastfont = fo
! 		cc = len(te) + (sp > 0)
! 		if self.pos > cc:
! 			self.pos = self.pos - cc
! 			return
! 		if self.pos < cc:
! 			self.d.setfont(self.lastfont)
! 			h = h1 + self.d.textwidth(te[:self.pos])
! 		else:
! 			h = h2
! 		ascent, descent = tuple[5:7]
! 		return h, v1, v1+ascent, v2
! 	#
! 	def _screenposanchor(self, tuple, word, h, v):
! 		pass
! 	#
! 	# Invert the stretch of text between pos1 and pos2.
! 	# If pos1 is None, the beginning is implied;
! 	# if pos2 is None, the end is implied.
! 	# Undoes its own effect when called again with the same arguments
! 	def invert(self, d, pos1, pos2):
! 		if pos1 is None:
! 			pos1 = self.left, self.top, self.top, self.top
! 		else:
! 			pos1 = self.screenpos(d, pos1)
! 		if pos2 is None:
! 			pos2 = self.right, self.bottom,self.bottom,self.bottom
! 		else:
! 			pos2 = self.screenpos(d, pos2)
! 		h1, top1, baseline1, bottom1 = pos1
! 		h2, top2, baseline2, bottom2 = pos2
! 		if bottom1 <= top2:
! 			d.invert((h1, top1), (self.right, bottom1))
! 			h1 = self.left
! 			if bottom1 < top2:
! 				d.invert((h1, bottom1), (self.right, top2))
! 			top1, bottom1 = top2, bottom2
! 		d.invert((h1, top1), (h2, bottom2))
--- 15,343 ----
  # for mouse hits, and parts of the text can be highlighted
  class Para:
!     #
!     def __init__(self):
!         self.words = [] # The words
!         self.just = 'l' # Justification: 'l', 'r', 'lr' or 'c'
!         self.indent_left = self.indent_right = self.indent_hang = 0
!         # Final lay-out parameters, may change
!         self.left = self.top = self.right = self.bottom = \
!                 self.width = self.height = self.lines = None
!     #
!     # Add a word, computing size information for it.
!     # Words may also be added manually by appending to self.words
!     # Each word should be a 7-tuple:
!     # (font, text, width, space, stretch, ascent, descent)
!     def addword(self, d, font, text, space, stretch):
!         if font is not None:
!             d.setfont(font)
!         width = d.textwidth(text)
!         ascent = d.baseline()
!         descent = d.lineheight() - ascent
!         spw = d.textwidth(' ')
!         space = space * spw
!         stretch = stretch * spw
!         tuple = (font, text, width, space, stretch, ascent, descent)
!         self.words.append(tuple)
!     #
!     # Hooks to begin and end anchors -- insert numbers in the word list!
!     def bgn_anchor(self, id):
!         self.words.append(id)
!     #
!     def end_anchor(self, id):
!         self.words.append(0)
!     #
!     # Return the total length (width) of the text added so far, in pixels
!     def getlength(self):
!         total = 0
!         for word in self.words:
!             if type(word) is not Int:
!                 total = total + word[2] + word[3]
!         return total
!     #
!     # Tab to a given position (relative to the current left indent):
!     # remove all stretch, add fixed space up to the new indent.
!     # If the current position is already at the tab stop,
!     # don't add any new space (but still remove the stretch)
!     def tabto(self, tab):
!         total = 0
!         as, de = 1, 0
!         for i in range(len(self.words)):
!             word = self.words[i]
!             if type(word) is Int: continue
!             (fo, te, wi, sp, st, as, de) = word
!             self.words[i] = (fo, te, wi, sp, 0, as, de)
!             total = total + wi + sp
!         if total < tab:
!             self.words.append((None, '', 0, tab-total, 0, as, de))
!     #
!     # Make a hanging tag: tab to hang, increment indent_left by hang,
!     # and reset indent_hang to -hang
!     def makehangingtag(self, hang):
!         self.tabto(hang)
!         self.indent_left = self.indent_left + hang
!         self.indent_hang = -hang
!     #
!     # Decide where the line breaks will be given some screen width
!     def layout(self, linewidth):
!         self.width = linewidth
!         height = 0
!         self.lines = lines = []
!         avail1 = self.width - self.indent_left - self.indent_right
!         avail = avail1 - self.indent_hang
!         words = self.words
!         i = 0
!         n = len(words)
!         lastfont = None
!         while i < n:
!             firstfont = lastfont
!             charcount = 0
!             width = 0
!             stretch = 0
!             ascent = 0
!             descent = 0
!             lsp = 0
!             j = i
!             while i < n:
!                 word = words[i]
!                 if type(word) is Int:
!                     if word > 0 and width >= avail:
!                         break
!                     i = i+1
!                     continue
!                 fo, te, wi, sp, st, as, de = word
!                 if width + wi > avail and width > 0 and wi > 0:
!                     break
!                 if fo is not None:
!                     lastfont = fo
!                     if width == 0:
!                         firstfont = fo
!                 charcount = charcount + len(te) + (sp > 0)
!                 width = width + wi + sp
!                 lsp = sp
!                 stretch = stretch + st
!                 lst = st
!                 ascent = max(ascent, as)
!                 descent = max(descent, de)
!                 i = i+1
!             while i > j and type(words[i-1]) is Int and \
!                     words[i-1] > 0: i = i-1
!             width = width - lsp
!             if i < n:
!                 stretch = stretch - lst
!             else:
!                 stretch = 0
!             tuple = i-j, firstfont, charcount, width, stretch, \
!                     ascent, descent
!             lines.append(tuple)
!             height = height + ascent + descent
!             avail = avail1
!         self.height = height
!     #
!     # Call a function for all words in a line
!     def visit(self, wordfunc, anchorfunc):
!         avail1 = self.width - self.indent_left - self.indent_right
!         avail = avail1 - self.indent_hang
!         v = self.top
!         i = 0
!         for tuple in self.lines:
!             wordcount, firstfont, charcount, width, stretch, \
!                     ascent, descent = tuple
!             h = self.left + self.indent_left
!             if i == 0: h = h + self.indent_hang
!             extra = 0
!             if self.just == 'r': h = h + avail - width
!             elif self.just == 'c': h = h + (avail - width) / 2
!             elif self.just == 'lr' and stretch > 0:
!                 extra = avail - width
!             v2 = v + ascent + descent
!             for j in range(i, i+wordcount):
!                 word = self.words[j]
!                 if type(word) is Int:
!                     ok = anchorfunc(self, tuple, word, \
!                                     h, v)
!                     if ok is not None: return ok
!                     continue
!                 fo, te, wi, sp, st, as, de = word
!                 if extra > 0 and stretch > 0:
!                     ex = extra * st / stretch
!                     extra = extra - ex
!                     stretch = stretch - st
!                 else:
!                     ex = 0
!                 h2 = h + wi + sp + ex
!                 ok = wordfunc(self, tuple, word, h, v, \
!                         h2, v2, (j==i), (j==i+wordcount-1))
!                 if ok is not None: return ok
!                 h = h2
!             v = v2
!             i = i + wordcount
!             avail = avail1
!     #
!     # Render a paragraph in "drawing object" d, using the rectangle
!     # given by (left, top, right) with an unspecified bottom.
!     # Return the computed bottom of the text.
!     def render(self, d, left, top, right):
!         if self.width != right-left:
!             self.layout(right-left)
!         self.left = left
!         self.top = top
!         self.right = right
!         self.bottom = self.top + self.height
!         self.anchorid = 0
!         try:
!             self.d = d
!             self.visit(self.__class__._renderword, \
!                        self.__class__._renderanchor)
!         finally:
!             self.d = None
!         return self.bottom
!     #
!     def _renderword(self, tuple, word, h, v, h2, v2, isfirst, islast):
!         if word[0] is not None: self.d.setfont(word[0])
!         baseline = v + tuple[5]
!         self.d.text((h, baseline - word[5]), word[1])
!         if self.anchorid > 0:
!             self.d.line((h, baseline+2), (h2, baseline+2))
!     #
!     def _renderanchor(self, tuple, word, h, v):
!         self.anchorid = word
!     #
!     # Return which anchor(s) was hit by the mouse
!     def hitcheck(self, mouseh, mousev):
!         self.mouseh = mouseh
!         self.mousev = mousev
!         self.anchorid = 0
!         self.hits = []
!         self.visit(self.__class__._hitcheckword, \
!                    self.__class__._hitcheckanchor)
!         return self.hits
!     #
!     def _hitcheckword(self, tuple, word, h, v, h2, v2, isfirst, islast):
!         if self.anchorid > 0 and h <= self.mouseh <= h2 and \
!                 v <= self.mousev <= v2:
!             self.hits.append(self.anchorid)
!     #
!     def _hitcheckanchor(self, tuple, word, h, v):
!         self.anchorid = word
!     #
!     # Return whether the given anchor id is present
!     def hasanchor(self, id):
!         return id in self.words or -id in self.words
!     #
!     # Extract the raw text from the word list, substituting one space
!     # for non-empty inter-word space, and terminating with '\n'
!     def extract(self):
!         text = ''
!         for w in self.words:
!             if type(w) is not Int:
!                 word = w[1]
!                 if w[3]: word = word + ' '
!                 text = text + word
!         return text + '\n'
!     #
!     # Return which character position was hit by the mouse, as
!     # an offset in the entire text as returned by extract().
!     # Return None if the mouse was not in this paragraph
!     def whereis(self, d, mouseh, mousev):
!         if mousev < self.top or mousev > self.bottom:
!             return None
!         self.mouseh = mouseh
!         self.mousev = mousev
!         self.lastfont = None
!         self.charcount = 0
!         try:
!             self.d = d
!             return self.visit(self.__class__._whereisword, \
!                               self.__class__._whereisanchor)
!         finally:
!             self.d = None
!     #
!     def _whereisword(self, tuple, word, h1, v1, h2, v2, isfirst, islast):
!         fo, te, wi, sp, st, as, de = word
!         if fo is not None: self.lastfont = fo
!         h = h1
!         if isfirst: h1 = 0
!         if islast: h2 = 999999
!         if not (v1 <= self.mousev <= v2 and h1 <= self.mouseh <= h2):
!             self.charcount = self.charcount + len(te) + (sp > 0)
!             return
!         if self.lastfont is not None:
!             self.d.setfont(self.lastfont)
!         cc = 0
!         for c in te:
!             cw = self.d.textwidth(c)
!             if self.mouseh <= h + cw/2:
!                 return self.charcount + cc
!             cc = cc+1
!             h = h+cw
!         self.charcount = self.charcount + cc
!         if self.mouseh <= (h+h2) / 2:
!             return self.charcount
!         else:
!             return self.charcount + 1
!     #
!     def _whereisanchor(self, tuple, word, h, v):
!         pass
!     #
!     # Return screen position corresponding to position in paragraph.
!     # Return tuple (h, vtop, vbaseline, vbottom).
!     # This is more or less the inverse of whereis()
!     def screenpos(self, d, pos):
!         if pos < 0:
!             ascent, descent = self.lines[0][5:7]
!             return self.left, self.top, self.top + ascent, \
!                     self.top + ascent + descent
!         self.pos = pos
!         self.lastfont = None
!         try:
!             self.d = d
!             ok = self.visit(self.__class__._screenposword, \
!                             self.__class__._screenposanchor)
!         finally:
!             self.d = None
!         if ok is None:
!             ascent, descent = self.lines[-1][5:7]
!             ok = self.right, self.bottom - ascent - descent, \
!                     self.bottom - descent, self.bottom
!         return ok
!     #
!     def _screenposword(self, tuple, word, h1, v1, h2, v2, isfirst, islast):
!         fo, te, wi, sp, st, as, de = word
!         if fo is not None: self.lastfont = fo
!         cc = len(te) + (sp > 0)
!         if self.pos > cc:
!             self.pos = self.pos - cc
!             return
!         if self.pos < cc:
!             self.d.setfont(self.lastfont)
!             h = h1 + self.d.textwidth(te[:self.pos])
!         else:
!             h = h2
!         ascent, descent = tuple[5:7]
!         return h, v1, v1+ascent, v2
!     #
!     def _screenposanchor(self, tuple, word, h, v):
!         pass
!     #
!     # Invert the stretch of text between pos1 and pos2.
!     # If pos1 is None, the beginning is implied;
!     # if pos2 is None, the end is implied.
!     # Undoes its own effect when called again with the same arguments
!     def invert(self, d, pos1, pos2):
!         if pos1 is None:
!             pos1 = self.left, self.top, self.top, self.top
!         else:
!             pos1 = self.screenpos(d, pos1)
!         if pos2 is None:
!             pos2 = self.right, self.bottom,self.bottom,self.bottom
!         else:
!             pos2 = self.screenpos(d, pos2)
!         h1, top1, baseline1, bottom1 = pos1
!         h2, top2, baseline2, bottom2 = pos2
!         if bottom1 <= top2:
!             d.invert((h1, top1), (self.right, bottom1))
!             h1 = self.left
!             if bottom1 < top2:
!                 d.invert((h1, bottom1), (self.right, top2))
!             top1, bottom1 = top2, bottom2
!         d.invert((h1, top1), (h2, bottom2))

Index: addpack.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/addpack.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** addpack.py	7 Mar 1994 11:45:34 -0000	1.1
--- addpack.py	18 Jul 2004 06:14:43 -0000	1.2
***************
*** 34,67 ****
  # If no directory is found, ImportError is raised.
  
! _packs = {}				# {pack: [pathname, ...], ...}
  
  def addpack(pack, *locations):
! 	import os
! 	if os.path.isabs(pack):
! 		base = os.path.basename(pack)
! 	else:
! 		base = pack
! 	if _packs.has_key(base):
! 		return
! 	import sys
! 	path = []
! 	for loc in _flatten(locations) + sys.path:
! 		fn = os.path.join(loc, base)
! 		if fn not in path and os.path.isdir(fn):
! 			path.append(fn)
! 	if pack != base and pack not in path and os.path.isdir(pack):
! 		path.append(pack)
! 	if not path: raise ImportError, 'package ' + pack + ' not found'
! 	_packs[base] = path
! 	for fn in path:
! 		if fn not in sys.path:
! 			sys.path.append(fn)
  
  def _flatten(locations):
! 	locs = []
! 	for loc in locations:
! 		if type(loc) == type(''):
! 			locs.append(loc)
! 		else:
! 			locs = locs + _flatten(loc)
! 	return locs
--- 34,67 ----
  # If no directory is found, ImportError is raised.
  
! _packs = {}                             # {pack: [pathname, ...], ...}
  
  def addpack(pack, *locations):
!     import os
!     if os.path.isabs(pack):
!         base = os.path.basename(pack)
!     else:
!         base = pack
!     if _packs.has_key(base):
!         return
!     import sys
!     path = []
!     for loc in _flatten(locations) + sys.path:
!         fn = os.path.join(loc, base)
!         if fn not in path and os.path.isdir(fn):
!             path.append(fn)
!     if pack != base and pack not in path and os.path.isdir(pack):
!         path.append(pack)
!     if not path: raise ImportError, 'package ' + pack + ' not found'
!     _packs[base] = path
!     for fn in path:
!         if fn not in sys.path:
!             sys.path.append(fn)
  
  def _flatten(locations):
!     locs = []
!     for loc in locations:
!         if type(loc) == type(''):
!             locs.append(loc)
!         else:
!             locs = locs + _flatten(loc)
!     return locs

Index: codehack.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/codehack.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** codehack.py	20 Jul 2001 18:54:44 -0000	1.6
--- codehack.py	18 Jul 2004 06:14:43 -0000	1.7
***************
*** 37,81 ****
  
  def getcodename(co):
! 	try:
! 		return co.co_name
! 	except AttributeError:
! 		pass
! 	key = `co` # arbitrary but uniquely identifying string
! 	if _namecache.has_key(key): return _namecache[key]
! 	filename = co.co_filename
! 	code = co.co_code
! 	name = ''
! 	if ord(code[0]) == SET_LINENO:
! 		lineno = ord(code[1]) | ord(code[2]) << 8
! 		line = linecache.getline(filename, lineno)
! 		words = line.split()
! 		if len(words) >= 2 and words[0] in ('def', 'class'):
! 			name = words[1]
! 			for i in range(len(name)):
! 				if name[i] not in identchars:
! 					name = name[:i]
! 					break
! 	_namecache[key] = name
! 	return name
  
  # Use the above routine to find a function's name.
  
  def getfuncname(func):
! 	try:
! 		return func.func_name
! 	except AttributeError:
! 		pass
! 	return getcodename(func.func_code)
  
  # A part of the above code to extract just the line number from a code object.
  
  def getlineno(co):
! 	try:
! 		return co.co_firstlineno
! 	except AttributeError:
! 		pass
! 	code = co.co_code
! 	if ord(code[0]) == SET_LINENO:
! 		return ord(code[1]) | ord(code[2]) << 8
! 	else:
! 		return -1
--- 37,81 ----
  
  def getcodename(co):
!     try:
!         return co.co_name
!     except AttributeError:
!         pass
!     key = `co` # arbitrary but uniquely identifying string
!     if _namecache.has_key(key): return _namecache[key]
!     filename = co.co_filename
!     code = co.co_code
!     name = ''
!     if ord(code[0]) == SET_LINENO:
!         lineno = ord(code[1]) | ord(code[2]) << 8
!         line = linecache.getline(filename, lineno)
!         words = line.split()
!         if len(words) >= 2 and words[0] in ('def', 'class'):
!             name = words[1]
!             for i in range(len(name)):
!                 if name[i] not in identchars:
!                     name = name[:i]
!                     break
!     _namecache[key] = name
!     return name
  
  # Use the above routine to find a function's name.
  
  def getfuncname(func):
!     try:
!         return func.func_name
!     except AttributeError:
!         pass
!     return getcodename(func.func_code)
  
  # A part of the above code to extract just the line number from a code object.
  
  def getlineno(co):
!     try:
!         return co.co_firstlineno
!     except AttributeError:
!         pass
!     code = co.co_code
!     if ord(code[0]) == SET_LINENO:
!         return ord(code[1]) | ord(code[2]) << 8
!     else:
!         return -1

Index: dump.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/dump.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** dump.py	1 Jan 1992 19:28:43 -0000	1.2
--- dump.py	18 Jul 2004 06:14:43 -0000	1.3
***************
*** 24,63 ****
  #
  def dumpsymtab(dict):
! 	for key in dict.keys():
! 		dumpvar(key, dict[key])
  
  # Dump a single variable
  #
  def dumpvar(name, x):
! 	import sys
! 	t = type(x)
! 	if t == type({}):
! 		print name, '= {}'
! 		for key in x.keys():
! 			item = x[key]
! 			if not printable(item):
! 				print '#',
! 			print name, '[', `key`, '] =', `item`
! 	elif t in (type(''), type(0), type(0.0), type([]), type(())):
! 		if not printable(x):
! 			print '#',
! 		print name, '=', `x`
! 	elif t == type(sys):
! 		print 'import', name, '#', x
! 	else:
! 		print '#', name, '=', x
  
  # check if a value is printable in a way that can be read back with input()
  #
  def printable(x):
! 	t = type(x)
! 	if t in (type(''), type(0), type(0.0)):
! 		return 1
! 	if t in (type([]), type(())):
! 		for item in x:
! 			if not printable(item):
! 				return 0
! 		return 1
! 	if x == {}:
! 		return 1
! 	return 0
--- 24,63 ----
  #
  def dumpsymtab(dict):
!     for key in dict.keys():
!         dumpvar(key, dict[key])
  
  # Dump a single variable
  #
  def dumpvar(name, x):
!     import sys
!     t = type(x)
!     if t == type({}):
!         print name, '= {}'
!         for key in x.keys():
!             item = x[key]
!             if not printable(item):
!                 print '#',
!             print name, '[', `key`, '] =', `item`
!     elif t in (type(''), type(0), type(0.0), type([]), type(())):
!         if not printable(x):
!             print '#',
!         print name, '=', `x`
!     elif t == type(sys):
!         print 'import', name, '#', x
!     else:
!         print '#', name, '=', x
  
  # check if a value is printable in a way that can be read back with input()
  #
  def printable(x):
!     t = type(x)
!     if t in (type(''), type(0), type(0.0)):
!         return 1
!     if t in (type([]), type(())):
!         for item in x:
!             if not printable(item):
!                 return 0
!         return 1
!     if x == {}:
!         return 1
!     return 0

Index: find.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/find.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** find.py	27 Jan 1995 02:41:42 -0000	1.1
--- find.py	18 Jul 2004 06:14:43 -0000	1.2
***************
*** 7,26 ****
  
  def find(pattern, dir = os.curdir):
! 	list = []
! 	names = os.listdir(dir)
! 	names.sort()
! 	for name in names:
! 		if name in (os.curdir, os.pardir):
! 			continue
! 		fullname = os.path.join(dir, name)
! 		if fnmatch.fnmatch(name, pattern):
! 			list.append(fullname)
! 		if os.path.isdir(fullname) and not os.path.islink(fullname):
! 			for p in _prune:
! 				if fnmatch.fnmatch(name, p):
! 					if _debug: print "skip", `fullname`
! 					break
! 			else:
! 				if _debug: print "descend into", `fullname`
! 				list = list + find(pattern, fullname)
! 	return list
--- 7,26 ----
  
  def find(pattern, dir = os.curdir):
!     list = []
!     names = os.listdir(dir)
!     names.sort()
!     for name in names:
!         if name in (os.curdir, os.pardir):
!             continue
!         fullname = os.path.join(dir, name)
!         if fnmatch.fnmatch(name, pattern):
!             list.append(fullname)
!         if os.path.isdir(fullname) and not os.path.islink(fullname):
!             for p in _prune:
!                 if fnmatch.fnmatch(name, p):
!                     if _debug: print "skip", `fullname`
!                     break
!             else:
!                 if _debug: print "descend into", `fullname`
!                 list = list + find(pattern, fullname)
!     return list

Index: fmt.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/fmt.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** fmt.py	12 Dec 2000 23:11:41 -0000	1.6
--- fmt.py	18 Jul 2004 06:14:43 -0000	1.7
***************
*** 13,106 ****
  # Formatter back-end to do nothing at all with the paragraphs
  class NullBackEnd:
! 	#
! 	def __init__(self):
! 		pass
! 	#
! 	def addpara(self, p):
! 		pass
! 	#
! 	def bgn_anchor(self, id):
[...1140 lines suppressed...]
!     def finish(self):
!         pass
!     #
!     def addpara(self, p):
!         self.paralist.append(p)
!         self.height = p.render(self.d, 0, self.height, self.width)
!     #
!     def redraw(self):
!         import gl
!         gl.winset(self.wid)
!         width = gl.getsize()[1]
!         if width != self.width:
!             setdocsize = 1
!             self.width = width
!             for p in self.paralist:
!                 p.top = p.bottom = None
!         d = self.d
!         v = 0
!         for p in self.paralist:
!             v = p.render(d, 0, v, width)

Index: grep.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/grep.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** grep.py	9 Feb 2001 16:34:24 -0000	1.10
--- grep.py	18 Jul 2004 06:14:43 -0000	1.11
***************
*** 9,79 ****
  
  def grep(pat, *files):
! 	return ggrep(RE_SYNTAX_GREP, pat, files)
  
  def egrep(pat, *files):
! 	return ggrep(RE_SYNTAX_EGREP, pat, files)
  
  def emgrep(pat, *files):
! 	return ggrep(RE_SYNTAX_EMACS, pat, files)
  
  def ggrep(syntax, pat, files):
! 	if len(files) == 1 and type(files[0]) == type([]):
! 		files = files[0]
! 	global opt_show_filename
! 	opt_show_filename = (len(files) != 1)
! 	syntax = regex.set_syntax(syntax)
! 	try:
! 		prog = regex.compile(pat)
! 	finally:
! 		syntax = regex.set_syntax(syntax)
! 	for filename in files:
! 		fp = open(filename, 'r')
! 		lineno = 0
! 		while 1:
! 			line = fp.readline()
! 			if not line: break
! 			lineno = lineno + 1
! 			if prog.search(line) >= 0:
! 				showline(filename, lineno, line, prog)
! 		fp.close()
  
  def pgrep(pat, *files):
! 	if len(files) == 1 and type(files[0]) == type([]):
! 		files = files[0]
! 	global opt_show_filename
! 	opt_show_filename = (len(files) != 1)
! 	import re
! 	prog = re.compile(pat)
! 	for filename in files:
! 		fp = open(filename, 'r')
! 		lineno = 0
! 		while 1:
! 			line = fp.readline()
! 			if not line: break
! 			lineno = lineno + 1
! 			if prog.search(line):
! 				showline(filename, lineno, line, prog)
! 		fp.close()
  
  def showline(filename, lineno, line, prog):
! 	if line[-1:] == '\n': line = line[:-1]
! 	if opt_show_lineno:
! 		prefix = `lineno`.rjust(3) + ': '
! 	else:
! 		prefix = ''
! 	if opt_show_filename:
! 		prefix = filename + ': ' + prefix
! 	print prefix + line
! 	if opt_show_where:
! 		start, end = prog.regs()[0]
! 		line = line[:start]
! 		if '\t' not in line:
! 			prefix = ' ' * (len(prefix) + start)
! 		else:
! 			prefix = ' ' * len(prefix)
! 			for c in line:
! 				if c != '\t': c = ' '
! 				prefix = prefix + c
! 		if start == end: prefix = prefix + '\\'
! 		else: prefix = prefix + '^'*(end-start)
! 		print prefix
--- 9,79 ----
  
  def grep(pat, *files):
!     return ggrep(RE_SYNTAX_GREP, pat, files)
  
  def egrep(pat, *files):
!     return ggrep(RE_SYNTAX_EGREP, pat, files)
  
  def emgrep(pat, *files):
!     return ggrep(RE_SYNTAX_EMACS, pat, files)
  
  def ggrep(syntax, pat, files):
!     if len(files) == 1 and type(files[0]) == type([]):
!         files = files[0]
!     global opt_show_filename
!     opt_show_filename = (len(files) != 1)
!     syntax = regex.set_syntax(syntax)
!     try:
!         prog = regex.compile(pat)
!     finally:
!         syntax = regex.set_syntax(syntax)
!     for filename in files:
!         fp = open(filename, 'r')
!         lineno = 0
!         while 1:
!             line = fp.readline()
!             if not line: break
!             lineno = lineno + 1
!             if prog.search(line) >= 0:
!                 showline(filename, lineno, line, prog)
!         fp.close()
  
  def pgrep(pat, *files):
!     if len(files) == 1 and type(files[0]) == type([]):
!         files = files[0]
!     global opt_show_filename
!     opt_show_filename = (len(files) != 1)
!     import re
!     prog = re.compile(pat)
!     for filename in files:
!         fp = open(filename, 'r')
!         lineno = 0
!         while 1:
!             line = fp.readline()
!             if not line: break
!             lineno = lineno + 1
!             if prog.search(line):
!                 showline(filename, lineno, line, prog)
!         fp.close()
  
  def showline(filename, lineno, line, prog):
!     if line[-1:] == '\n': line = line[:-1]
!     if opt_show_lineno:
!         prefix = `lineno`.rjust(3) + ': '
!     else:
!         prefix = ''
!     if opt_show_filename:
!         prefix = filename + ': ' + prefix
!     print prefix + line
!     if opt_show_where:
!         start, end = prog.regs()[0]
!         line = line[:start]
!         if '\t' not in line:
!             prefix = ' ' * (len(prefix) + start)
!         else:
!             prefix = ' ' * len(prefix)
!             for c in line:
!                 if c != '\t': c = ' '
!                 prefix = prefix + c
!         if start == end: prefix = prefix + '\\'
!         else: prefix = prefix + '^'*(end-start)
!         print prefix

Index: lockfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/lockfile.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** lockfile.py	10 May 2001 15:33:31 -0000	1.2
--- lockfile.py	18 Jul 2004 06:14:43 -0000	1.3
***************
*** 2,15 ****
  
  def writelock(f):
! 	_lock(f, fcntl.F_WRLCK)
  
  def readlock(f):
! 	_lock(f, fcntl.F_RDLCK)
  
  def unlock(f):
! 	_lock(f, fcntl.F_UNLCK)
  
  def _lock(f, op):
! 	dummy = fcntl.fcntl(f.fileno(), fcntl.F_SETLKW,
! 			    struct.pack('2h8l', op,
! 					0, 0, 0, 0, 0, 0, 0, 0, 0))
--- 2,15 ----
  
  def writelock(f):
!     _lock(f, fcntl.F_WRLCK)
  
  def readlock(f):
!     _lock(f, fcntl.F_RDLCK)
  
  def unlock(f):
!     _lock(f, fcntl.F_UNLCK)
  
  def _lock(f, op):
!     dummy = fcntl.fcntl(f.fileno(), fcntl.F_SETLKW,
!                         struct.pack('2h8l', op,
!                                     0, 0, 0, 0, 0, 0, 0, 0, 0))

Index: newdir.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/newdir.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** newdir.py	1 Aug 1994 11:28:43 -0000	1.5
--- newdir.py	18 Jul 2004 06:14:43 -0000	1.6
***************
*** 6,58 ****
  
  def listattrs(x):
! 	try:
! 		dictkeys = x.__dict__.keys()
! 	except (AttributeError, TypeError):
! 		dictkeys = []
! 	#
! 	try:
! 		methods = x.__methods__
! 	except (AttributeError, TypeError):
! 		methods = []
! 	#
! 	try:
! 		members = x.__members__
! 	except (AttributeError, TypeError):
! 		members = []
! 	#
! 	try:
! 		the_class = x.__class__
! 	except (AttributeError, TypeError):
! 		the_class = None
! 	#
! 	try:
! 		bases = x.__bases__
! 	except (AttributeError, TypeError):
! 		bases = ()
! 	#
! 	total = dictkeys + methods + members
! 	if the_class:
! 		# It's a class instace; add the class's attributes
! 		# that are functions (methods)...
! 		class_attrs = listattrs(the_class)
! 		class_methods = []
! 		for name in class_attrs:
! 			if is_function(getattr(the_class, name)):
! 				class_methods.append(name)
! 		total = total + class_methods
! 	elif bases:
! 		# It's a derived class; add the base class attributes
! 		for base in bases:
! 			base_attrs = listattrs(base)
! 			total = total + base_attrs
! 	total.sort()
! 	return total
! 	i = 0
! 	while i+1 < len(total):
! 		if total[i] == total[i+1]:
! 			del total[i+1]
! 		else:
! 			i = i+1
! 	return total
  
  
--- 6,58 ----
  
  def listattrs(x):
!     try:
!         dictkeys = x.__dict__.keys()
!     except (AttributeError, TypeError):
!         dictkeys = []
!     #
!     try:
!         methods = x.__methods__
!     except (AttributeError, TypeError):
!         methods = []
!     #
!     try:
!         members = x.__members__
!     except (AttributeError, TypeError):
!         members = []
!     #
!     try:
!         the_class = x.__class__
!     except (AttributeError, TypeError):
!         the_class = None
!     #
!     try:
!         bases = x.__bases__
!     except (AttributeError, TypeError):
!         bases = ()
!     #
!     total = dictkeys + methods + members
!     if the_class:
!         # It's a class instace; add the class's attributes
!         # that are functions (methods)...
!         class_attrs = listattrs(the_class)
!         class_methods = []
!         for name in class_attrs:
!             if is_function(getattr(the_class, name)):
!                 class_methods.append(name)
!         total = total + class_methods
!     elif bases:
!         # It's a derived class; add the base class attributes
!         for base in bases:
!             base_attrs = listattrs(base)
!             total = total + base_attrs
!     total.sort()
!     return total
!     i = 0
!     while i+1 < len(total):
!         if total[i] == total[i+1]:
!             del total[i+1]
!         else:
!             i = i+1
!     return total
  
  
***************
*** 60,64 ****
  
  def is_function(x):
! 	return type(x) == type(is_function)
  
  
--- 60,64 ----
  
  def is_function(x):
!     return type(x) == type(is_function)
  
  
***************
*** 67,73 ****
  
  def dir(x = None):
! 	if x is not None:
! 		return listattrs(x)
! 	else:
! 		import __main__
! 		return listattrs(__main__)
--- 67,73 ----
  
  def dir(x = None):
!     if x is not None:
!         return listattrs(x)
!     else:
!         import __main__
!         return listattrs(__main__)

Index: packmail.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/packmail.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** packmail.py	9 Feb 2001 16:25:20 -0000	1.10
--- packmail.py	18 Jul 2004 06:14:43 -0000	1.11
***************
*** 9,111 ****
  # Print help
  def help():
! 	print 'All fns have a file open for writing as first parameter'
! 	print 'pack(f, fullname, name): pack fullname as name'
! 	print 'packsome(f, directory, namelist): selected files from directory'
! 	print 'packall(f, directory): pack all files from directory'
! 	print 'packnotolder(f, directory, name): pack all files from directory'
! 	print '                        that are not older than a file there'
! 	print 'packtree(f, directory): pack entire directory tree'
  
  # Pack one file
  def pack(outfp, file, name):
! 	fp = open(file, 'r')
! 	outfp.write('echo ' + name + '\n')
! 	outfp.write('sed "s/^X//" >"' + name + '" <<"!"\n')
! 	while 1:
! 		line = fp.readline()
! 		if not line: break
! 		if line[-1:] != '\n':
! 			line = line + '\n'
! 		outfp.write('X' + line)
! 	outfp.write('!\n')
! 	fp.close()
  
  # Pack some files from a directory
  def packsome(outfp, dirname, names):
! 	for name in names:
! 		print name
! 		file = os.path.join(dirname, name)
! 		pack(outfp, file, name)
  
  # Pack all files from a directory
  def packall(outfp, dirname):
! 	names = os.listdir(dirname)
! 	try:
! 	    names.remove('.')
! 	except:
! 	    pass
! 	try:
! 	    names.remove('..')
! 	except:
! 	    pass
! 	names.sort()
! 	packsome(outfp, dirname, names)
  
  # Pack all files from a directory that are not older than a give one
  def packnotolder(outfp, dirname, oldest):
! 	names = os.listdir(dirname)
! 	try:
! 	    names.remove('.')
! 	except:
! 	    pass
! 	try:
! 	    names.remove('..')
! 	except:
! 	    pass
! 	oldest = os.path.join(dirname, oldest)
! 	st = os.stat(oldest)
! 	mtime = st[ST_MTIME]
! 	todo = []
! 	for name in names:
! 		print name, '...',
! 		st = os.stat(os.path.join(dirname, name))
! 		if st[ST_MTIME] >= mtime:
! 			print 'Yes.'
! 			todo.append(name)
! 		else:
! 			print 'No.'
! 	todo.sort()
! 	packsome(outfp, dirname, todo)
  
  # Pack a whole tree (no exceptions)
  def packtree(outfp, dirname):
! 	print 'packtree', dirname
! 	outfp.write('mkdir ' + unixfix(dirname) + '\n')
! 	names = os.listdir(dirname)
! 	try:
! 	    names.remove('.')
! 	except:
! 	    pass
! 	try:
! 	    names.remove('..')
! 	except:
! 	    pass
! 	subdirs = []
! 	for name in names:
! 		fullname = os.path.join(dirname, name)
! 		if os.path.isdir(fullname):
! 			subdirs.append(fullname)
! 		else:
! 			print 'pack', fullname
! 			pack(outfp, fullname, unixfix(fullname))
! 	for subdirname in subdirs:
! 		packtree(outfp, subdirname)
  
  def unixfix(name):
! 	comps = name.split(os.sep)
! 	res = ''
! 	for comp in comps:
! 		if comp:
! 			if res: res = res + '/'
! 			res = res + comp
! 	return res
--- 9,111 ----
  # Print help
  def help():
!     print 'All fns have a file open for writing as first parameter'
!     print 'pack(f, fullname, name): pack fullname as name'
!     print 'packsome(f, directory, namelist): selected files from directory'
!     print 'packall(f, directory): pack all files from directory'
!     print 'packnotolder(f, directory, name): pack all files from directory'
!     print '                        that are not older than a file there'
!     print 'packtree(f, directory): pack entire directory tree'
  
  # Pack one file
  def pack(outfp, file, name):
!     fp = open(file, 'r')
!     outfp.write('echo ' + name + '\n')
!     outfp.write('sed "s/^X//" >"' + name + '" <<"!"\n')
!     while 1:
!         line = fp.readline()
!         if not line: break
!         if line[-1:] != '\n':
!             line = line + '\n'
!         outfp.write('X' + line)
!     outfp.write('!\n')
!     fp.close()
  
  # Pack some files from a directory
  def packsome(outfp, dirname, names):
!     for name in names:
!         print name
!         file = os.path.join(dirname, name)
!         pack(outfp, file, name)
  
  # Pack all files from a directory
  def packall(outfp, dirname):
!     names = os.listdir(dirname)
!     try:
!         names.remove('.')
!     except:
!         pass
!     try:
!         names.remove('..')
!     except:
!         pass
!     names.sort()
!     packsome(outfp, dirname, names)
  
  # Pack all files from a directory that are not older than a give one
  def packnotolder(outfp, dirname, oldest):
!     names = os.listdir(dirname)
!     try:
!         names.remove('.')
!     except:
!         pass
!     try:
!         names.remove('..')
!     except:
!         pass
!     oldest = os.path.join(dirname, oldest)
!     st = os.stat(oldest)
!     mtime = st[ST_MTIME]
!     todo = []
!     for name in names:
!         print name, '...',
!         st = os.stat(os.path.join(dirname, name))
!         if st[ST_MTIME] >= mtime:
!             print 'Yes.'
!             todo.append(name)
!         else:
!             print 'No.'
!     todo.sort()
!     packsome(outfp, dirname, todo)
  
  # Pack a whole tree (no exceptions)
  def packtree(outfp, dirname):
!     print 'packtree', dirname
!     outfp.write('mkdir ' + unixfix(dirname) + '\n')
!     names = os.listdir(dirname)
!     try:
!         names.remove('.')
!     except:
!         pass
!     try:
!         names.remove('..')
!     except:
!         pass
!     subdirs = []
!     for name in names:
!         fullname = os.path.join(dirname, name)
!         if os.path.isdir(fullname):
!             subdirs.append(fullname)
!         else:
!             print 'pack', fullname
!             pack(outfp, fullname, unixfix(fullname))
!     for subdirname in subdirs:
!         packtree(outfp, subdirname)
  
  def unixfix(name):
!     comps = name.split(os.sep)
!     res = ''
!     for comp in comps:
!         if comp:
!             if res: res = res + '/'
!             res = res + comp
!     return res

Index: poly.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/poly.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** poly.py	22 Feb 1999 15:19:47 -0000	1.2
--- poly.py	18 Jul 2004 06:14:43 -0000	1.3
***************
*** 7,52 ****
  
  def normalize(p): # Strip unnecessary zero coefficients
! 	n = len(p)
! 	while n:
! 		if p[n-1]: return p[:n]
! 		n = n-1
! 	return []
  
  def plus(a, b):
! 	if len(a) < len(b): a, b = b, a # make sure a is the longest
! 	res = a[:] # make a copy
! 	for i in range(len(b)):
! 		res[i] = res[i] + b[i]
! 	return normalize(res)
  
  def minus(a, b):
! 	neg_b = map(lambda x: -x, b[:])
! 	return plus(a, neg_b)
  
  def one(power, coeff): # Representation of coeff * x**power
! 	res = []
! 	for i in range(power): res.append(0)
! 	return res + [coeff]
  
  def times(a, b):
! 	res = []
! 	for i in range(len(a)):
! 		for j in range(len(b)):
! 			res = plus(res, one(i+j, a[i]*b[j]))
! 	return res
  
  def power(a, n): # Raise polynomial a to the positive integral power n
! 	if n == 0: return [1]
! 	if n == 1: return a
! 	if n/2*2 == n:
! 		b = power(a, n/2)
! 		return times(b, b)
! 	return times(power(a, n-1), a)
  
  def der(a): # First derivative
! 	res = a[1:]
! 	for i in range(len(res)):
! 		res[i] = res[i] * (i+1)
! 	return res
  
  # Computing a primitive function would require rational arithmetic...
--- 7,52 ----
  
  def normalize(p): # Strip unnecessary zero coefficients
!     n = len(p)
!     while n:
!         if p[n-1]: return p[:n]
!         n = n-1
!     return []
  
  def plus(a, b):
!     if len(a) < len(b): a, b = b, a # make sure a is the longest
!     res = a[:] # make a copy
!     for i in range(len(b)):
!         res[i] = res[i] + b[i]
!     return normalize(res)
  
  def minus(a, b):
!     neg_b = map(lambda x: -x, b[:])
!     return plus(a, neg_b)
  
  def one(power, coeff): # Representation of coeff * x**power
!     res = []
!     for i in range(power): res.append(0)
!     return res + [coeff]
  
  def times(a, b):
!     res = []
!     for i in range(len(a)):
!         for j in range(len(b)):
!             res = plus(res, one(i+j, a[i]*b[j]))
!     return res
  
  def power(a, n): # Raise polynomial a to the positive integral power n
!     if n == 0: return [1]
!     if n == 1: return a
!     if n/2*2 == n:
!         b = power(a, n/2)
!         return times(b, b)
!     return times(power(a, n-1), a)
  
  def der(a): # First derivative
!     res = a[1:]
!     for i in range(len(res)):
!         res[i] = res[i] * (i+1)
!     return res
  
  # Computing a primitive function would require rational arithmetic...

Index: rand.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/rand.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** rand.py	16 Aug 1991 13:28:11 -0000	1.2
--- rand.py	18 Jul 2004 06:14:43 -0000	1.3
***************
*** 5,13 ****
  
  def srand(seed):
! 	whrandom.seed(seed%256, seed/256%256, seed/65536%256)
  
  def rand():
! 	return int(whrandom.random() * 32768.0) % 32768
  
  def choice(seq):
! 	return seq[rand() % len(seq)]
--- 5,13 ----
  
  def srand(seed):
!     whrandom.seed(seed%256, seed/256%256, seed/65536%256)
  
  def rand():
!     return int(whrandom.random() * 32768.0) % 32768
  
  def choice(seq):
!     return seq[rand() % len(seq)]

Index: tb.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/tb.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** tb.py	9 Feb 2001 11:29:54 -0000	1.9
--- tb.py	18 Jul 2004 06:14:43 -0000	1.10
***************
*** 13,177 ****
  
  def browser(tb):
! 	if not tb:
! 		print 'No traceback.'
! 		return
! 	tblist = []
! 	while tb:
! 		tblist.append(tb)
! 		tb = tb.tb_next
! 	ptr = len(tblist)-1
! 	tb = tblist[ptr]
! 	while 1:
! 		if tb != tblist[ptr]:
! 			tb = tblist[ptr]
! 			print `ptr` + ':',
! 			printtbheader(tb)
! 		try:
! 			line = raw_input('TB: ')
! 		except KeyboardInterrupt:
! 			print '\n[Interrupted]'
! 			break
! 		except EOFError:
! 			print '\n[EOF]'
! 			break
! 		cmd = line.strip()
! 		if cmd:
! 			if cmd == 'quit':
! 				break
! 			elif cmd == 'list':
! 				browserlist(tb)
! 			elif cmd == 'up':
! 				if ptr-1 >= 0: ptr = ptr-1
! 				else: print 'Bottom of stack.'
! 			elif cmd == 'down':
! 				if ptr+1 < len(tblist): ptr = ptr+1
! 				else: print 'Top of stack.'
! 			elif cmd == 'locals':
! 				printsymbols(tb.tb_frame.f_locals)
! 			elif cmd == 'globals':
! 				printsymbols(tb.tb_frame.f_globals)
! 			elif cmd in ('?', 'help'):
! 				browserhelp()
! 			else:
! 				browserexec(tb, cmd)
  
  def browserlist(tb):
! 	filename = tb.tb_frame.f_code.co_filename
! 	lineno = tb.tb_lineno
! 	last = lineno
! 	first = max(1, last-10)
! 	for i in range(first, last+1):
! 		if i == lineno: prefix = '***' + `i`.rjust(4) + ':'
! 		else: prefix = `i`.rjust(7) + ':'
! 		line = linecache.getline(filename, i)
! 		if line[-1:] == '\n': line = line[:-1]
! 		print prefix + line
  
  def browserexec(tb, cmd):
! 	locals = tb.tb_frame.f_locals
! 	globals = tb.tb_frame.f_globals
! 	try:
! 		exec cmd+'\n' in globals, locals
! 	except:
! 		t, v = sys.exc_info()[:2]
! 		print '*** Exception:',
! 		if type(t) is type(''):
! 			print t,
! 		else:
! 			print t.__name__,
! 		if v is not None:
! 			print ':', v,
! 		print
! 		print 'Type help to get help.'
  
  def browserhelp():
! 	print
! 	print '    This is the traceback browser.  Commands are:'
! 	print '        up      : move one level up in the call stack'
! 	print '        down    : move one level down in the call stack'
! 	print '        locals  : print all local variables at this level'
! 	print '        globals : print all global variables at this level'
! 	print '        list    : list source code around the failure'
! 	print '        help    : print help (what you are reading now)'
! 	print '        quit    : back to command interpreter'
! 	print '    Typing any other 1-line statement will execute it'
! 	print '    using the current level\'s symbol tables'
! 	print
  
  def printtb(tb):
! 	while tb:
! 		print1tb(tb)
! 		tb = tb.tb_next
  
  def print1tb(tb):
! 	printtbheader(tb)
! 	if tb.tb_frame.f_locals is not tb.tb_frame.f_globals:
! 		printsymbols(tb.tb_frame.f_locals)
  
  def printtbheader(tb):
! 	filename = tb.tb_frame.f_code.co_filename
! 	lineno = tb.tb_lineno
! 	info = '"' + filename + '"(' + `lineno` + ')'
! 	line = linecache.getline(filename, lineno)
! 	if line:
! 		info = info + ': ' + line.strip()
! 	print info
  
  def printsymbols(d):
! 	keys = d.keys()
! 	keys.sort()
! 	for name in keys:
! 		print '  ' + name.ljust(12) + ':',
! 		printobject(d[name], 4)
! 		print
  
  def printobject(v, maxlevel):
! 	if v is None:
! 		print 'None',
! 	elif type(v) in (type(0), type(0.0)):
! 		print v,
! 	elif type(v) is type(''):
! 		if len(v) > 20:
! 			print `v[:17] + '...'`,
! 		else:
! 			print `v`,
! 	elif type(v) is type(()):
! 		print '(',
! 		printlist(v, maxlevel)
! 		print ')',
! 	elif type(v) is type([]):
! 		print '[',
! 		printlist(v, maxlevel)
! 		print ']',
! 	elif type(v) is type({}):
! 		print '{',
! 		printdict(v, maxlevel)
! 		print '}',
! 	else:
! 		print v,
  
  def printlist(v, maxlevel):
! 	n = len(v)
! 	if n == 0: return
! 	if maxlevel <= 0:
! 		print '...',
! 		return
! 	for i in range(min(6, n)):
! 		printobject(v[i], maxlevel-1)
! 		if i+1 < n: print ',',
! 	if n > 6: print '...',
  
  def printdict(v, maxlevel):
! 	keys = v.keys()
! 	n = len(keys)
! 	if n == 0: return
! 	if maxlevel <= 0:
! 		print '...',
! 		return
! 	keys.sort()
! 	for i in range(min(6, n)):
! 		key = keys[i]
! 		print `key` + ':',
! 		printobject(v[key], maxlevel-1)
! 		if i+1 < n: print ',',
! 	if n > 6: print '...',
--- 13,177 ----
  
  def browser(tb):
!     if not tb:
!         print 'No traceback.'
!         return
!     tblist = []
!     while tb:
!         tblist.append(tb)
!         tb = tb.tb_next
!     ptr = len(tblist)-1
!     tb = tblist[ptr]
!     while 1:
!         if tb != tblist[ptr]:
!             tb = tblist[ptr]
!             print `ptr` + ':',
!             printtbheader(tb)
!         try:
!             line = raw_input('TB: ')
!         except KeyboardInterrupt:
!             print '\n[Interrupted]'
!             break
!         except EOFError:
!             print '\n[EOF]'
!             break
!         cmd = line.strip()
!         if cmd:
!             if cmd == 'quit':
!                 break
!             elif cmd == 'list':
!                 browserlist(tb)
!             elif cmd == 'up':
!                 if ptr-1 >= 0: ptr = ptr-1
!                 else: print 'Bottom of stack.'
!             elif cmd == 'down':
!                 if ptr+1 < len(tblist): ptr = ptr+1
!                 else: print 'Top of stack.'
!             elif cmd == 'locals':
!                 printsymbols(tb.tb_frame.f_locals)
!             elif cmd == 'globals':
!                 printsymbols(tb.tb_frame.f_globals)
!             elif cmd in ('?', 'help'):
!                 browserhelp()
!             else:
!                 browserexec(tb, cmd)
  
  def browserlist(tb):
!     filename = tb.tb_frame.f_code.co_filename
!     lineno = tb.tb_lineno
!     last = lineno
!     first = max(1, last-10)
!     for i in range(first, last+1):
!         if i == lineno: prefix = '***' + `i`.rjust(4) + ':'
!         else: prefix = `i`.rjust(7) + ':'
!         line = linecache.getline(filename, i)
!         if line[-1:] == '\n': line = line[:-1]
!         print prefix + line
  
  def browserexec(tb, cmd):
!     locals = tb.tb_frame.f_locals
!     globals = tb.tb_frame.f_globals
!     try:
!         exec cmd+'\n' in globals, locals
!     except:
!         t, v = sys.exc_info()[:2]
!         print '*** Exception:',
!         if type(t) is type(''):
!             print t,
!         else:
!             print t.__name__,
!         if v is not None:
!             print ':', v,
!         print
!         print 'Type help to get help.'
  
  def browserhelp():
!     print
!     print '    This is the traceback browser.  Commands are:'
!     print '        up      : move one level up in the call stack'
!     print '        down    : move one level down in the call stack'
!     print '        locals  : print all local variables at this level'
!     print '        globals : print all global variables at this level'
!     print '        list    : list source code around the failure'
!     print '        help    : print help (what you are reading now)'
!     print '        quit    : back to command interpreter'
!     print '    Typing any other 1-line statement will execute it'
!     print '    using the current level\'s symbol tables'
!     print
  
  def printtb(tb):
!     while tb:
!         print1tb(tb)
!         tb = tb.tb_next
  
  def print1tb(tb):
!     printtbheader(tb)
!     if tb.tb_frame.f_locals is not tb.tb_frame.f_globals:
!         printsymbols(tb.tb_frame.f_locals)
  
  def printtbheader(tb):
!     filename = tb.tb_frame.f_code.co_filename
!     lineno = tb.tb_lineno
!     info = '"' + filename + '"(' + `lineno` + ')'
!     line = linecache.getline(filename, lineno)
!     if line:
!         info = info + ': ' + line.strip()
!     print info
  
  def printsymbols(d):
!     keys = d.keys()
!     keys.sort()
!     for name in keys:
!         print '  ' + name.ljust(12) + ':',
!         printobject(d[name], 4)
!         print
  
  def printobject(v, maxlevel):
!     if v is None:
!         print 'None',
!     elif type(v) in (type(0), type(0.0)):
!         print v,
!     elif type(v) is type(''):
!         if len(v) > 20:
!             print `v[:17] + '...'`,
!         else:
!             print `v`,
!     elif type(v) is type(()):
!         print '(',
!         printlist(v, maxlevel)
!         print ')',
!     elif type(v) is type([]):
!         print '[',
!         printlist(v, maxlevel)
!         print ']',
!     elif type(v) is type({}):
!         print '{',
!         printdict(v, maxlevel)
!         print '}',
!     else:
!         print v,
  
  def printlist(v, maxlevel):
!     n = len(v)
!     if n == 0: return
!     if maxlevel <= 0:
!         print '...',
!         return
!     for i in range(min(6, n)):
!         printobject(v[i], maxlevel-1)
!         if i+1 < n: print ',',
!     if n > 6: print '...',
  
  def printdict(v, maxlevel):
!     keys = v.keys()
!     n = len(keys)
!     if n == 0: return
!     if maxlevel <= 0:
!         print '...',
!         return
!     keys.sort()
!     for i in range(min(6, n)):
!         key = keys[i]
!         print `key` + ':',
!         printobject(v[key], maxlevel-1)
!         if i+1 < n: print ',',
!     if n > 6: print '...',

Index: util.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/util.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** util.py	21 Apr 1991 19:34:48 -0000	1.4
--- util.py	18 Jul 2004 06:14:43 -0000	1.5
***************
*** 11,15 ****
  #
  def remove(item, list):
! 	if item in list: list.remove(item)
  
  
--- 11,15 ----
  #
  def remove(item, list):
!     if item in list: list.remove(item)
  
  
***************
*** 17,21 ****
  #
  def readfile(fn):
! 	return readopenfile(open(fn, 'r'))
  
  
--- 17,21 ----
  #
  def readfile(fn):
!     return readopenfile(open(fn, 'r'))
  
  
***************
*** 23,25 ****
  #
  def readopenfile(fp):
! 	return fp.read()
--- 23,25 ----
  #
  def readopenfile(fp):
!     return fp.read()

Index: zmod.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-old/zmod.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** zmod.py	12 Dec 2000 23:11:41 -0000	1.2
--- zmod.py	18 Jul 2004 06:14:43 -0000	1.3
***************
*** 2,6 ****
  
  # Compute properties of mathematical "fields" formed by taking
! # Z/n (the whole numbers modulo some whole number n) and an 
  # irreducible polynomial (i.e., a polynomial with only complex zeros),
  # e.g., Z/5 and X**2 + 2.
--- 2,6 ----
  
  # Compute properties of mathematical "fields" formed by taking
! # Z/n (the whole numbers modulo some whole number n) and an
  # irreducible polynomial (i.e., a polynomial with only complex zeros),
  # e.g., Z/5 and X**2 + 2.
***************
*** 31,35 ****
  
  def mod(x, y):
! 	return divmod(x, y)[1]
  
  
--- 31,35 ----
  
  def mod(x, y):
!     return divmod(x, y)[1]
  
  
***************
*** 37,45 ****
  
  def norm(a, n, p):
! 	a = poly.modulo(a, p)
! 	a = a[:]
! 	for i in range(len(a)): a[i] = mod(a[i], n)
! 	a = poly.normalize(a)
! 	return a
  
  
--- 37,45 ----
  
  def norm(a, n, p):
!     a = poly.modulo(a, p)
!     a = a[:]
!     for i in range(len(a)): a[i] = mod(a[i], n)
!     a = poly.normalize(a)
!     return a
  
  
***************
*** 47,94 ****
  
  def make_all(mat):
! 	all = []
! 	for row in mat:
! 		for a in row:
! 			all.append(a)
! 	return all
  
  def make_elements(n, d):
! 	if d == 0: return [poly.one(0, 0)]
! 	sub = make_elements(n, d-1)
! 	all = []
! 	for a in sub:
! 		for i in range(n):
! 			all.append(poly.plus(a, poly.one(d-1, i)))
! 	return all
  
  def make_inv(all, n, p):
! 	x = poly.one(1, 1)
! 	inv = []
! 	for a in all:
! 		inv.append(norm(poly.times(a, x), n, p))
! 	return inv
  
  def checkfield(n, p):
! 	all = make_elements(n, len(p)-1)
! 	inv = make_inv(all, n, p)
! 	all1 = all[:]
! 	inv1 = inv[:]
! 	all1.sort()
! 	inv1.sort()
! 	if all1 == inv1: print 'BINGO!'
! 	else:
! 		print 'Sorry:', n, p
! 		print all
! 		print inv
  
  def rj(s, width):
! 	if type(s) is not type(''): s = `s`
! 	n = len(s)
! 	if n >= width: return s
! 	return ' '*(width - n) + s
  
  def lj(s, width):
! 	if type(s) is not type(''): s = `s`
! 	n = len(s)
! 	if n >= width: return s
! 	return s + ' '*(width - n)
--- 47,94 ----
  
  def make_all(mat):
!     all = []
!     for row in mat:
!         for a in row:
!             all.append(a)
!     return all
  
  def make_elements(n, d):
!     if d == 0: return [poly.one(0, 0)]
!     sub = make_elements(n, d-1)
!     all = []
!     for a in sub:
!         for i in range(n):
!             all.append(poly.plus(a, poly.one(d-1, i)))
!     return all
  
  def make_inv(all, n, p):
!     x = poly.one(1, 1)
!     inv = []
!     for a in all:
!         inv.append(norm(poly.times(a, x), n, p))
!     return inv
  
  def checkfield(n, p):
!     all = make_elements(n, len(p)-1)
!     inv = make_inv(all, n, p)
!     all1 = all[:]
!     inv1 = inv[:]
!     all1.sort()
!     inv1.sort()
!     if all1 == inv1: print 'BINGO!'
!     else:
!         print 'Sorry:', n, p
!         print all
!         print inv
  
  def rj(s, width):
!     if type(s) is not type(''): s = `s`
!     n = len(s)
!     if n >= width: return s
!     return ' '*(width - n) + s
  
  def lj(s, width):
!     if type(s) is not type(''): s = `s`
!     n = len(s)
!     if n >= width: return s
!     return s + ' '*(width - n)



More information about the Python-checkins mailing list