Changeset 50102 in webkit


Ignore:
Timestamp:
Oct 26, 2009 3:10:26 PM (15 years ago)
Author:
eric@webkit.org
Message:

2009-10-26 Yuzo Fujishima <yuzo@google.com>

Reviewed by Eric Seidel.

Upgrade pywebsocket to 0.4.1. This will make reusing LayoutTests/fast/js/resources easier, for example.

https://bugs.webkit.org/show_bug.cgi?id=30763

  • pywebsocket/mod_pywebsocket/init.py:
  • pywebsocket/mod_pywebsocket/dispatch.py:
  • pywebsocket/mod_pywebsocket/headerparserhandler.py:
  • pywebsocket/mod_pywebsocket/standalone.py:
  • pywebsocket/setup.py:
  • pywebsocket/test/test_dispatch.py:
Location:
trunk/WebKitTools
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r50091 r50102  
     12009-10-26  Yuzo Fujishima  <yuzo@google.com>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Upgrade pywebsocket to 0.4.1. This will make reusing LayoutTests/fast/js/resources easier, for example.
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=30763
     8
     9        * pywebsocket/mod_pywebsocket/__init__.py:
     10        * pywebsocket/mod_pywebsocket/dispatch.py:
     11        * pywebsocket/mod_pywebsocket/headerparserhandler.py:
     12        * pywebsocket/mod_pywebsocket/standalone.py:
     13        * pywebsocket/setup.py:
     14        * pywebsocket/test/test_dispatch.py:
     15
    1162009-10-26  Carol Szabo  <carol.szabo@nokia.com>
    217
  • trunk/WebKitTools/pywebsocket/mod_pywebsocket/__init__.py

    r49672 r50102  
    5252       PythonHeaderParserHandler mod_pywebsocket.headerparserhandler
    5353
     54   To limit the search for Web Socket handlers to a directory <scan_dir>
     55   under <websock_handlers>, configure as follows:
     56   
     57       PythonOption mod_pywebsocket.handler_scan <scan_dir>
     58       
     59   <scan_dir> is useful in saving scan time when <websock_handlers>
     60   contains many non-Web Socket handler files.
     61
    5462   Example snippet of httpd.conf:
    5563   (mod_pywebsocket is in /websock_lib, Web Socket handlers are in
  • trunk/WebKitTools/pywebsocket/mod_pywebsocket/dispatch.py

    r49672 r50102  
    120120    """
    121121
    122     def __init__(self, root_dir):
     122    def __init__(self, root_dir, scan_dir=None):
    123123        """Construct an instance.
    124124
    125125        Args:
    126126            root_dir: The directory where handler definition files are
    127             placed.
     127                      placed.
     128            scan_dir: The directory where handler definition files are
     129                      searched. scan_dir must be a directory under root_dir,
     130                      including root_dir itself.  If scan_dir is None, root_dir
     131                      is used as scan_dir. scan_dir can be useful in saving
     132                      scan time when root_dir contains many subdirectories.
    128133        """
    129134
    130135        self._handlers = {}
    131136        self._source_warnings = []
    132         self._source_files_in_dir(root_dir)
     137        if scan_dir is None:
     138            scan_dir = root_dir
     139        if not os.path.abspath(scan_dir).startswith(os.path.abspath(root_dir)):
     140            raise DispatchError('scan_dir:%s must be a directory under '
     141                                'root_dir:%s.' % (scan_dir, root_dir))
     142        self._source_files_in_dir(root_dir, scan_dir)
    133143
    134144    def source_warnings(self):
     
    177187            raise DispatchError('No handler for: %r' % request.ws_resource)
    178188
    179     def _source_files_in_dir(self, root_dir):
    180         """Source all the handler source files in the directory."""
     189    def _source_files_in_dir(self, root_dir, scan_dir):
     190        """Source all the handler source files in the scan_dir directory.
     191       
     192        The resource path is determined relative to root_dir.
     193        """
    181194
    182195        to_resource = _path_to_resource_converter(root_dir)
    183         for path in _source_file_paths(root_dir):
     196        for path in _source_file_paths(scan_dir):
    184197            try:
    185198                handlers = _source(open(path).read())
  • trunk/WebKitTools/pywebsocket/mod_pywebsocket/headerparserhandler.py

    r49672 r50102  
    4646_PYOPT_HANDLER_ROOT = 'mod_pywebsocket.handler_root'
    4747
     48# PythonOption to specify the handler scan directory.
     49# This must be a directory under the root directory.
     50# The default is the root directory.
     51_PYOPT_HANDLER_SCAN = 'mod_pywebsocket.handler_scan'
     52
    4853
    4954def _create_dispatcher():
     
    5358        raise Exception('PythonOption %s is not defined' % _PYOPT_HANDLER_ROOT,
    5459                        apache.APLOG_ERR)
    55     dispatcher = dispatch.Dispatcher(_HANDLER_ROOT)
     60    _HANDLER_SCAN = apache.main_server.get_options().get(
     61            _PYOPT_HANDLER_SCAN, _HANDLER_ROOT)
     62    dispatcher = dispatch.Dispatcher(_HANDLER_ROOT, _HANDLER_SCAN)
    5663    for warning in dispatcher.source_warnings():
    5764        apache.log_error('mod_pywebsocket: %s' % warning, apache.APLOG_WARNING)
  • trunk/WebKitTools/pywebsocket/mod_pywebsocket/standalone.py

    r49672 r50102  
    3737Usage:
    3838    python standalone.py [-p <ws_port>] [-w <websock_handlers>]
     39                         [-s <scan_dir>]
    3940                         [-d <document_root>]
    4041
     
    4647See __init__.py for details of <websock_handlers> and how to write Web Socket
    4748handlers. If this path is relative, <document_root> is used as the base.
     49
     50<scan_dir> is a path under the root directory. If specified, only the handlers
     51under scan_dir are scanned. This is useful in saving scan time.
    4852
    4953Note:
     
    163167                self, WebSocketRequestHandler.options.use_tls)
    164168        self._dispatcher = dispatch.Dispatcher(
    165                 WebSocketRequestHandler.options.websock_handlers)
     169                WebSocketRequestHandler.options.websock_handlers,
     170                WebSocketRequestHandler.options.scan_dir)
    166171        self._print_warnings_if_any()
    167172        self._handshaker = handshake.Handshaker(self._request,
     
    207212                      default='.',
    208213                      help='Web Socket handlers root directory.')
     214    parser.add_option('-s', '--scan_dir', dest='scan_dir',
     215                      default=None,
     216                      help=('Web Socket handlers scan directory. '
     217                            'Must be a directory under websock_handlers.'))
    209218    parser.add_option('-d', '--document_root', dest='document_root',
    210219                      default='.',
     
    227236            sys.exit(1)
    228237
     238    if not options.scan_dir:
     239        options.scan_dir = options.websock_handlers
     240
    229241    WebSocketRequestHandler.options = options
    230242    WebSocketServer.options = options
  • trunk/WebKitTools/pywebsocket/setup.py

    r49672 r50102  
    5757      packages=[_PACKAGE_NAME],
    5858      url='http://code.google.com/p/pywebsocket/',
    59       version='0.4.0',
     59      version='0.4.1',
    6060      )
    6161
  • trunk/WebKitTools/pywebsocket/test/test_dispatch.py

    r49672 r50102  
    4646_TEST_HANDLERS_DIR = os.path.join(
    4747        os.path.split(__file__)[0], 'testdata', 'handlers')
     48
     49_TEST_HANDLERS_SUB_DIR = os.path.join(_TEST_HANDLERS_DIR, 'sub')
    4850
    4951class DispatcherTest(unittest.TestCase):
     
    107109
    108110    def test_source_warnings(self):
    109         dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR)
     111        dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
    110112        warnings = dispatcher.source_warnings()
    111113        warnings.sort()
     
    127129            self.assertEquals(expected, actual)
    128130
    129     def test_shake_hand(self):
    130         dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR)
     131    def test_do_extra_handshake(self):
     132        dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
    131133        request = mock.MockRequest()
    132134        request.ws_resource = '/origin_check'
     
    139141
    140142    def test_transfer_data(self):
    141         dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR)
     143        dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
    142144        request = mock.MockRequest(connection=mock.MockConn(''))
    143145        request.ws_resource = '/origin_check'
     
    156158
    157159    def test_transfer_data_no_handler(self):
    158         dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR)
     160        dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
    159161        for resource in ['/blank', '/sub/non_callable',
    160162                         '/sub/no_wsh_at_the_end', '/does/not/exist']:
     
    171173
    172174    def test_transfer_data_handler_exception(self):
    173         dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR)
     175        dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
    174176        request = mock.MockRequest(connection=mock.MockConn(''))
    175177        request.ws_resource = '/sub/exception_in_transfer'
     
    183185            self.fail()
    184186
     187    def test_scan_dir(self):
     188        disp = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
     189        self.assertEqual(3, len(disp._handlers))
     190        self.failUnless(disp._handlers.has_key('/origin_check'))
     191        self.failUnless(disp._handlers.has_key('/sub/exception_in_transfer'))
     192        self.failUnless(disp._handlers.has_key('/sub/plain'))
     193
     194    def test_scan_sub_dir(self):
     195        disp = dispatch.Dispatcher(_TEST_HANDLERS_DIR, _TEST_HANDLERS_SUB_DIR)
     196        self.assertEqual(2, len(disp._handlers))
     197        self.failIf(disp._handlers.has_key('/origin_check'))
     198        self.failUnless(disp._handlers.has_key('/sub/exception_in_transfer'))
     199        self.failUnless(disp._handlers.has_key('/sub/plain'))
     200
     201    def test_scan_sub_dir_as_root(self):
     202        disp = dispatch.Dispatcher(_TEST_HANDLERS_SUB_DIR,
     203                                   _TEST_HANDLERS_SUB_DIR)
     204        self.assertEqual(2, len(disp._handlers))
     205        self.failIf(disp._handlers.has_key('/origin_check'))
     206        self.failIf(disp._handlers.has_key('/sub/exception_in_transfer'))
     207        self.failIf(disp._handlers.has_key('/sub/plain'))
     208        self.failUnless(disp._handlers.has_key('/exception_in_transfer'))
     209        self.failUnless(disp._handlers.has_key('/plain'))
     210
     211    def test_scan_dir_must_under_root(self):
     212        dispatch.Dispatcher('a/b', 'a/b/c')  # OK
     213        dispatch.Dispatcher('a/b///', 'a/b')  # OK
     214        self.assertRaises(dispatch.DispatchError,
     215                          dispatch.Dispatcher, 'a/b/c', 'a/b')
     216
    185217
    186218if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.