From 4710c53dcad1ebf3755f3efb9e80ac24bd72a9b2 Mon Sep 17 00:00:00 2001 From: darylm503 Date: Mon, 16 Apr 2012 22:12:42 +0000 Subject: AppPkg/Applications/Python: Add Python 2.7.2 sources since the release of Python 2.7.3 made them unavailable from the python.org web site. These files are a subset of the python-2.7.2.tgz distribution from python.org. Changed files from PyMod-2.7.2 have been copied into the corresponding directories of this tree, replacing the original files in the distribution. Signed-off-by: daryl.mcdaniel@intel.com git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13197 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Python/Python-2.7.2/Demo/comparisons/README | 60 ++++++++++++++++++ .../Python/Python-2.7.2/Demo/comparisons/patterns | 4 ++ .../Python-2.7.2/Demo/comparisons/regextest.py | 47 ++++++++++++++ .../Python-2.7.2/Demo/comparisons/sortingtest.py | 45 +++++++++++++ .../Python-2.7.2/Demo/comparisons/systemtest.py | 74 ++++++++++++++++++++++ 5 files changed, 230 insertions(+) create mode 100644 AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/README create mode 100644 AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/patterns create mode 100644 AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/regextest.py create mode 100644 AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/sortingtest.py create mode 100644 AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/systemtest.py (limited to 'AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons') diff --git a/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/README b/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/README new file mode 100644 index 0000000000..af86febbe9 --- /dev/null +++ b/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/README @@ -0,0 +1,60 @@ +Subject: Re: What language would you use? +From: Tom Christiansen +Date: 6 Nov 1994 15:14:51 GMT +Newsgroups: comp.lang.python,comp.lang.tcl,comp.lang.scheme,comp.lang.misc,comp.lang.perl +Message-Id: <39irtb$3t4@csnews.cs.Colorado.EDU> +References: <39b7ha$j9v@zeno.nscf.org> <39hhjp$lgn@csnews.cs.Colorado.EDU> <39hvsu$dus@mathserv.mps.ohio-state.edu> + +[...] +If you're really into benchmarks, I'd love it if someone were to code up +the following problems in tcl, python, and scheme (and whatever else you'd +like). Separate versions (one optimized for speed, one for beauty :-) are +ok. Post your code so we can time it on our own systems. + +0) Factorial Test (numerics and function calls) + + (we did this already) + +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. + +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. + +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 + be resolved because it points to a nonexistent or otherwise + unresolvable file. Do *not* use an external find executable. + Directories may be very very deep. Print a warning immediately if the + system you're running on doesn't support symbolic links. + + +I'll post perl solutions if people post the others. + + +--tom +-- +Tom Christiansen Perl Consultant, Gamer, Hiker tchrist@mox.perl.com + + "But Billy! A *small* allowance prepares you for a lifetime of small + salaries and for your Social Security payments." --Family Circus diff --git a/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/patterns b/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/patterns new file mode 100644 index 0000000000..11ec3faa2f --- /dev/null +++ b/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/patterns @@ -0,0 +1,4 @@ +^def +^class +^import +^from diff --git a/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/regextest.py b/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/regextest.py new file mode 100644 index 0000000000..19617a3ce0 --- /dev/null +++ b/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/regextest.py @@ -0,0 +1,47 @@ +#! /usr/bin/env python + +# 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: +# - combines all patterns into a single one using ( ... | ... | ... ) +# - reads patterns from stdin, scans files given as command line arguments +# - produces output in the format :: +# - is only about 2.5 times as slow as egrep (though I couldn't run +# Tom's test -- this system, a vanilla SGI, only has /etc/terminfo) + +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') + +if __name__ == '__main__': + main() diff --git a/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/sortingtest.py b/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/sortingtest.py new file mode 100644 index 0000000000..e19f63eb52 --- /dev/null +++ b/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/sortingtest.py @@ -0,0 +1,45 @@ +#! /usr/bin/env python + +# 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. + +# This implementation: +# - Reads stdin, writes stdout +# - Uses any amount of whitespace to separate fields +# - Allows signed numbers +# - Treats illegally formatted fields as field=0 +# - Outputs the sorted fields with exactly one space between them +# - Handles blank input lines correctly + +import re +import sys + +def main(): + prog = re.compile('^(.*)=([-+]?[0-9]+)') + def makekey(item, prog=prog): + match = prog.match(item) + if match: + var, num = match.groups() + return int(num), var + else: + # Bad input -- pretend it's a var with value 0 + return 0, item + for line in sys.stdin: + items = sorted(makekey(item) for item in line.split()) + for num, var in items: + print "%s=%s" % (var, num), + print + +main() diff --git a/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/systemtest.py b/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/systemtest.py new file mode 100644 index 0000000000..a715fe0d42 --- /dev/null +++ b/AppPkg/Applications/Python/Python-2.7.2/Demo/comparisons/systemtest.py @@ -0,0 +1,74 @@ +#! /usr/bin/env python + +# 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 +# be resolved because it points to a nonexistent or otherwise +# unresolvable file. Do *not* use an external find executable. +# Directories may be very very deep. Print a warning immediately if the +# system you're running on doesn't support symbolic links. + +# This implementation: +# - takes one optional argument, using the current directory as default +# - uses chdir to increase performance +# - sorts the names per directory +# - prints output lines of the form "path1 -> path2" as it goes +# - prints error messages about directories it can't list or chdir into + +import os +import sys +from stat import * + +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() -- cgit v1.2.3