Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: telemetry/third_party/websocket-client/websocket.py

Issue 2236493003: [catapult android trybot] Make Telemetry tests run on Android (Closed) Base URL: git@github.com:catapult-project/catapult.git@master
Patch Set: Add stack traces and more logging Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « telemetry/telemetry/web_perf/timeline_based_page_test_unittest.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """ 1 """
2 websocket - WebSocket client library for Python 2 websocket - WebSocket client library for Python
3 3
4 Copyright (C) 2010 Hiroki Ohtani(liris) 4 Copyright (C) 2010 Hiroki Ohtani(liris)
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public 7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version. 9 version 2.1 of the License, or (at your option) any later version.
10 10
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 if is_secure: 445 if is_secure:
446 if HAVE_SSL: 446 if HAVE_SSL:
447 if self.sslopt is None: 447 if self.sslopt is None:
448 sslopt = {} 448 sslopt = {}
449 else: 449 else:
450 sslopt = self.sslopt 450 sslopt = self.sslopt
451 self.sock = ssl.wrap_socket(self.sock, **sslopt) 451 self.sock = ssl.wrap_socket(self.sock, **sslopt)
452 else: 452 else:
453 raise WebSocketException("SSL not available.") 453 raise WebSocketException("SSL not available.")
454 454
455 print "STARTING HANDSHAKE: %s" % time.time()
456 print " hostname: %s" % hostname
457 print " port: %s" % port
458 print " START TRACEBACK"
459 import traceback; traceback.print_stack()
460 print "END TRACEBACK"
455 self._handshake(hostname, port, resource, **options) 461 self._handshake(hostname, port, resource, **options)
456 462
457 def _handshake(self, host, port, resource, **options): 463 def _handshake(self, host, port, resource, **options):
458 sock = self.sock 464 sock = self.sock
459 headers = [] 465 headers = []
460 headers.append("GET %s HTTP/1.1" % resource) 466 headers.append("GET %s HTTP/1.1" % resource)
461 headers.append("Upgrade: websocket") 467 headers.append("Upgrade: websocket")
462 headers.append("Connection: Upgrade") 468 headers.append("Connection: Upgrade")
463 if port == 80: 469 if port == 80:
464 hostport = host 470 hostport = host
(...skipping 17 matching lines...) Expand all
482 488
483 header_str = "\r\n".join(headers) 489 header_str = "\r\n".join(headers)
484 self._send(header_str) 490 self._send(header_str)
485 if traceEnabled: 491 if traceEnabled:
486 logger.debug("--- request header ---") 492 logger.debug("--- request header ---")
487 logger.debug(header_str) 493 logger.debug(header_str)
488 logger.debug("-----------------------") 494 logger.debug("-----------------------")
489 495
490 status, resp_headers = self._read_headers() 496 status, resp_headers = self._read_headers()
491 if status != 101: 497 if status != 101:
498 print "FAILED HANDSHAKE: %s" % time.time()
492 self.close() 499 self.close()
493 raise WebSocketException("Handshake Status %d" % status) 500 raise WebSocketException("Handshake Status %d" % status)
494 501
495 success = self._validate_header(resp_headers, key) 502 success = self._validate_header(resp_headers, key)
496 if not success: 503 if not success:
497 self.close() 504 self.close()
498 raise WebSocketException("Invalid WebSocket Header") 505 raise WebSocketException("Invalid WebSocket Header")
499 506
507 print "HANDSHAKE SUCCEEDED"
500 self.connected = True 508 self.connected = True
501 509
502 def _validate_header(self, headers, key): 510 def _validate_header(self, headers, key):
503 for k, v in _HEADERS_TO_CHECK.iteritems(): 511 for k, v in _HEADERS_TO_CHECK.iteritems():
504 r = headers.get(k, None) 512 r = headers.get(k, None)
505 if not r: 513 if not r:
506 return False 514 return False
507 r = r.lower() 515 r = r.lower()
508 if v != r: 516 if v != r:
509 return False 517 return False
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 if __name__ == "__main__": 892 if __name__ == "__main__":
885 enableTrace(True) 893 enableTrace(True)
886 ws = create_connection("ws://echo.websocket.org/") 894 ws = create_connection("ws://echo.websocket.org/")
887 print("Sending 'Hello, World'...") 895 print("Sending 'Hello, World'...")
888 ws.send("Hello, World") 896 ws.send("Hello, World")
889 print("Sent") 897 print("Sent")
890 print("Receiving...") 898 print("Receiving...")
891 result = ws.recv() 899 result = ws.recv()
892 print("Received '%s'" % result) 900 print("Received '%s'" % result)
893 ws.close() 901 ws.close()
OLDNEW
« no previous file with comments | « telemetry/telemetry/web_perf/timeline_based_page_test_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698