[Python-checkins] python/dist/src/Demo/comparisons systemtest.py,1.2,1.2.30.1 sortingtest.py,1.2,1.2.30.1 regextest.py,1.2,1.2.30.1

jhylton@users.sourceforge.net jhylton@users.sourceforge.net
Mon, 28 Apr 2003 10:39:41 -0700


Update of /cvsroot/python/python/dist/src/Demo/comparisons
In directory sc8-pr-cvs1:/tmp/cvs-serv27228/Demo/comparisons

Modified Files:
      Tag: ast-branch
	systemtest.py sortingtest.py regextest.py 
Log Message:
Merge head to this branch.

Merge all sorts of changes from just before 2.3b1 into the ast
branch.  This should make the eventual merge back to the trunk easier.

The merge is almost entirely porting changes into the ast-branch.
There was no attempt to get changes to compile.c into newcompile.c.
That work should be done when newcompile.c is closer to completion.

The only significant conflicts appeared to be in pythonrun.c.


Index: systemtest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Demo/comparisons/systemtest.py,v
retrieving revision 1.2
retrieving revision 1.2.30.1
diff -C2 -d -r1.2 -r1.2.30.1
*** systemtest.py	27 Nov 1996 19:49:10 -0000	1.2
--- systemtest.py	28 Apr 2003 17:39:06 -0000	1.2.30.1
***************
*** 2,6 ****
  
  # 3)  System Test
! # 
  #     Given a list of directories, report any bogus symbolic links contained
  #     anywhere in those subtrees.  A bogus symbolic link is one that cannot
--- 2,6 ----
  
  # 3)  System Test
! #
  #     Given a list of directories, report any bogus symbolic links contained
  #     anywhere in those subtrees.  A bogus symbolic link is one that cannot
***************
*** 22,74 ****
  
  def main():
! 	try:
! 		# Note: can't test for presence of lstat -- it's always there
! 		dummy = os.readlink
! 	except AttributeError:
! 		print "This system doesn't have symbolic links"
! 		sys.exit(0)
! 	if sys.argv[1:]:
! 		prefix = sys.argv[1]
! 	else:
! 		prefix = ''
! 	if prefix:
! 		os.chdir(prefix)
! 		if prefix[-1:] != '/': prefix = prefix + '/'
! 		reportboguslinks(prefix)
! 	else:
! 		reportboguslinks('')
  
  def reportboguslinks(prefix):
! 	try:
! 		names = os.listdir('.')
! 	except os.error, msg:
! 		print "%s%s: can't list: %s" % (prefix, '.', msg)
! 		return
! 	names.sort()
! 	for name in names:
! 		if name == os.curdir or name == os.pardir:
! 			continue
! 		try:
! 			mode = os.lstat(name)[ST_MODE]
! 		except os.error:
! 			print "%s%s: can't stat: %s" % (prefix, name, msg)
! 			continue
! 		if S_ISLNK(mode):
! 			try:
! 				os.stat(name)
! 			except os.error:
! 				print "%s%s -> %s" % \
! 				      (prefix, name, os.readlink(name))
! 		elif S_ISDIR(mode):
! 			try:
! 				os.chdir(name)
! 			except os.error, msg:
! 				print "%s%s: can't chdir: %s" % \
! 				      (prefix, name, msg)
! 				continue
! 			try:
! 				reportboguslinks(prefix + name + '/')
! 			finally:
! 				os.chdir('..')
  
  main()
--- 22,74 ----
  
  def main():
!     try:
!         # Note: can't test for presence of lstat -- it's always there
!         dummy = os.readlink
!     except AttributeError:
!         print "This system doesn't have symbolic links"
!         sys.exit(0)
!     if sys.argv[1:]:
!         prefix = sys.argv[1]
!     else:
!         prefix = ''
!     if prefix:
!         os.chdir(prefix)
!         if prefix[-1:] != '/': prefix = prefix + '/'
!         reportboguslinks(prefix)
!     else:
!         reportboguslinks('')
  
  def reportboguslinks(prefix):
!     try:
!         names = os.listdir('.')
!     except os.error, msg:
!         print "%s%s: can't list: %s" % (prefix, '.', msg)
!         return
!     names.sort()
!     for name in names:
!         if name == os.curdir or name == os.pardir:
!             continue
!         try:
!             mode = os.lstat(name)[ST_MODE]
!         except os.error:
!             print "%s%s: can't stat: %s" % (prefix, name, msg)
!             continue
!         if S_ISLNK(mode):
!             try:
!                 os.stat(name)
!             except os.error:
!                 print "%s%s -> %s" % \
!                       (prefix, name, os.readlink(name))
!         elif S_ISDIR(mode):
!             try:
!                 os.chdir(name)
!             except os.error, msg:
!                 print "%s%s: can't chdir: %s" % \
!                       (prefix, name, msg)
!                 continue
!             try:
!                 reportboguslinks(prefix + name + '/')
!             finally:
!                 os.chdir('..')
  
  main()

Index: sortingtest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Demo/comparisons/sortingtest.py,v
retrieving revision 1.2
retrieving revision 1.2.30.1
diff -C2 -d -r1.2 -r1.2.30.1
*** sortingtest.py	27 Nov 1996 19:49:08 -0000	1.2
--- sortingtest.py	28 Apr 2003 17:39:06 -0000	1.2.30.1
***************
*** 2,16 ****
  
  # 2)  Sorting Test
! # 
  #     Sort an input file that consists of lines like this
! # 
  #         var1=23 other=14 ditto=23 fred=2
! # 
  #     such that each output line is sorted WRT to the number.  Order
  #     of output lines does not change.  Resolve collisions using the
  #     variable name.   e.g.
! # 
! #         fred=2 other=14 ditto=23 var1=23 
! # 
  #     Lines may be up to several kilobytes in length and contain
  #     zillions of variables.
--- 2,16 ----
  
  # 2)  Sorting Test
! #
  #     Sort an input file that consists of lines like this
! #
  #         var1=23 other=14 ditto=23 fred=2
! #
  #     such that each output line is sorted WRT to the number.  Order
  #     of output lines does not change.  Resolve collisions using the
  #     variable name.   e.g.
! #
! #         fred=2 other=14 ditto=23 var1=23
! #
  #     Lines may be up to several kilobytes in length and contain
  #     zillions of variables.
***************
*** 24,50 ****
  # - Handles blank input lines correctly
  
! import regex
  import string
  import sys
  
  def main():
! 	prog = regex.compile('^\(.*\)=\([-+]?[0-9]+\)')
! 	def makekey(item, prog=prog):
! 		if prog.match(item) >= 0:
! 			var, num = prog.group(1, 2)
! 			return string.atoi(num), var
! 		else:
! 			# Bad input -- pretend it's a var with value 0
! 			return 0, item
! 	while 1:
! 		line = sys.stdin.readline()
! 		if not line:
! 			break
! 		items = string.split(line)
! 		items = map(makekey, items)
! 		items.sort()
! 		for num, var in items:
! 			print "%s=%s" % (var, num),
! 		print
  
  main()
--- 24,51 ----
  # - Handles blank input lines correctly
  
! import re
  import string
  import sys
  
  def main():
!     prog = re.compile('^(.*)=([-+]?[0-9]+)')
!     def makekey(item, prog=prog):
!         match = prog.match(item)
!         if match:
!             var, num = match.group(1, 2)
!             return string.atoi(num), var
!         else:
!             # Bad input -- pretend it's a var with value 0
!             return 0, item
!     while 1:
!         line = sys.stdin.readline()
!         if not line:
!             break
!         items = line.split()
!         items = map(makekey, items)
!         items.sort()
!         for num, var in items:
!             print "%s=%s" % (var, num),
!         print
  
  main()

Index: regextest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Demo/comparisons/regextest.py,v
retrieving revision 1.2
retrieving revision 1.2.30.1
diff -C2 -d -r1.2 -r1.2.30.1
*** regextest.py	27 Nov 1996 19:49:06 -0000	1.2
--- regextest.py	28 Apr 2003 17:39:07 -0000	1.2.30.1
***************
*** 2,12 ****
  
  # 1)  Regular Expressions Test
! # 
! #     Read a file of (extended per egrep) regular expressions (one per line), 
  #     and apply those to all files whose names are listed on the command line.
  #     Basically, an 'egrep -f' simulator.  Test it with 20 "vt100" patterns
  #     against a five /etc/termcap files.  Tests using more elaborate patters
  #     would also be interesting.  Your code should not break if given hundreds
! #     of regular expressions or binary files to scan.  
  
  # This implementation:
--- 2,12 ----
  
  # 1)  Regular Expressions Test
! #
! #     Read a file of (extended per egrep) regular expressions (one per line),
  #     and apply those to all files whose names are listed on the command line.
  #     Basically, an 'egrep -f' simulator.  Test it with 20 "vt100" patterns
  #     against a five /etc/termcap files.  Tests using more elaborate patters
  #     would also be interesting.  Your code should not break if given hundreds
! #     of regular expressions or binary files to scan.
  
  # This implementation:
***************
*** 19,50 ****
  import string
  import sys
! import regex
! from regex_syntax import *
! 
! regex.set_syntax(RE_SYNTAX_EGREP)
  
  def main():
! 	pats = map(chomp, sys.stdin.readlines())
! 	bigpat = '(' + string.joinfields(pats, '|') + ')'
! 	prog = regex.compile(bigpat)
! 	
! 	for file in sys.argv[1:]:
! 		try:
! 			fp = open(file, 'r')
! 		except IOError, msg:
! 			print "%s: %s" % (file, msg)
! 			continue
! 		lineno = 0
! 		while 1:
! 			line = fp.readline()
! 			if not line:
! 				break
! 			lineno = lineno + 1
! 			if prog.search(line) >= 0:
! 				print "%s:%s:%s" % (file, lineno, line),
  
  def chomp(s):
! 	if s[-1:] == '\n': return s[:-1]
! 	else: return s
  
  main()
--- 19,46 ----
  import string
  import sys
! import re
  
  def main():
!     pats = map(chomp, sys.stdin.readlines())
!     bigpat = '(' + '|'.join(pats) + ')'
!     prog = re.compile(bigpat)
! 
!     for file in sys.argv[1:]:
!         try:
!             fp = open(file, 'r')
!         except IOError, msg:
!             print "%s: %s" % (file, msg)
!             continue
!         lineno = 0
!         while 1:
!             line = fp.readline()
!             if not line:
!                 break
!             lineno = lineno + 1
!             if prog.search(line):
!                 print "%s:%s:%s" % (file, lineno, line),
  
  def chomp(s):
!     return s.rstrip('\n')
  
  main()