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