OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2007 Google Inc. | 3 # Copyright 2007 Google Inc. |
4 # | 4 # |
5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
6 # you may not use this file except in compliance with the License. | 6 # you may not use this file except in compliance with the License. |
7 # You may obtain a copy of the License at | 7 # You may obtain a copy of the License at |
8 # | 8 # |
9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
10 # | 10 # |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 url_loc = urlparse.urlparse(url) | 409 url_loc = urlparse.urlparse(url) |
410 self._Authenticate('%s://%s' % (url_loc[0], url_loc[1])) | 410 self._Authenticate('%s://%s' % (url_loc[0], url_loc[1])) |
411 ## elif e.code >= 500 and e.code < 600: | 411 ## elif e.code >= 500 and e.code < 600: |
412 ## # Server Error - try again. | 412 ## # Server Error - try again. |
413 ## continue | 413 ## continue |
414 elif e.code == 301: | 414 elif e.code == 301: |
415 # Handle permanent redirect manually. | 415 # Handle permanent redirect manually. |
416 url = e.info()["location"] | 416 url = e.info()["location"] |
417 else: | 417 else: |
418 raise | 418 raise |
419 except urllib2.URLError, e: | |
420 if hasattr(e, 'reason'): | |
M-A Ruel
2011/01/17 18:17:17
you could rewrite as
reason = getattr(e, 'reason',
Ken Russell (switch to Gerrit)
2011/01/18 21:24:10
Done.
| |
421 reason = e.reason | |
422 if isinstance(reason, str) and reason.find("110") != -1: | |
423 # Connection timeout error. | |
424 if tries <= 3: | |
425 # Try again. | |
426 continue | |
427 raise | |
419 finally: | 428 finally: |
420 socket.setdefaulttimeout(old_timeout) | 429 socket.setdefaulttimeout(old_timeout) |
421 | 430 |
422 | 431 |
423 class HttpRpcServer(AbstractRpcServer): | 432 class HttpRpcServer(AbstractRpcServer): |
424 """Provides a simplified RPC-style interface for HTTP requests.""" | 433 """Provides a simplified RPC-style interface for HTTP requests.""" |
425 | 434 |
426 def _Authenticate(self, *args): | 435 def _Authenticate(self, *args): |
427 """Save the cookie jar after authentication.""" | 436 """Save the cookie jar after authentication.""" |
428 super(HttpRpcServer, self)._Authenticate(*args) | 437 super(HttpRpcServer, self)._Authenticate(*args) |
(...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1777 try: | 1786 try: |
1778 RealMain(sys.argv) | 1787 RealMain(sys.argv) |
1779 except KeyboardInterrupt: | 1788 except KeyboardInterrupt: |
1780 print | 1789 print |
1781 StatusUpdate("Interrupted.") | 1790 StatusUpdate("Interrupted.") |
1782 sys.exit(1) | 1791 sys.exit(1) |
1783 | 1792 |
1784 | 1793 |
1785 if __name__ == "__main__": | 1794 if __name__ == "__main__": |
1786 main() | 1795 main() |
OLD | NEW |