8000 Fix most trivially-findable print statements. · python/cpython@be19ed7 · GitHub
[go: up one dir, main page]

Skip to content

Commit be19ed7

Browse files
committed
Fix most trivially-findable print statements.
There's one major and one minor category still unfixed: doctests are the major category (and I hope to be able to augment the refactoring tool to refactor bona fide doctests soon); other code generating print statements in strings is the minor category. (Oh, and I don't know if the compiler package works.)
1 parent 452bf51 commit be19ed7

File tree

331 files changed

+2568
-2649
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

331 files changed

+2568
-2649
lines changed

Lib/BaseHTTPServer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ def test(HandlerClass = BaseHTTPRequestHandler,
570570
httpd = ServerClass(server_address, HandlerClass)
571571

572572
sa = httpd.socket.getsockname()
573-
print "Serving HTTP on", sa[0], "port", sa[1], "..."
573+
print("Serving HTTP on", sa[0], "port", sa[1], "...")
574574
httpd.serve_forever()
575575

576576

Lib/Bastion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def total(self):
165165
print "accessible"
166166
\n"""
167167
exec(testcode)
168-
print '='*20, "Using rexec:", '='*20
168+
print('='*20, "Using rexec:", '='*20)
169169
import rexec
170170
r = rexec.RExec()
171171
m = r.add_module('__main__')

Lib/Cookie.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@
8080
>>> C = Cookie.SmartCookie()
8181
>>> C["rocky"] = "road"
8282
>>> C["rocky"]["path"] = "/cookie"
83-
>>> print C.output(header="Cookie:")
83+
>>> print(C.output(header="Cookie:"))
8484
Cookie: rocky=road; Path=/cookie
85-
>>> print C.output(attrs=[], header="Cookie:")
85+
>>> print(C.output(attrs=[], header="Cookie:"))
8686
Cookie: rocky=road
8787
8888
The load() method of a Cookie extracts cookies from a string. In a
@@ -100,7 +100,7 @@
100100
101101
>>> C = Cookie.SmartCookie()
102102
>>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=\\012;";')
103-
>>> print C
103+
>>> print(C)
104104
Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=\012;"
105105
106106
Each element of the Cookie also supports all of the RFC 2109
@@ -110,7 +110,7 @@
110110
>>> C = Cookie.SmartCookie()
111111
>>> C["oreo"] = "doublestuff"
112112
>>> C["oreo"]["path"] = "/"
113-
>>> print C
113+
>>> print(C)
114114
Set-Cookie: oreo=doublestuff; Path=/
115115
116116
Each dictionary element has a 'value' attribute, which gives you
@@ -198,7 +198,7 @@
198198
fact, this simply returns a SmartCookie.
199199
200200
>>> C = Cookie.Cookie()
201-
>>> print C.__class__.__name__
201+
>>> print(C.__class__.__name__)
202202
SmartCookie
203203
204204

Lib/DocXMLRPCServer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ def handle_get(self):
270270

271271
response = self.generate_html_documentation()
272272

273-
print 'Content-Type: text/html'
274-
print 'Content-Length: %d' % len(response)
275-
print
273+
print('Content-Type: text/html')
274+
print('Content-Length: %d' % len(response))
275+
print()
276276
sys.stdout.write(response)
277277

278278
def __init__(self):

Lib/SimpleXMLRPCServer.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,9 @@ def handle_xmlrpc(self, request_text):
543543

544544
response = self._marshaled_dispatch(request_text)
545545

546-
print 'Content-Type: text/xml'
547-
print 'Content-Length: %d' % len(response)
548-
print
546+
print('Content-Type: text/xml')
547+
print('Content-Length: %d' % len(response))
548+
print()
549549
sys.stdout.write(response)
550550

551551
def handle_get(self):
@@ -565,10 +565,10 @@ def handle_get(self):
565565
'message' : message,
566566
'explain' : explain
567567
}
568-
print 'Status: %d %s' % (code, message)
569-
print 'Content-Type: text/html'
570-
print 'Content-Length: %d' % len(response)
571-
print
568+
print('Status: %d %s' % (code, message))
569+
print('Content-Type: text/html')
570+
print('Content-Length: %d' % len(response))
571+
print()
572572
sys.stdout.write(response)
573573

574574
def handle_request(self, request_text = None):
@@ -590,7 +590,7 @@ def handle_request(self, request_text = None):
590590
self.handle_xmlrpc(request_text)
591591

592592
if __name__ == '__main__':
593-
print 'Running XML-RPC server on port 8000'
593+
print('Running XML-RPC server on port 8000')
594594
server = SimpleXMLRPCServer(("localhost", 8000))
595595
server.register_function(pow)
596596
server.register_function(lambda x,y: x+y, 'add')

Lib/SocketServer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,12 @@ def handle_error(self, request, client_address):
263263
The default is to print a traceback and continue.
264264
265265
"""
266-
print '-'*40
267-
print 'Exception happened during processing of request from',
268-
print client_address
266+
print('-'*40)
267+
print('Exception happened during processing of request from', end=' ')
268+
print(client_address)
269269
import traceback
270270
traceback.print_exc() # XXX But this goes to stderr!
271-
print '-'*40
271+
print('-'*40)
272272

273273

274274
class TCPServer(BaseServer):

Lib/StringIO.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,14 @@ def test():
291291
if f.getvalue() != text:
292292
raise RuntimeError, 'write failed'
293293 D7AE
length = f.tell()
294-
print 'File length =', length
294+
print('File length =', length)
295295
f.seek(len(lines[0]))
296296
f.write(lines[1])
297297
f.seek(0)
298-
print 'First line =', repr(f.readline())
299-
print 'Position =', f.tell()
298+
print('First line =', repr(f.readline()))
299+
print('Position =', f.tell())
300300
line = f.readline()
301-
print 'Second line =', repr(line)
301+
print('Second line =', repr(line))
302302
f.seek(-len(line), 1)
303303
line2 = f.read(len(line))
304304
if line != line2:
@@ -310,13 +310,13 @@ def test():
310310
line2 = f.read()
311311
if line != line2:
312312
raise RuntimeError, 'bad result after seek back from EOF'
313-
print 'Read', len(list), 'more lines'
314-
print 'File length =', f.tell()
313+
print('Read', len(list), 'more lines')
314+
print('File length =', f.tell())
315315
if f.tell() != length:
316316
raise RuntimeError, 'bad length'
317317
f.truncate(length/2)
318318
f.seek(0, 2)
319-
print 'Truncated length =', f.tell()
319+
print('Truncated length =', f.tell())
320320
if f.tell() != length/2:
321321
raise RuntimeError, 'truncate did not adjust length'
322322
f.close()

Lib/aifc.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ def _read_comm_chunk(self, chunk):
453453
kludge = 0
454454
if chunk.chunksize == 18:
455455
kludge = 1
456-
print 'Warning: bad COMM chunk size'
456+
print('Warning: bad COMM chunk size')
457457
chunk.chunksize = 23
458458
#DEBUG end
459459
self._comptype = chunk.read(4)
@@ -518,11 +518,11 @@ def _readmark(self, chunk):
518518
# a position 0 and name ''
519519
self._markers.append((id, pos, name))
520520
except EOFError:
521-
print 'Warning: MARK chunk contains only',
522-
print len(self._markers),
523-
if len(self._markers) == 1: print 'marker',
524-
else: print 'markers',
525-
print 'instead of', nmarkers
521+
print('Warning: MARK chunk contains only', end=' ')
522+
print(len(self._markers), end=' ')
523+
if len(self._markers) == 1: print('marker', end=' ')
524+
else: print('markers', end=' ')
525+
print('instead of', nmarkers)
526526

527527
class Aifc_write:
528528
# Variables used in this class:
@@ -939,16 +939,16 @@ def open(f, mode=None):
939939
sys.argv.append('/usr/demos/data/audio/bach.aiff')
940940
fn = sys.argv[1]
941941
f = open(fn, 'r')
942-
print "Reading", fn
943-
print "nchannels =", f.getnchannels()
944-
print "nframes =", f.getnframes()
945-
print "sampwidth =", f.getsampwidth()
946-
print "framerate =", f.getframerate()
947-
print "comptype =", f.getcomptype()
948-
print "compname =", f.getcompname()
942+
print("Reading", fn)
943+
print("nchannels =", f.getnchannels())
944+
print("nframes =", f.getnframes())
945+
print("sampwidth =", f.getsampwidth())
946+
print("framerate =", f.getframerate())
947+
print("comptype =", f.getcomptype())
948+
print("compname =", f.getcompname())
949949
if sys.argv[2:]:
950950
gn = sys.argv[2]
951-
print "Writing", gn
951+
print("Writing", gn)
952952
g = open(gn, 'w')
953953
g.setparams(f.getparams())
954954
while 1:
@@ -958,4 +958,4 @@ def open(f, mode=None):
958958
g.writeframes(data)
959959
g.close()
960960
f.close()
961-
print "Done."
961+
print("Done.")

Lib/asyncore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def log(self, message):
373373

374374
def log_info(self, message, type='info'):
375375
if __debug__ or type != 'info':
376-
print '%s: %s' % (type, message)
376+
print('%s: %s' % (type, message))
377377

378378
def handle_read_event(self):
379379
if self.accepting:

Lib/atexit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _run_exitfuncs():
2626
exc_info = sys.exc_info()
2727
except:
2828
import traceback
29-
print >> sys.stderr, "Error in atexit._run_exitfuncs:"
29+
print("Error in atexit._run_exitfuncs:", file=sys.stderr)
3030
traceback.print_exc()
3131
exc_info = sys.exc_info()
3232

@@ -53,11 +53,11 @@ def register(func, *targs, **kargs):
5353

5454
if __name__ == "__main__":
5555
def x1():
56-
print "running x1"
56+
print("running x1")
5757
def x2(n):
58-
print "running x2(%r)" % (n,)
58+
print("running x2(%r)" % (n,))
5959
def x3(n, kwd=None):
60-
print "running x3(%r, kwd=%r)" % (n, kwd)
60+
print("running x3(%r, kwd=%r)" % (n, kwd))
6161

6262
register(x1)
6363
register(x2, 12)

Lib/audiodev.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def test(fn = None):
240240
fn = 'f:just samples:just.aif'
241241
import aifc
242242
af = aifc.open(fn, 'r')
243-
print fn, af.getparams()
243+
print(fn, af.getparams())
244244
p = AudioDev()
245245
p.setoutrate(af.getframerate())
246246
p.setsampwidth(af.getsampwidth())
@@ -249,7 +249,7 @@ def test(fn = None):
249249
while 1:
250250
data = af.readframes(BUFSIZ)
251251
if not data: break
252-
print len(data)
252+
print(len(data))
253253
p.writeframes(data)
254254
p.wait()
255255

Lib/base64.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,11 @@ def test():
330330
opts, args = getopt.getopt(sys.argv[1:], 'deut')
331331
except getopt.error as msg:
332332
sys.stdout = sys.stderr
333-
print msg
334-
print """usage: %s [-d|-e|-u|-t] [file|-]
333+
print(msg)
334+
print("""usage: %s [-d|-e|-u|-t] [file|-]
335335
-d, -u: decode
336336
-e: encode (default)
337-
-t: encode and decode string 'Aladdin:open sesame'"""%sys.argv[0]
337+
-t: encode and decode string 'Aladdin:open sesame'"""%sys.argv[0])
338338
sys.exit(2)
339339
func = encode
340340
for o, a in opts:
@@ -352,7 +352,7 @@ def test1():
352352
s0 = "Aladdin:open sesame"
353353
s1 = encodestring(s0)
354354
s2 = decodestring(s1)
355-
print s0, repr(s1), s2
355+
print(s0, repr(s1), s2)
356356

357357

358358
if __name__ == '__main__':

Lib/bdb.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def trace_dispatch(self, frame, event, arg):
5858
return self.trace_dispatch
5959
if event == 'c_return':
6060
return self.trace_dispatch
61-
print 'bdb.Bdb.dispatch: unknown debugging event:', repr(event)
61+
print('bdb.Bdb.dispatch: unknown debugging event:', repr(event))
6262
return self.trace_dispatch
6363

6464
def dispatch_line(self, frame):
@@ -483,17 +483,17 @@ def bpprint(self, out=None):
483483
disp = disp + 'yes '
484484
else:
485485
disp = disp + 'no '
486-
print >>out, '%-4dbreakpoint %s at %s:%d' % (self.number, disp,
487-
self.file, self.line)
486+
print('%-4dbreakpoint %s at %s:%d' % (self.number, disp,
487+
self.file, self.line), file=out)
488488
if self.cond:
489-
print >>out, '\tstop only if %s' % (self.cond,)
489+
print('\tstop only if %s' % (self.cond,), file=out)
490490
if self.ignore:
491-
print >>out, '\tignore next %d hits' % (self.ignore)
491+
print('\tignore next %d hits' % (self.ignore), file=out)
492492
if (self.hits):
493493
if (self.hits > 1): ss = 's'
494494
else: ss = ''
495-
print >>out, ('\tbreakpoint already hit %d time%s' %
496-
(self.hits, ss))
495+
print(('\tbreakpoint already hit %d time%s' %
496+
(self.hits, ss)), file=out)
497497

498498
# -----------end of Breakpoint class----------
499499

< 10000 div aria-hidden="true" class="position-absolute top-0 d-flex user-select-none DiffLineTableCellParts-module__comment-indicator--eI0hb">
@@ -582,27 +582,27 @@ class Tdb(Bdb):
582582
def user_call(self, frame, args):
583583
name = frame.f_code.co_name
584584
if not name: name = '???'
585-
print '+++ call', name, args
585+
print('+++ call', name, args)
586586
def user_line(self, frame):
587587
import linecache
588588
name = frame.f_code.co_name
589589
if not name: name = '???'
590590
fn = self.canonic(frame.f_code.co_filename)
591591
line = linecache.getline(fn, frame.f_lineno)
592-
print '+++', fn, frame.f_lineno, name, ':', line.strip()
592+
print('+++', fn, frame.f_lineno, name, ':', line.strip())
593593
def user_return(self, frame, retval):
594-
print '+++ return', retval
594+
print('+++ return', retval)
595595
def user_exception(self, frame, exc_stuff):
596-
print '+++ exception', exc_stuff
596+
print('+++ exception', exc_stuff)
597597
self.set_continue()
598598

599599
def foo(n):
600-
print 'foo(', n, ')'
600+
print('foo(', n, ')')
601601
x = bar(n*10)
602-
print 'bar returned', x
602+
print('bar returned', x)
603603

604604
def bar(a):
605-
print 'bar(', a, ')'
605+
print('bar(', a, ')')
606606
return a/2
607607

608608
def test():
Lib/bsddb/dbtables.py
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ def sync(self):
208208

209209
def _db_print(self) :
210210
"""Print the database to stdout for debugging"""
211-
print "******** Printing raw database for debugging ********"
211+
print("******** Printing raw database for debugging ********")
212212
cur = self.db.cursor()
213213
try:
214214
key, data = cur.first()
215215
while 1:
216-
print repr({key: data})
216+
print(repr({key: data}))
217217
next = cur.next()
218218
if next:
219219
key, data = next

Lib/bsddb/test/test_all.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222

2323

2424
def print_versions():
25-
print
26-
print '-=' * 38
27-
print db.DB_VERSION_STRING
28-
print 'bsddb.db.version(): %s' % (db.version(), )
29-
print 'bsddb.db.__version__: %s' % db.__version__
30-
print 'bsddb.db.cvsid: %s' % db.cvsid
31-
print 'python version: %s' % sys.version
32-
print 'My pid: %s' % os.getpid()
33-
print '-=' * 38
25+
print()
26+
print('-=' * 38)
27+
print(db.DB_VERSION_STRING)
28+
print('bsddb.db.version(): %s' % (db.version(), ))
29+
print('bsddb.db.__version__: %s' % db.__version__)
30+
print('bsddb.db.cvsid: %s' % db.cvsid)
31+
print('python version: %s' % sys.version)
32+
print('My pid: %s' % os.getpid())
33+
print('-=' * 38)
3434

3535

3636
class PrintInfoFakeTest(unittest.TestCase):

0 commit comments

Comments
 (0)
0