Replace backticks with repr() or "%r"

From SF patch #852334.
This commit is contained in:
Walter Dörwald 2004-02-12 17:35:32 +00:00
parent ecfeb7f095
commit 70a6b49821
246 changed files with 926 additions and 962 deletions

View file

@ -58,12 +58,12 @@ def ispython(name):
return ispythonprog.match(name) >= 0
def recursedown(dirname):
dbg('recursedown(' + `dirname` + ')\n')
dbg('recursedown(%r)\n' % (dirname,))
bad = 0
try:
names = os.listdir(dirname)
except os.error, msg:
err(dirname + ': cannot list directory: ' + `msg` + '\n')
err('%s: cannot list directory: %r\n' % (dirname, msg))
return 1
names.sort()
subdirs = []
@ -80,11 +80,11 @@ def recursedown(dirname):
return bad
def fix(filename):
## dbg('fix(' + `filename` + ')\n')
## dbg('fix(%r)\n' % (dirname,))
try:
f = open(filename, 'r')
except IOError, msg:
err(filename + ': cannot open: ' + `msg` + '\n')
err('%s: cannot open: %r\n' % (filename, msg))
return 1
head, tail = os.path.split(filename)
tempname = os.path.join(head, '@' + tail)
@ -122,14 +122,13 @@ def fix(filename):
g = open(tempname, 'w')
except IOError, msg:
f.close()
err(tempname+': cannot create: '+\
`msg`+'\n')
err('%s: cannot create: %r\n' % (tempname, msg))
return 1
f.seek(0)
lineno = 0
rep(filename + ':\n')
continue # restart from the beginning
rep(`lineno` + '\n')
rep(repr(lineno) + '\n')
rep('< ' + line)
rep('> ' + newline)
if g is not None:
@ -146,17 +145,17 @@ def fix(filename):
statbuf = os.stat(filename)
os.chmod(tempname, statbuf[ST_MODE] & 07777)
except os.error, msg:
err(tempname + ': warning: chmod failed (' + `msg` + ')\n')
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(filename + ': warning: backup failed (' + `msg` + ')\n')
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(filename + ': rename failed (' + `msg` + ')\n')
err('%s: rename failed (%r)\n' % (filename, msg))
return 1
# Return succes
return 0

View file

@ -31,5 +31,5 @@ while 1:
if not line or line == '\n':
break
if line.startswith('Subject: '):
print `line[9:-1]`,
print repr(line[9:-1]),
print

View file

@ -60,7 +60,7 @@ def main():
if search and string.find(line, search) < 0:
continue
if prog.match(line) < 0:
print 'Bad line', lineno, ':', `line`
print 'Bad line', lineno, ':', repr(line)
continue
items = prog.group(1, 2, 3, 4, 5, 6)
(logtime, loguser, loghost, logfile, logbytes,

View file

@ -83,24 +83,24 @@ def makestatus(name, thisuser):
lines.append(line)
#
if totaljobs:
line = `(totalbytes+1023)/1024` + ' K'
line = '%d K' % ((totalbytes+1023)/1024)
if totaljobs <> len(users):
line = line + ' (' + `totaljobs` + ' jobs)'
line = line + ' (%d jobs)' % totaljobs
if len(users) == 1:
line = line + ' for ' + users.keys()[0]
line = line + ' for %s' % (users.keys()[0],)
else:
line = line + ' for ' + `len(users)` + ' users'
line = line + ' for %d users' % len(users)
if userseen:
if aheadjobs == 0:
line = line + ' (' + thisuser + ' first)'
line = line + ' (%s first)' % thisuser
else:
line = line + ' (' + `(aheadbytes+1023)/1024`
line = line + ' K before ' + thisuser + ')'
line = line + ' (%d K before %s)' % (
(aheadbytes+1023)/1024, thisuser)
lines.append(line)
#
sts = pipe.close()
if sts:
lines.append('lpq exit status ' + `sts`)
lines.append('lpq exit status %r' % (sts,))
return string.joinfields(lines, ': ')
try:

View file

@ -89,8 +89,8 @@ def test():
if debug > 1:
for key in m.trans.keys():
if key is None or len(key) < histsize:
print `key`, m.trans[key]
if histsize == 0: print `''`, m.trans['']
print repr(key), m.trans[key]
if histsize == 0: print repr(''), m.trans['']
print
while 1:
data = m.get()

View file

@ -73,7 +73,7 @@ def mmdf(f):
sts = message(f, line) or sts
else:
sys.stderr.write(
'Bad line in MMFD mailbox: %s\n' % `line`)
'Bad line in MMFD mailbox: %r\n' % (line,))
return sts
counter = 0 # for generating unique Message-ID headers
@ -89,7 +89,7 @@ def message(f, delimiter = ''):
t = time.mktime(tt)
else:
sys.stderr.write(
'Unparseable date: %s\n' % `m.getheader('Date')`)
'Unparseable date: %r\n' % (m.getheader('Date'),))
t = os.fstat(f.fileno())[stat.ST_MTIME]
print 'From', email, time.ctime(t)
# Copy RFC822 header

View file

@ -12,13 +12,13 @@ def main():
rcstree = 'RCStree'
rcs = 'RCS'
if os.path.islink(rcs):
print `rcs`, 'is a symlink to', `os.readlink(rcs)`
print '%r is a symlink to %r' % (rcs, os.readlink(rcs))
return
if os.path.isdir(rcs):
print `rcs`, 'is an ordinary directory'
print '%r is an ordinary directory' % (rcs,)
return
if os.path.exists(rcs):
print `rcs`, 'is a file?!?!'
print '%r is a file?!?!' % (rcs,)
return
#
p = os.getcwd()
@ -29,26 +29,26 @@ def main():
# (2) up is the same directory as p
# Ergo:
# (3) join(up, down) is the current directory
#print 'p =', `p`
#print 'p =', repr(p)
while not os.path.isdir(os.path.join(p, rcstree)):
head, tail = os.path.split(p)
#print 'head =', `head`, '; tail =', `tail`
#print 'head = %r; tail = %r' % (head, tail)
if not tail:
print 'Sorry, no ancestor dir contains', `rcstree`
print 'Sorry, no ancestor dir contains %r' % (rcstree,)
return
p = head
up = os.path.join(os.pardir, up)
down = os.path.join(tail, down)
#print 'p =', `p`, '; up =', `up`, '; down =', `down`
#print 'p = %r; up = %r; down = %r' % (p, up, down)
there = os.path.join(up, rcstree)
there = os.path.join(there, down)
there = os.path.join(there, rcs)
if os.path.isdir(there):
print `there`, 'already exists'
print '%r already exists' % (there, )
else:
print 'making', `there`
print 'making %r' % (there,)
makedirs(there)
print 'making symlink', `rcs`, '->', `there`
print 'making symlink %r -> %r' % (rcs, there)
os.symlink(there, rcs)
def makedirs(p):

View file

@ -27,7 +27,7 @@ def main():
def output(d):
# Use write() to avoid spaces between the digits
# Use int(d) to avoid a trailing L after each digit
sys.stdout.write(`int(d)`)
sys.stdout.write(repr(int(d)))
# Flush so the output is seen immediately
sys.stdout.flush()

View file

@ -304,7 +304,7 @@ def getallgroups(server):
def getnewgroups(server, treedate):
print 'Getting list of new groups since start of '+treedate+'...',
info = server.newgroups(treedate,'000001')[1]
print 'got '+`len(info)`+'.'
print 'got %d.' % len(info)
print 'Processing...',
groups = []
for i in info:

View file

@ -125,6 +125,6 @@ fp.write(program)
fp.flush()
if DFLAG:
import pdb
pdb.run('execfile(' + `tfn` + ')')
pdb.run('execfile(%r)' % (tfn,))
else:
execfile(tfn)