[Python-checkins] python/dist/src/Demo/scripts eqfix.py, 1.8,
1.9 fact.py, 1.6, 1.7 ftpstats.py, 1.5, 1.6 lpwatch.py, 1.8,
1.9 makedir.py, 1.4, 1.5 markov.py, 1.4, 1.5 mboxconvert.py,
1.5, 1.6 mkrcs.py, 1.5, 1.6 morse.py, 1.1, 1.2 mpzpi.py, 1.5,
1.6 newslist.py, 1.11, 1.12 pp.py, 1.6, 1.7 primes.py, 1.4,
1.5 script.py, 1.2, 1.3 update.py, 1.2, 1.3
tim_one at users.sourceforge.net
tim_one at users.sourceforge.net
Sun Jul 18 07:56:27 CEST 2004
- Previous message: [Python-checkins] python/dist/src/Demo/rpc T.py, 1.4,
1.5 mountclient.py, 1.8, 1.9 nfsclient.py, 1.10,
1.11 rnusersclient.py, 1.4, 1.5 rpc.py, 1.12, 1.13 xdr.py,
1.11, 1.12
- Next message: [Python-checkins] python/dist/src/Demo/sockets broadcast.py, 1.5,
1.6 echosvr.py, 1.7, 1.8 finger.py, 1.5, 1.6 ftp.py, 1.6,
1.7 gopher.py, 1.5, 1.6 mcast.py, 1.10, 1.11 radio.py, 1.4,
1.5 rpython.py, 1.2, 1.3 rpythond.py, 1.3, 1.4 telnet.py, 1.6,
1.7 throughput.py, 1.6, 1.7 udpecho.py, 1.6, 1.7 unicast.py,
1.2, 1.3 unixserver.py, 1.3, 1.4
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Demo/scripts
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28702/Demo/scripts
Modified Files:
eqfix.py fact.py ftpstats.py lpwatch.py makedir.py markov.py
mboxconvert.py mkrcs.py morse.py mpzpi.py newslist.py pp.py
primes.py script.py update.py
Log Message:
Whitespace normalization. Ran reindent.py over the entire source tree.
Index: eqfix.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Demo/scripts/eqfix.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** eqfix.py 12 Feb 2004 17:35:02 -0000 1.8
--- eqfix.py 18 Jul 2004 05:56:08 -0000 1.9
***************
*** 2,8 ****
# Fix Python source files to use the new equality test operator, i.e.,
! # if x = y: ...
# is changed to
! # if x == y: ...
# The script correctly tokenizes the Python program to reliably
# distinguish between assignments and equality tests.
--- 2,8 ----
# Fix Python source files to use the new equality test operator, i.e.,
! # if x = y: ...
# is changed to
! # if x == y: ...
# The script correctly tokenizes the Python program to reliably
# distinguish between assignments and equality tests.
***************
*** 40,163 ****
def main():
! bad = 0
! if not sys.argv[1:]: # No arguments
! err('usage: ' + sys.argv[0] + ' file-or-directory ...\n')
! sys.exit(2)
! for arg in sys.argv[1:]:
! if os.path.isdir(arg):
! if recursedown(arg): bad = 1
! elif os.path.islink(arg):
! err(arg + ': will not process symbolic links\n')
! bad = 1
! else:
! if fix(arg): bad = 1
! sys.exit(bad)
ispythonprog = regex.compile('^[a-zA-Z0-9_]+\.py$')
def ispython(name):
! return ispythonprog.match(name) >= 0
def recursedown(dirname):
! dbg('recursedown(%r)\n' % (dirname,))
! bad = 0
! try:
! names = os.listdir(dirname)
! except os.error, msg:
! err('%s: cannot list directory: %r\n' % (dirname, msg))
! return 1
! names.sort()
! subdirs = []
! for name in names:
! if name in (os.curdir, os.pardir): continue
! fullname = os.path.join(dirname, name)
! if os.path.islink(fullname): pass
! elif os.path.isdir(fullname):
! subdirs.append(fullname)
! elif ispython(name):
! if fix(fullname): bad = 1
! for fullname in subdirs:
! if recursedown(fullname): bad = 1
! return bad
def fix(filename):
! ## dbg('fix(%r)\n' % (dirname,))
! try:
! f = open(filename, 'r')
! except IOError, msg:
! err('%s: cannot open: %r\n' % (filename, msg))
! return 1
! head, tail = os.path.split(filename)
! tempname = os.path.join(head, '@' + tail)
! g = None
! # If we find a match, we rewind the file and start over but
! # now copy everything to a temp file.
! lineno = 0
! while 1:
! line = f.readline()
! if not line: break
! lineno = lineno + 1
! if g is None and '0円' in line:
! # Check for binary files
! err(filename + ': contains null bytes; not fixed\n')
! f.close()
! return 1
! if lineno == 1 and g is None and line[:2] == '#!':
! # Check for non-Python scripts
! words = string.split(line[2:])
! if words and regex.search('[pP]ython', words[0]) < 0:
! msg = filename + ': ' + words[0]
! msg = msg + ' script; not fixed\n'
! err(msg)
! f.close()
! return 1
! while line[-2:] == '\\\n':
! nextline = f.readline()
! if not nextline: break
! line = line + nextline
! lineno = lineno + 1
! newline = fixline(line)
! if newline != line:
! if g is None:
! try:
! g = open(tempname, 'w')
! except IOError, msg:
! f.close()
! err('%s: cannot create: %r\n' % (tempname, msg))
! return 1
! f.seek(0)
! lineno = 0
! rep(filename + ':\n')
! continue # restart from the beginning
! rep(repr(lineno) + '\n')
! rep('< ' + line)
! rep('> ' + newline)
! if g is not None:
! g.write(newline)
! # End of file
! f.close()
! if not g: return 0 # No changes
!
! # Finishing touch -- move files
! # First copy the file's mode to the temp file
! try:
! statbuf = os.stat(filename)
! os.chmod(tempname, statbuf[ST_MODE] & 07777)
! except os.error, msg:
! err('%s: warning: chmod failed (%r)\n' % (tempname, msg))
! # Then make a backup of the original file as filename~
! try:
! os.rename(filename, filename + '~')
! except os.error, msg:
! err('%s: warning: backup failed (%r)\n' % (filename, msg))
! # Now move the temp file to the original file
! try:
! os.rename(tempname, filename)
! except os.error, msg:
! err('%s: rename failed (%r)\n' % (filename, msg))
! return 1
! # Return succes
! return 0
--- 40,163 ----
def main():
! bad = 0
! if not sys.argv[1:]: # No arguments
! err('usage: ' + sys.argv[0] + ' file-or-directory ...\n')
! sys.exit(2)
! for arg in sys.argv[1:]:
! if os.path.isdir(arg):
! if recursedown(arg): bad = 1
! elif os.path.islink(arg):
! err(arg + ': will not process symbolic links\n')
! bad = 1
! else:
! if fix(arg): bad = 1
! sys.exit(bad)
ispythonprog = regex.compile('^[a-zA-Z0-9_]+\.py$')
def ispython(name):
! return ispythonprog.match(name) >= 0
def recursedown(dirname):
! dbg('recursedown(%r)\n' % (dirname,))
! bad = 0
! try:
! names = os.listdir(dirname)
! except os.error, msg:
! err('%s: cannot list directory: %r\n' % (dirname, msg))
! return 1
! names.sort()
! subdirs = []
! for name in names:
! if name in (os.curdir, os.pardir): continue
! fullname = os.path.join(dirname, name)
! if os.path.islink(fullname): pass
! elif os.path.isdir(fullname):
! subdirs.append(fullname)
! elif ispython(name):
! if fix(fullname): bad = 1
! for fullname in subdirs:
! if recursedown(fullname): bad = 1
! return bad
def fix(filename):
! ## dbg('fix(%r)\n' % (dirname,))
! try:
! f = open(filename, 'r')
! except IOError, msg:
! err('%s: cannot open: %r\n' % (filename, msg))
! return 1
! head, tail = os.path.split(filename)
! tempname = os.path.join(head, '@' + tail)
! g = None
! # If we find a match, we rewind the file and start over but
! # now copy everything to a temp file.
! lineno = 0
! while 1:
! line = f.readline()
! if not line: break
! lineno = lineno + 1
! if g is None and '0円' in line:
! # Check for binary files
! err(filename + ': contains null bytes; not fixed\n')
! f.close()
! return 1
! if lineno == 1 and g is None and line[:2] == '#!':
! # Check for non-Python scripts
! words = string.split(line[2:])
! if words and regex.search('[pP]ython', words[0]) < 0:
! msg = filename + ': ' + words[0]
! msg = msg + ' script; not fixed\n'
! err(msg)
! f.close()
! return 1
! while line[-2:] == '\\\n':
! nextline = f.readline()
! if not nextline: break
! line = line + nextline
! lineno = lineno + 1
! newline = fixline(line)
! if newline != line:
! if g is None:
! try:
! g = open(tempname, 'w')
! except IOError, msg:
! f.close()
! err('%s: cannot create: %r\n' % (tempname, msg))
! return 1
! f.seek(0)
! lineno = 0
! rep(filename + ':\n')
! continue # restart from the beginning
! rep(repr(lineno) + '\n')
! rep('< ' + line)
! rep('> ' + newline)
! if g is not None:
! g.write(newline)
! # End of file
! f.close()
! if not g: return 0 # No changes
! # Finishing touch -- move files
!
! # First copy the file's mode to the temp file
! try:
! statbuf = os.stat(filename)
! os.chmod(tempname, statbuf[ST_MODE] & 07777)
! except os.error, msg:
! err('%s: warning: chmod failed (%r)\n' % (tempname, msg))
! # Then make a backup of the original file as filename~
! try:
! os.rename(filename, filename + '~')
! except os.error, msg:
! err('%s: warning: backup failed (%r)\n' % (filename, msg))
! # Now move the temp file to the original file
! try:
! os.rename(tempname, filename)
! except os.error, msg:
! err('%s: rename failed (%r)\n' % (filename, msg))
! return 1
! # Return succes
! return 0
***************
*** 165,197 ****
match = {'if':':', 'elif':':', 'while':':', 'return':'\n', \
! '(':')', '[':']', '{':'}', '`':'`'}
def fixline(line):
! # Quick check for easy case
! if '=' not in line: return line
!
! i, n = 0, len(line)
! stack = []
! while i < n:
! j = tokenprog.match(line, i)
! if j < 0:
! # A bad token; forget about the rest of this line
! print '(Syntax error:)'
! print line,
! return line
! a, b = tokenprog.regs[3] # Location of the token proper
! token = line[a:b]
! i = i+j
! if stack and token == stack[-1]:
! del stack[-1]
! elif match.has_key(token):
! stack.append(match[token])
! elif token == '=' and stack:
! line = line[:a] + '==' + line[b:]
! i, n = a + len('=='), len(line)
! elif token == '==' and not stack:
! print '(Warning: \'==\' at top level:)'
! print line,
! return line
--- 165,197 ----
match = {'if':':', 'elif':':', 'while':':', 'return':'\n', \
! '(':')', '[':']', '{':'}', '`':'`'}
def fixline(line):
! # Quick check for easy case
! if '=' not in line: return line
!
! i, n = 0, len(line)
! stack = []
! while i < n:
! j = tokenprog.match(line, i)
! if j < 0:
! # A bad token; forget about the rest of this line
! print '(Syntax error:)'
! print line,
! return line
! a, b = tokenprog.regs[3] # Location of the token proper
! token = line[a:b]
! i = i+j
! if stack and token == stack[-1]:
! del stack[-1]
! elif match.has_key(token):
! stack.append(match[token])
! elif token == '=' and stack:
! line = line[:a] + '==' + line[b:]
! i, n = a + len('=='), len(line)
! elif token == '==' and not stack:
! print '(Warning: \'==\' at top level:)'
! print line,
! return line
Index: fact.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Demo/scripts/fact.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** fact.py 27 Nov 1996 19:46:48 -0000 1.6
--- fact.py 18 Jul 2004 05:56:08 -0000 1.7
***************
*** 9,48 ****
from math import sqrt
! error = 'fact.error' # exception
def fact(n):
! if n < 1: raise error # fact() argument should be >= 1
! if n == 1: return [] # special case
! res = []
! # Treat even factors special, so we can use i = i+2 later
! while n%2 == 0:
! res.append(2)
! n = n/2
! # Try odd numbers up to sqrt(n)
! limit = sqrt(float(n+1))
! i = 3
! while i <= limit:
! if n%i == 0:
! res.append(i)
! n = n/i
! limit = sqrt(n+1)
! else:
! i = i+2
! if n != 1:
! res.append(n)
! return res
def main():
! if len(sys.argv) > 1:
! for arg in sys.argv[1:]:
! n = eval(arg)
! print n, fact(n)
! else:
! try:
! while 1:
! n = input()
! print n, fact(n)
! except EOFError:
! pass
main()
--- 9,48 ----
from math import sqrt
! error = 'fact.error' # exception
def fact(n):
! if n < 1: raise error # fact() argument should be >= 1
! if n == 1: return [] # special case
! res = []
! # Treat even factors special, so we can use i = i+2 later
! while n%2 == 0:
! res.append(2)
! n = n/2
! # Try odd numbers up to sqrt(n)
! limit = sqrt(float(n+1))
! i = 3
! while i <= limit:
! if n%i == 0:
! res.append(i)
! n = n/i
! limit = sqrt(n+1)
! else:
! i = i+2
! if n != 1:
! res.append(n)
! return res
def main():
! if len(sys.argv) > 1:
! for arg in sys.argv[1:]:
! n = eval(arg)
! print n, fact(n)
! else:
! try:
! while 1:
! n = input()
! print n, fact(n)
! except EOFError:
! pass
main()
Index: ftpstats.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Demo/scripts/ftpstats.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** ftpstats.py 17 Jul 2004 14:44:17 -0000 1.5
--- ftpstats.py 18 Jul 2004 05:56:08 -0000 1.6
***************
*** 22,144 ****
def main():
! maxitems = 25
! search = None
! try:
! opts, args = getopt.getopt(sys.argv[1:], 'm:s:')
! except getopt.error, msg:
! print msg
! print 'usage: ftpstats [-m maxitems] [file]'
! sys.exit(2)
! for o, a in opts:
! if o == '-m':
! maxitems = string.atoi(a)
! if o == '-s':
! search = a
! file = '/usr/adm/ftpd'
! if args: file = args[0]
! if file == '-':
! f = sys.stdin
! else:
! try:
! f = open(file, 'r')
! except IOError, msg:
! print file, ':', msg
! sys.exit(1)
! bydate = {}
! bytime = {}
! byfile = {}
! bydir = {}
! byhost = {}
! byuser = {}
! bytype = {}
! lineno = 0
! try:
! while 1:
! line = f.readline()
! if not line: break
! lineno = lineno + 1
! if search and string.find(line, search) < 0:
! continue
! if prog.match(line) < 0:
! print 'Bad line', lineno, ':', repr(line)
! continue
! items = prog.group(1, 2, 3, 4, 5, 6)
! (logtime, loguser, loghost, logfile, logbytes,
! logxxx2) = items
! ## print logtime
! ## print '-->', loguser
! ## print '--> -->', loghost
! ## print '--> --> -->', logfile
! ## print '--> --> --> -->', logbytes
! ## print '--> --> --> --> -->', logxxx2
! ## for i in logtime, loghost, logbytes, logxxx2:
! ## if '!' in i: print '???', i
! add(bydate, logtime[-4:] + ' ' + logtime[:6], items)
! add(bytime, logtime[7:9] + ':00-59', items)
! direction, logfile = logfile[0], logfile[1:]
! # The real path probably starts at the last //...
! while 1:
! i = string.find(logfile, '//')
! if i < 0: break
! logfile = logfile[i+1:]
! add(byfile, logfile + ' ' + direction, items)
! logdir = os.path.dirname(logfile)
! ## logdir = os.path.normpath(logdir) + '/.'
! while 1:
! add(bydir, logdir + ' ' + direction, items)
! dirhead = os.path.dirname(logdir)
! if dirhead == logdir: break
! logdir = dirhead
! add(byhost, loghost, items)
! add(byuser, loguser, items)
! add(bytype, direction, items)
! except KeyboardInterrupt:
! print 'Interrupted at line', lineno
! show(bytype, 'by transfer direction', maxitems)
! show(bydir, 'by directory', maxitems)
! show(byfile, 'by file', maxitems)
! show(byhost, 'by host', maxitems)
! show(byuser, 'by user', maxitems)
! showbar(bydate, 'by date')
! showbar(bytime, 'by time of day')
def showbar(dict, title):
! n = len(title)
! print '='*((70-n)/2), title, '='*((71-n)/2)
! list = []
! keys = dict.keys()
! keys.sort()
! for key in keys:
! n = len(str(key))
! list.append((len(dict[key]), key))
! maxkeylength = 0
! maxcount = 0
! for count, key in list:
! maxkeylength = max(maxkeylength, len(key))
! maxcount = max(maxcount, count)
! maxbarlength = 72 - maxkeylength - 7
! for count, key in list:
! barlength = int(round(maxbarlength*float(count)/maxcount))
! bar = '*'*barlength
! print '%5d %-*s %s' % (count, maxkeylength, key, bar)
def show(dict, title, maxitems):
! if len(dict) > maxitems:
! title = title + ' (first %d)'%maxitems
! n = len(title)
! print '='*((70-n)/2), title, '='*((71-n)/2)
! list = []
! keys = dict.keys()
! for key in keys:
! list.append((-len(dict[key]), key))
! list.sort()
! for count, key in list[:maxitems]:
! print '%5d %s' % (-count, key)
def add(dict, key, item):
! if dict.has_key(key):
! dict[key].append(item)
! else:
! dict[key] = [item]
main()
--- 22,144 ----
def main():
! maxitems = 25
! search = None
! try:
! opts, args = getopt.getopt(sys.argv[1:], 'm:s:')
! except getopt.error, msg:
! print msg
! print 'usage: ftpstats [-m maxitems] [file]'
! sys.exit(2)
! for o, a in opts:
! if o == '-m':
! maxitems = string.atoi(a)
! if o == '-s':
! search = a
! file = '/usr/adm/ftpd'
! if args: file = args[0]
! if file == '-':
! f = sys.stdin
! else:
! try:
! f = open(file, 'r')
! except IOError, msg:
! print file, ':', msg
! sys.exit(1)
! bydate = {}
! bytime = {}
! byfile = {}
! bydir = {}
! byhost = {}
! byuser = {}
! bytype = {}
! lineno = 0
! try:
! while 1:
! line = f.readline()
! if not line: break
! lineno = lineno + 1
! if search and string.find(line, search) < 0:
! continue
! if prog.match(line) < 0:
! print 'Bad line', lineno, ':', repr(line)
! continue
! items = prog.group(1, 2, 3, 4, 5, 6)
! (logtime, loguser, loghost, logfile, logbytes,
! logxxx2) = items
! ## print logtime
! ## print '-->', loguser
! ## print '--> -->', loghost
! ## print '--> --> -->', logfile
! ## print '--> --> --> -->', logbytes
! ## print '--> --> --> --> -->', logxxx2
! ## for i in logtime, loghost, logbytes, logxxx2:
! ## if '!' in i: print '???', i
! add(bydate, logtime[-4:] + ' ' + logtime[:6], items)
! add(bytime, logtime[7:9] + ':00-59', items)
! direction, logfile = logfile[0], logfile[1:]
! # The real path probably starts at the last //...
! while 1:
! i = string.find(logfile, '//')
! if i < 0: break
! logfile = logfile[i+1:]
! add(byfile, logfile + ' ' + direction, items)
! logdir = os.path.dirname(logfile)
! ## logdir = os.path.normpath(logdir) + '/.'
! while 1:
! add(bydir, logdir + ' ' + direction, items)
! dirhead = os.path.dirname(logdir)
! if dirhead == logdir: break
! logdir = dirhead
! add(byhost, loghost, items)
! add(byuser, loguser, items)
! add(bytype, direction, items)
! except KeyboardInterrupt:
! print 'Interrupted at line', lineno
! show(bytype, 'by transfer direction', maxitems)
! show(bydir, 'by directory', maxitems)
! show(byfile, 'by file', maxitems)
! show(byhost, 'by host', maxitems)
! show(byuser, 'by user', maxitems)
! showbar(bydate, 'by date')
! showbar(bytime, 'by time of day')
def showbar(dict, title):
! n = len(title)
! print '='*((70-n)/2), title, '='*((71-n)/2)
! list = []
! keys = dict.keys()
! keys.sort()
! for key in keys:
! n = len(str(key))
! list.append((len(dict[key]), key))
! maxkeylength = 0
! maxcount = 0
! for count, key in list:
! maxkeylength = max(maxkeylength, len(key))
! maxcount = max(maxcount, count)
! maxbarlength = 72 - maxkeylength - 7
! for count, key in list:
! barlength = int(round(maxbarlength*float(count)/maxcount))
! bar = '*'*barlength
! print '%5d %-*s %s' % (count, maxkeylength, key, bar)
def show(dict, title, maxitems):
! if len(dict) > maxitems:
! title = title + ' (first %d)'%maxitems
! n = len(title)
! print '='*((70-n)/2), title, '='*((71-n)/2)
! list = []
! keys = dict.keys()
! for key in keys:
! list.append((-len(dict[key]), key))
! list.sort()
! for count, key in list[:maxitems]:
! print '%5d %s' % (-count, key)
def add(dict, key, item):
! if dict.has_key(key):
! dict[key].append(item)
! else:
! dict[key] = [item]
main()
- Previous message: [Python-checkins] python/dist/src/Demo/rpc T.py, 1.4,
1.5 mountclient.py, 1.8, 1.9 nfsclient.py, 1.10,
1.11 rnusersclient.py, 1.4, 1.5 rpc.py, 1.12, 1.13 xdr.py,
1.11, 1.12
- Next message: [Python-checkins] python/dist/src/Demo/sockets broadcast.py, 1.5,
1.6 echosvr.py, 1.7, 1.8 finger.py, 1.5, 1.6 ftp.py, 1.6,
1.7 gopher.py, 1.5, 1.6 mcast.py, 1.10, 1.11 radio.py, 1.4,
1.5 rpython.py, 1.2, 1.3 rpythond.py, 1.3, 1.4 telnet.py, 1.6,
1.7 throughput.py, 1.6, 1.7 udpecho.py, 1.6, 1.7 unicast.py,
1.2, 1.3 unixserver.py, 1.3, 1.4
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Python-checkins
mailing list