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

Side by Side Diff: chrome/test/pyautolib/remote_host.py

Issue 7841010: PyAuto remote_host Mac fixes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial commit. Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import cStringIO 6 import cStringIO
7 import os 7 import os
8 import pickle 8 import pickle
9 import socket 9 import socket
10 import sys 10 import sys
(...skipping 16 matching lines...) Expand all
27 listening_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 27 listening_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
28 listening_socket.bind(('', port)) 28 listening_socket.bind(('', port))
29 listening_socket.listen(1) 29 listening_socket.listen(1)
30 self._socket, _ = listening_socket.accept() 30 self._socket, _ = listening_socket.accept()
31 31
32 while self.Connected(): 32 while self.Connected():
33 self._HandleRPC() 33 self._HandleRPC()
34 34
35 def StopSocketServer(self): 35 def StopSocketServer(self):
36 if self._socket: 36 if self._socket:
37 self._socket.shutdown(socket.SHUT_RDWR) 37 try:
38 self._socket.close() 38 self._socket.shutdown(socket.SHUT_RDWR)
39 self._socket.close()
40 except socket.error:
41 pass
39 self._socket = None 42 self._socket = None
40 43
41 def Connected(self): 44 def Connected(self):
42 return self._socket 45 return self._socket
43 46
44 def CreateTarget(self, target_class): 47 def CreateTarget(self, target_class):
45 """Creates an instance of the specified class to serve as the RPC target. 48 """Creates an instance of the specified class to serve as the RPC target.
46 49
47 RPC calls can be made on the target. 50 RPC calls can be made on the target.
48 """ 51 """
(...skipping 20 matching lines...) Expand all
69 sys.stderr = stderr = cStringIO.StringIO() 72 sys.stderr = stderr = cStringIO.StringIO()
70 73
71 # Make requested method call. 74 # Make requested method call.
72 result = None 75 result = None
73 exception = None 76 exception = None
74 try: 77 try:
75 if getattr(self, request[0], None): 78 if getattr(self, request[0], None):
76 result = getattr(self, request[0])(*request[1], **request[2]) 79 result = getattr(self, request[0])(*request[1], **request[2])
77 else: 80 else:
78 result = getattr(self.target, request[0])(*request[1], **request[2]) 81 result = getattr(self.target, request[0])(*request[1], **request[2])
79 except BaseException as e: 82 except BaseException, e:
80 exception = (e.__class__.__name__, str(e)) 83 exception = (e.__class__.__name__, str(e))
81 84
82 # Put output back to the way it was before. 85 # Put output back to the way it was before.
83 sys.stdout = old_stdout 86 sys.stdout = old_stdout
84 sys.stderr = old_stderr 87 sys.stderr = old_stderr
85 88
86 # Package up and send the result of the method call. 89 # Package up and send the result of the method call.
87 response = pickle.dumps((result, stdout.getvalue(), stderr.getvalue(), 90 response = pickle.dumps((result, stdout.getvalue(), stderr.getvalue(),
88 exception)) 91 exception))
89 if self._socket.send(response) != len(response): 92 if self._socket.send(response) != len(response):
90 self.StopSocketServer() 93 self.StopSocketServer()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698