Show More
@@ -107,7 +107,7 b' EXTRA ATTRIBUTES AND METHODS' | |||
|
107 | 107 | |
|
108 | 108 | # $Id: keepalive.py,v 1.14 2006/04/04 21:00:32 mstenner Exp $ |
|
109 | 109 | |
|
110 | from __future__ import absolute_import | |
|
110 | from __future__ import absolute_import, print_function | |
|
111 | 111 | |
|
112 | 112 | import errno |
|
113 | 113 | import httplib |
@@ -539,13 +539,13 b' def safesend(self, str):' | |||
|
539 | 539 | # NOTE: we DO propagate the error, though, because we cannot simply |
|
540 | 540 | # ignore the error... the caller will know if they can retry. |
|
541 | 541 | if self.debuglevel > 0: |
|
542 |
print |
|
|
542 | print("send:", repr(str)) | |
|
543 | 543 | try: |
|
544 | 544 | blocksize = 8192 |
|
545 | 545 | read = getattr(str, 'read', None) |
|
546 | 546 | if read is not None: |
|
547 | 547 | if self.debuglevel > 0: |
|
548 |
print |
|
|
548 | print("sending a read()able") | |
|
549 | 549 | data = read(blocksize) |
|
550 | 550 | while data: |
|
551 | 551 | self.sock.sendall(data) |
@@ -597,7 +597,7 b' def error_handler(url):' | |||
|
597 | 597 | urllib2.install_opener(opener) |
|
598 | 598 | pos = {0: 'off', 1: 'on'} |
|
599 | 599 | for i in (0, 1): |
|
600 |
print |
|
|
600 | print(" fancy error handling %s (HANDLE_ERRORS = %i)" % (pos[i], i)) | |
|
601 | 601 | HANDLE_ERRORS = i |
|
602 | 602 | try: |
|
603 | 603 | fo = urllib2.urlopen(url) |
@@ -608,13 +608,13 b' def error_handler(url):' | |||
|
608 | 608 | except AttributeError: |
|
609 | 609 | status, reason = None, None |
|
610 | 610 | except IOError as e: |
|
611 |
print |
|
|
611 | print(" EXCEPTION: %s" % e) | |
|
612 | 612 | raise |
|
613 | 613 | else: |
|
614 |
print |
|
|
614 | print(" status = %s, reason = %s" % (status, reason)) | |
|
615 | 615 | HANDLE_ERRORS = orig |
|
616 | 616 | hosts = keepalive_handler.open_connections() |
|
617 |
print |
|
|
617 | print("open connections:", hosts) | |
|
618 | 618 | keepalive_handler.close_all() |
|
619 | 619 | |
|
620 | 620 | def continuity(url): |
@@ -629,7 +629,7 b' def continuity(url):' | |||
|
629 | 629 | foo = fo.read() |
|
630 | 630 | fo.close() |
|
631 | 631 | m = md5(foo) |
|
632 |
print |
|
|
632 | print(format % ('normal urllib', m.hexdigest())) | |
|
633 | 633 | |
|
634 | 634 | # now install the keepalive handler and try again |
|
635 | 635 | opener = urllib2.build_opener(HTTPHandler()) |
@@ -639,7 +639,7 b' def continuity(url):' | |||
|
639 | 639 | foo = fo.read() |
|
640 | 640 | fo.close() |
|
641 | 641 | m = md5(foo) |
|
642 |
print |
|
|
642 | print(format % ('keepalive read', m.hexdigest())) | |
|
643 | 643 | |
|
644 | 644 | fo = urllib2.urlopen(url) |
|
645 | 645 | foo = '' |
@@ -650,25 +650,25 b' def continuity(url):' | |||
|
650 | 650 | else: break |
|
651 | 651 | fo.close() |
|
652 | 652 | m = md5(foo) |
|
653 |
print |
|
|
653 | print(format % ('keepalive readline', m.hexdigest())) | |
|
654 | 654 | |
|
655 | 655 | def comp(N, url): |
|
656 |
print |
|
|
656 | print(' making %i connections to:\n %s' % (N, url)) | |
|
657 | 657 | |
|
658 | 658 | sys.stdout.write(' first using the normal urllib handlers') |
|
659 | 659 | # first use normal opener |
|
660 | 660 | opener = urllib2.build_opener() |
|
661 | 661 | urllib2.install_opener(opener) |
|
662 | 662 | t1 = fetch(N, url) |
|
663 |
print |
|
|
663 | print(' TIME: %.3f s' % t1) | |
|
664 | 664 | |
|
665 | 665 | sys.stdout.write(' now using the keepalive handler ') |
|
666 | 666 | # now install the keepalive handler and try again |
|
667 | 667 | opener = urllib2.build_opener(HTTPHandler()) |
|
668 | 668 | urllib2.install_opener(opener) |
|
669 | 669 | t2 = fetch(N, url) |
|
670 |
print |
|
|
671 |
print |
|
|
670 | print(' TIME: %.3f s' % t2) | |
|
671 | print(' improvement factor: %.2f' % (t1 / t2)) | |
|
672 | 672 | |
|
673 | 673 | def fetch(N, url, delay=0): |
|
674 | 674 | import time |
@@ -687,7 +687,7 b' def fetch(N, url, delay=0):' | |||
|
687 | 687 | for i in lens[1:]: |
|
688 | 688 | j = j + 1 |
|
689 | 689 | if not i == lens[0]: |
|
690 |
print |
|
|
690 | print("WARNING: inconsistent length on read %i: %i" % (j, i)) | |
|
691 | 691 | |
|
692 | 692 | return diff |
|
693 | 693 | |
@@ -696,16 +696,16 b' def test_timeout(url):' | |||
|
696 | 696 | dbbackup = DEBUG |
|
697 | 697 | class FakeLogger(object): |
|
698 | 698 | def debug(self, msg, *args): |
|
699 |
print |
|
|
699 | print(msg % args) | |
|
700 | 700 | info = warning = error = debug |
|
701 | 701 | DEBUG = FakeLogger() |
|
702 |
print |
|
|
702 | print(" fetching the file to establish a connection") | |
|
703 | 703 | fo = urllib2.urlopen(url) |
|
704 | 704 | data1 = fo.read() |
|
705 | 705 | fo.close() |
|
706 | 706 | |
|
707 | 707 | i = 20 |
|
708 |
print |
|
|
708 | print(" waiting %i seconds for the server to close the connection" % i) | |
|
709 | 709 | while i > 0: |
|
710 | 710 | sys.stdout.write('\r %2i' % i) |
|
711 | 711 | sys.stdout.flush() |
@@ -713,33 +713,33 b' def test_timeout(url):' | |||
|
713 | 713 | i -= 1 |
|
714 | 714 | sys.stderr.write('\r') |
|
715 | 715 | |
|
716 |
print |
|
|
716 | print(" fetching the file a second time") | |
|
717 | 717 | fo = urllib2.urlopen(url) |
|
718 | 718 | data2 = fo.read() |
|
719 | 719 | fo.close() |
|
720 | 720 | |
|
721 | 721 | if data1 == data2: |
|
722 |
print |
|
|
722 | print(' data are identical') | |
|
723 | 723 | else: |
|
724 |
print |
|
|
724 | print(' ERROR: DATA DIFFER') | |
|
725 | 725 | |
|
726 | 726 | DEBUG = dbbackup |
|
727 | 727 | |
|
728 | 728 | |
|
729 | 729 | def test(url, N=10): |
|
730 |
print |
|
|
730 | print("checking error handler (do this on a non-200)") | |
|
731 | 731 | try: error_handler(url) |
|
732 | 732 | except IOError: |
|
733 |
print |
|
|
733 | print("exiting - exception will prevent further tests") | |
|
734 | 734 | sys.exit() |
|
735 | ||
|
736 |
print |
|
|
735 | print('') | |
|
736 | print("performing continuity test (making sure stuff isn't corrupted)") | |
|
737 | 737 | continuity(url) |
|
738 | ||
|
739 |
print |
|
|
738 | print('') | |
|
739 | print("performing speed comparison") | |
|
740 | 740 | comp(N, url) |
|
741 | ||
|
742 |
print |
|
|
741 | print('') | |
|
742 | print("performing dropped-connection check") | |
|
743 | 743 | test_timeout(url) |
|
744 | 744 | |
|
745 | 745 | if __name__ == '__main__': |
@@ -748,6 +748,6 b" if __name__ == '__main__':" | |||
|
748 | 748 | N = int(sys.argv[1]) |
|
749 | 749 | url = sys.argv[2] |
|
750 | 750 | except (IndexError, ValueError): |
|
751 |
print |
|
|
751 | print("%s <integer> <url>" % sys.argv[0]) | |
|
752 | 752 | else: |
|
753 | 753 | test(url, N) |
@@ -100,7 +100,6 b'' | |||
|
100 | 100 | i18n/polib.py not using absolute_import |
|
101 | 101 | mercurial/cmdutil.py not using absolute_import |
|
102 | 102 | mercurial/commands.py not using absolute_import |
|
103 | mercurial/keepalive.py requires print_function | |
|
104 | 103 | mercurial/lsprof.py requires print_function |
|
105 | 104 | mercurial/lsprofcalltree.py requires print_function |
|
106 | 105 | mercurial/mail.py requires print_function |
General Comments 0
You need to be logged in to leave comments.
Login now