WebKitTools/ChangeLog

 12009-12-03 Yuzo Fujishima <yuzo@google.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Update pywebsocket to 0.4.3
 6 This version logs friendlier and higher-level messages in WARN level, which is used for LayoutTests.
 7 Stack trace is logged now in INFO level.
 8 https://bugs.webkit.org/show_bug.cgi?id=32097
 9
 10 * pywebsocket/mod_pywebsocket/dispatch.py:
 11 * pywebsocket/mod_pywebsocket/msgutil.py:
 12 * pywebsocket/mod_pywebsocket/standalone.py:
 13 * pywebsocket/mod_pywebsocket/util.py:
 14 * pywebsocket/setup.py:
 15 * pywebsocket/test/test_dispatch.py:
 16 * pywebsocket/test/test_util.py:
 17
1182009-12-02 Eric Seidel <eric@webkit.org>
219
320 Reviewed by Adam Barth.

WebKitTools/pywebsocket/mod_pywebsocket/dispatch.py

@@class Dispatcher(object):
160160 do_extra_handshake_, unused_transfer_data = self._handler(request)
161161 try:
162162 do_extra_handshake_(request)
163  except Exception:
164  raise DispatchError('%s raised exception: %s' %
165  (_DO_EXTRA_HANDSHAKE_HANDLER_NAME, util.get_stack_trace()))
 163 except Exception, e:
 164 util.prepend_message_to_exception(
 165 '%s raised exception for %s: ' % (
 166 _DO_EXTRA_HANDSHAKE_HANDLER_NAME,
 167 request.ws_resource),
 168 e)
 169 raise
166170
167171 def transfer_data(self, request):
168172 """Let a handler transfer_data with a Web Socket client.

@@class Dispatcher(object):
177181 unused_do_extra_handshake, transfer_data_ = self._handler(request)
178182 try:
179183 transfer_data_(request)
180  except Exception:
181  raise DispatchError('%s raised exception: %s' %
182  (_TRANSFER_DATA_HANDLER_NAME, util.get_stack_trace()))
 184 except Exception, e:
 185 util.prepend_message_to_exception(
 186 '%s raised exception for %s: ' % (
 187 _TRANSFER_DATA_HANDLER_NAME, request.ws_resource),
 188 e)
 189 raise
183190
184191 def _handler(self, request):
185192 try:

WebKitTools/pywebsocket/mod_pywebsocket/msgutil.py

@@not suitable because they don't allow direct raw bytes writing/reading.
3939
4040import Queue
4141import threading
 42import util
 43
 44
 45class MsgUtilException(Exception):
 46 pass
 47
 48
 49def _read(request, length):
 50 bytes = request.connection.read(length)
 51 if not bytes:
 52 raise MsgUtilException(
 53 'Failed to receive message from %r' %
 54 (request.connection.remote_addr,))
 55 return bytes
 56
 57
 58def _write(request, bytes):
 59 try:
 60 request.connection.write(bytes)
 61 except Exception, e:
 62 util.prepend_message_to_exception(
 63 'Failed to send message to %r: ' %
 64 (request.connection.remote_addr,),
 65 e)
 66 raise
4267
4368
4469def send_message(request, message):

@@def send_message(request, message):
4974 message: unicode string to send.
5075 """
5176
52  request.connection.write('\x00' + message.encode('utf-8') + '\xff')
 77 _write(request, '\x00' + message.encode('utf-8') + '\xff')
5378
5479
5580def receive_message(request):

@@def receive_message(request):
6388 # Read 1 byte.
6489 # mp_conn.read will block if no bytes are available.
6590 # Timeout is controlled by TimeOut directive of Apache.
66  frame_type_str = request.connection.read(1)
 91 frame_type_str = _read(request, 1)
6792 frame_type = ord(frame_type_str[0])
6893 if (frame_type & 0x80) == 0x80:
6994 # The payload length is specified in the frame.

@@def receive_message(request):
84109def _payload_length(request):
85110 length = 0
86111 while True:
87  b_str = request.connection.read(1)
 112 b_str = _read(request, 1)
88113 b = ord(b_str[0])
89114 length = length * 128 + (b & 0x7f)
90115 if (b & 0x80) == 0:

@@def _payload_length(request):
95120def _receive_bytes(request, length):
96121 bytes = []
97122 while length > 0:
98  new_bytes = request.connection.read(length)
 123 new_bytes = _read(request, length)
99124 bytes.append(new_bytes)
100125 length -= len(new_bytes)
101126 return ''.join(bytes)

@@def _receive_bytes(request, length):
104129def _read_until(request, delim_char):
105130 bytes = []
106131 while True:
107  ch = request.connection.read(1)
 132 ch = _read(request, 1)
108133 if ch == delim_char:
109134 break
110135 bytes.append(ch)

WebKitTools/pywebsocket/mod_pywebsocket/standalone.py

@@class _StandaloneConnection(object):
113113 self._request_handler.server.server_port)
114114 local_addr = property(get_local_addr)
115115
 116 def get_remote_addr(self):
 117 """Getter to mimic mp_conn.remote_addr.
 118
 119 Setting the property in __init__ won't work because the request
 120 handler is not initialized yet there."""
 121 return self._request_handler.client_address
 122 remote_addr = property(get_remote_addr)
 123
116124 def write(self, data):
117125 """Mimic mp_conn.write()."""
118126 return self._request_handler.wfile.write(data)

@@class WebSocketRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
227235 except dispatch.DispatchError, e:
228236 logging.warning('mod_pywebsocket: %s' % e)
229237 return False
 238 except Exception, e:
 239 logging.warning('mod_pywebsocket: %s' % e)
 240 logging.info('mod_pywebsocket: %s' % util.get_stack_trace())
 241 return False
230242 return result
231243
232244 def log_request(self, code='-', size='-'):

WebKitTools/pywebsocket/mod_pywebsocket/util.py

@@def get_stack_trace():
4949 return out.getvalue()
5050
5151
 52def prepend_message_to_exception(message, exc):
 53 """Prepend message to the exception."""
 54
 55 exc.args = (message + str(exc),)
 56 return
 57
 58
5259# vi:sts=4 sw=4 et

WebKitTools/pywebsocket/setup.py

@@setup(author='Yuzo Fujishima',
5656 name=_PACKAGE_NAME,
5757 packages=[_PACKAGE_NAME],
5858 url='http://code.google.com/p/pywebsocket/',
59  version='0.4.2.1',
 59 version='0.4.3',
6060 )
6161
6262

WebKitTools/pywebsocket/test/test_dispatch.py

@@class DispatcherTest(unittest.TestCase):
136136 dispatcher.do_extra_handshake(request) # Must not raise exception.
137137
138138 request.ws_origin = 'http://bad.example.com'
139  self.assertRaises(dispatch.DispatchError,
140  dispatcher.do_extra_handshake, request)
 139 self.assertRaises(Exception, dispatcher.do_extra_handshake, request)
141140
142141 def test_transfer_data(self):
143142 dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)

@@class DispatcherTest(unittest.TestCase):
193192 try:
194193 dispatcher.transfer_data(request)
195194 self.fail()
196  except dispatch.DispatchError, e:
 195 except Exception, e:
197196 self.failUnless(str(e).find('Intentional') != -1)
198  except Exception:
199  self.fail()
200197
201198 def test_scan_dir(self):
202199 disp = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)

WebKitTools/pywebsocket/test/test_util.py

@@class UtilTest(unittest.TestCase):
4949 self.failUnless(trace.startswith('Traceback'))
5050 self.failUnless(trace.find('ZeroDivisionError') != -1)
5151
 52 def test_prepend_message_to_exception(self):
 53 exc = Exception('World')
 54 self.assertEqual('World', str(exc))
 55 util.prepend_message_to_exception('Hello ', exc)
 56 self.assertEqual('Hello World', str(exc))
 57
5258
5359if __name__ == '__main__':
5460 unittest.main()