keepalive: use print function
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 21 Jun 2015 23:14:54 -0700
changeset 27616 0765d8423fbc
parent 27615 4030d3b79953
child 27617 b1a59b80e1a3
keepalive: use print function
mercurial/keepalive.py
tests/test-check-py3-compat.t
--- a/mercurial/keepalive.py	Sun Jun 21 21:45:41 2015 -0700
+++ b/mercurial/keepalive.py	Sun Jun 21 23:14:54 2015 -0700
@@ -107,7 +107,7 @@
 
 # $Id: keepalive.py,v 1.14 2006/04/04 21:00:32 mstenner Exp $
 
-from __future__ import absolute_import
+from __future__ import absolute_import, print_function
 
 import errno
 import httplib
@@ -539,13 +539,13 @@
     # NOTE: we DO propagate the error, though, because we cannot simply
     #       ignore the error... the caller will know if they can retry.
     if self.debuglevel > 0:
-        print "send:", repr(str)
+        print("send:", repr(str))
     try:
         blocksize = 8192
         read = getattr(str, 'read', None)
         if read is not None:
             if self.debuglevel > 0:
-                print "sending a read()able"
+                print("sending a read()able")
             data = read(blocksize)
             while data:
                 self.sock.sendall(data)
@@ -597,7 +597,7 @@
     urllib2.install_opener(opener)
     pos = {0: 'off', 1: 'on'}
     for i in (0, 1):
-        print "  fancy error handling %s (HANDLE_ERRORS = %i)" % (pos[i], i)
+        print("  fancy error handling %s (HANDLE_ERRORS = %i)" % (pos[i], i))
         HANDLE_ERRORS = i
         try:
             fo = urllib2.urlopen(url)
@@ -608,13 +608,13 @@
             except AttributeError:
                 status, reason = None, None
         except IOError as e:
-            print "  EXCEPTION: %s" % e
+            print("  EXCEPTION: %s" % e)
             raise
         else:
-            print "  status = %s, reason = %s" % (status, reason)
+            print("  status = %s, reason = %s" % (status, reason))
     HANDLE_ERRORS = orig
     hosts = keepalive_handler.open_connections()
-    print "open connections:", hosts
+    print("open connections:", hosts)
     keepalive_handler.close_all()
 
 def continuity(url):
@@ -629,7 +629,7 @@
     foo = fo.read()
     fo.close()
     m = md5(foo)
-    print format % ('normal urllib', m.hexdigest())
+    print(format % ('normal urllib', m.hexdigest()))
 
     # now install the keepalive handler and try again
     opener = urllib2.build_opener(HTTPHandler())
@@ -639,7 +639,7 @@
     foo = fo.read()
     fo.close()
     m = md5(foo)
-    print format % ('keepalive read', m.hexdigest())
+    print(format % ('keepalive read', m.hexdigest()))
 
     fo = urllib2.urlopen(url)
     foo = ''
@@ -650,25 +650,25 @@
         else: break
     fo.close()
     m = md5(foo)
-    print format % ('keepalive readline', m.hexdigest())
+    print(format % ('keepalive readline', m.hexdigest()))
 
 def comp(N, url):
-    print '  making %i connections to:\n  %s' % (N, url)
+    print('  making %i connections to:\n  %s' % (N, url))
 
     sys.stdout.write('  first using the normal urllib handlers')
     # first use normal opener
     opener = urllib2.build_opener()
     urllib2.install_opener(opener)
     t1 = fetch(N, url)
-    print '  TIME: %.3f s' % t1
+    print('  TIME: %.3f s' % t1)
 
     sys.stdout.write('  now using the keepalive handler       ')
     # now install the keepalive handler and try again
     opener = urllib2.build_opener(HTTPHandler())
     urllib2.install_opener(opener)
     t2 = fetch(N, url)
-    print '  TIME: %.3f s' % t2
-    print '  improvement factor: %.2f' % (t1 / t2)
+    print('  TIME: %.3f s' % t2)
+    print('  improvement factor: %.2f' % (t1 / t2))
 
 def fetch(N, url, delay=0):
     import time
@@ -687,7 +687,7 @@
     for i in lens[1:]:
         j = j + 1
         if not i == lens[0]:
-            print "WARNING: inconsistent length on read %i: %i" % (j, i)
+            print("WARNING: inconsistent length on read %i: %i" % (j, i))
 
     return diff
 
@@ -696,16 +696,16 @@
     dbbackup = DEBUG
     class FakeLogger(object):
         def debug(self, msg, *args):
-            print msg % args
+            print(msg % args)
         info = warning = error = debug
     DEBUG = FakeLogger()
-    print "  fetching the file to establish a connection"
+    print("  fetching the file to establish a connection")
     fo = urllib2.urlopen(url)
     data1 = fo.read()
     fo.close()
 
     i = 20
-    print "  waiting %i seconds for the server to close the connection" % i
+    print("  waiting %i seconds for the server to close the connection" % i)
     while i > 0:
         sys.stdout.write('\r  %2i' % i)
         sys.stdout.flush()
@@ -713,33 +713,33 @@
         i -= 1
     sys.stderr.write('\r')
 
-    print "  fetching the file a second time"
+    print("  fetching the file a second time")
     fo = urllib2.urlopen(url)
     data2 = fo.read()
     fo.close()
 
     if data1 == data2:
-        print '  data are identical'
+        print('  data are identical')
     else:
-        print '  ERROR: DATA DIFFER'
+        print('  ERROR: DATA DIFFER')
 
     DEBUG = dbbackup
 
 
 def test(url, N=10):
-    print "checking error handler (do this on a non-200)"
+    print("checking error handler (do this on a non-200)")
     try: error_handler(url)
     except IOError:
-        print "exiting - exception will prevent further tests"
+        print("exiting - exception will prevent further tests")
         sys.exit()
-    print
-    print "performing continuity test (making sure stuff isn't corrupted)"
+    print('')
+    print("performing continuity test (making sure stuff isn't corrupted)")
     continuity(url)
-    print
-    print "performing speed comparison"
+    print('')
+    print("performing speed comparison")
     comp(N, url)
-    print
-    print "performing dropped-connection check"
+    print('')
+    print("performing dropped-connection check")
     test_timeout(url)
 
 if __name__ == '__main__':
@@ -748,6 +748,6 @@
         N = int(sys.argv[1])
         url = sys.argv[2]
     except (IndexError, ValueError):
-        print "%s <integer> <url>" % sys.argv[0]
+        print("%s <integer> <url>" % sys.argv[0])
     else:
         test(url, N)
--- a/tests/test-check-py3-compat.t	Sun Jun 21 21:45:41 2015 -0700
+++ b/tests/test-check-py3-compat.t	Sun Jun 21 23:14:54 2015 -0700
@@ -100,7 +100,6 @@
   i18n/polib.py not using absolute_import
   mercurial/cmdutil.py not using absolute_import
   mercurial/commands.py not using absolute_import
-  mercurial/keepalive.py requires print_function
   mercurial/lsprof.py requires print_function
   mercurial/lsprofcalltree.py requires print_function
   mercurial/mail.py requires print_function