From 5e177bc6f3a903fe060b5145f7f23bc9634bedc9 Mon Sep 17 00:00:00 2001 From: lixiang Date: Thu, 30 Nov 2023 17:12:07 +0800 Subject: [PATCH] chromium 114 source init Change-Id: Iddf2b16c8acb95bb2bf3755ea60ace47e23c6ca9 Signed-off-by: lixiang --- .travis.yml | 17 + CONTRIBUTING | 30 + LICENSE | 28 + MANIFEST.in | 6 + README.md | 36 + example/abort_handshake_wsh.py | 43 + example/abort_wsh.py | 43 + example/arraybuffer_benchmark.html | 134 +++ example/bench_wsh.py | 59 ++ example/benchmark.html | 175 ++++ example/benchmark.js | 238 +++++ example/benchmark_helper_wsh.py | 84 ++ example/cgi-bin/hi.py | 5 + example/close_wsh.py | 70 ++ example/console.html | 317 ++++++ example/cookie_wsh.py | 54 + example/echo_client.py | 699 +++++++++++++ example/echo_noext_wsh.py | 62 ++ example/echo_wsh.py | 55 + example/handler_map.txt | 11 + example/hsts_wsh.py | 40 + example/internal_error_wsh.py | 42 + example/origin_check_wsh.py | 44 + example/performance_test_iframe.html | 37 + example/performance_test_iframe.js | 86 ++ example/special_headers.cgi | 26 + example/util.js | 323 ++++++ example/util_main.js | 89 ++ example/util_worker.js | 44 + mod_pywebsocket/__init__.py | 172 ++++ mod_pywebsocket/_stream_exceptions.py | 82 ++ mod_pywebsocket/common.py | 273 +++++ mod_pywebsocket/dispatch.py | 389 +++++++ mod_pywebsocket/extensions.py | 474 +++++++++ mod_pywebsocket/fast_masking.i | 98 ++ mod_pywebsocket/handshake/__init__.py | 101 ++ mod_pywebsocket/handshake/base.py | 396 ++++++++ mod_pywebsocket/handshake/hybi.py | 223 ++++ mod_pywebsocket/http_header_util.py | 254 +++++ mod_pywebsocket/memorizingfile.py | 99 ++ mod_pywebsocket/msgutil.py | 214 ++++ mod_pywebsocket/request_handler.py | 319 ++++++ mod_pywebsocket/server_util.py | 87 ++ mod_pywebsocket/standalone.py | 491 +++++++++ mod_pywebsocket/stream.py | 950 ++++++++++++++++++ mod_pywebsocket/util.py | 386 +++++++ mod_pywebsocket/websocket_server.py | 289 ++++++ setup.py | 73 ++ test/__init__.py | 0 test/cert/cacert.pem | 17 + test/cert/cert.pem | 61 ++ test/cert/client_cert.p12 | Bin 0 -> 2582 bytes test/cert/key.pem | 15 + test/client_for_testing.py | 726 +++++++++++++ test/mock.py | 227 +++++ test/run_all.py | 88 ++ test/set_sys_path.py | 41 + test/test_dispatch.py | 298 ++++++ test/test_endtoend.py | 738 ++++++++++++++ test/test_extensions.py | 192 ++++ test/test_handshake.py | 172 ++++ test/test_handshake_hybi.py | 422 ++++++++ test/test_http_header_util.py | 93 ++ test/test_memorizingfile.py | 100 ++ test/test_mock.py | 137 +++ test/test_msgutil.py | 912 +++++++++++++++++ test/test_stream.py | 70 ++ test/test_util.py | 191 ++++ test/testdata/README | 1 + test/testdata/handlers/abort_by_user_wsh.py | 41 + test/testdata/handlers/blank_wsh.py | 30 + test/testdata/handlers/origin_check_wsh.py | 43 + .../handlers/sub/exception_in_transfer_wsh.py | 42 + .../handlers/sub/no_wsh_at_the_end.py | 43 + .../testdata/handlers/sub/non_callable_wsh.py | 35 + test/testdata/handlers/sub/plain_wsh.py | 41 + .../handlers/sub/wrong_handshake_sig_wsh.py | 43 + .../handlers/sub/wrong_transfer_sig_wsh.py | 43 + test/testdata/hello.pl | 32 + 79 files changed, 13161 insertions(+) create mode 100644 .travis.yml create mode 100644 CONTRIBUTING create mode 100644 LICENSE create mode 100644 MANIFEST.in create mode 100644 README.md create mode 100644 example/abort_handshake_wsh.py create mode 100644 example/abort_wsh.py create mode 100644 example/arraybuffer_benchmark.html create mode 100644 example/bench_wsh.py create mode 100644 example/benchmark.html create mode 100644 example/benchmark.js create mode 100644 example/benchmark_helper_wsh.py create mode 100755 example/cgi-bin/hi.py create mode 100644 example/close_wsh.py create mode 100644 example/console.html create mode 100644 example/cookie_wsh.py create mode 100755 example/echo_client.py create mode 100644 example/echo_noext_wsh.py create mode 100644 example/echo_wsh.py create mode 100644 example/handler_map.txt create mode 100644 example/hsts_wsh.py create mode 100644 example/internal_error_wsh.py create mode 100644 example/origin_check_wsh.py create mode 100644 example/performance_test_iframe.html create mode 100644 example/performance_test_iframe.js create mode 100755 example/special_headers.cgi create mode 100644 example/util.js create mode 100644 example/util_main.js create mode 100644 example/util_worker.js create mode 100644 mod_pywebsocket/__init__.py create mode 100644 mod_pywebsocket/_stream_exceptions.py create mode 100644 mod_pywebsocket/common.py create mode 100644 mod_pywebsocket/dispatch.py create mode 100644 mod_pywebsocket/extensions.py create mode 100644 mod_pywebsocket/fast_masking.i create mode 100644 mod_pywebsocket/handshake/__init__.py create mode 100644 mod_pywebsocket/handshake/base.py create mode 100644 mod_pywebsocket/handshake/hybi.py create mode 100644 mod_pywebsocket/http_header_util.py create mode 100644 mod_pywebsocket/memorizingfile.py create mode 100644 mod_pywebsocket/msgutil.py create mode 100644 mod_pywebsocket/request_handler.py create mode 100644 mod_pywebsocket/server_util.py create mode 100755 mod_pywebsocket/standalone.py create mode 100644 mod_pywebsocket/stream.py create mode 100644 mod_pywebsocket/util.py create mode 100644 mod_pywebsocket/websocket_server.py create mode 100755 setup.py create mode 100644 test/__init__.py create mode 100644 test/cert/cacert.pem create mode 100644 test/cert/cert.pem create mode 100644 test/cert/client_cert.p12 create mode 100644 test/cert/key.pem create mode 100644 test/client_for_testing.py create mode 100644 test/mock.py create mode 100755 test/run_all.py create mode 100644 test/set_sys_path.py create mode 100755 test/test_dispatch.py create mode 100755 test/test_endtoend.py create mode 100755 test/test_extensions.py create mode 100755 test/test_handshake.py create mode 100755 test/test_handshake_hybi.py create mode 100755 test/test_http_header_util.py create mode 100755 test/test_memorizingfile.py create mode 100755 test/test_mock.py create mode 100755 test/test_msgutil.py create mode 100755 test/test_stream.py create mode 100755 test/test_util.py create mode 100644 test/testdata/README create mode 100644 test/testdata/handlers/abort_by_user_wsh.py create mode 100644 test/testdata/handlers/blank_wsh.py create mode 100644 test/testdata/handlers/origin_check_wsh.py create mode 100644 test/testdata/handlers/sub/exception_in_transfer_wsh.py create mode 100644 test/testdata/handlers/sub/no_wsh_at_the_end.py create mode 100644 test/testdata/handlers/sub/non_callable_wsh.py create mode 100644 test/testdata/handlers/sub/plain_wsh.py create mode 100644 test/testdata/handlers/sub/wrong_handshake_sig_wsh.py create mode 100644 test/testdata/handlers/sub/wrong_transfer_sig_wsh.py create mode 100644 test/testdata/hello.pl diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2065a64 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,17 @@ +language: python +python: + - 2.7 + - 3.5 + - 3.6 + - 3.7 + - 3.8 + - nightly + +matrix: + allow_failures: + - python: 3.5, nightly +install: + - pip install six yapf +script: + - python test/run_all.py + - yapf --diff --recursive . diff --git a/CONTRIBUTING b/CONTRIBUTING new file mode 100644 index 0000000..f975be1 --- /dev/null +++ b/CONTRIBUTING @@ -0,0 +1,30 @@ +# How to Contribute + +We'd love to accept your patches and contributions to this project. There are +just a few small guidelines you need to follow. + +## Contributor License Agreement + +Contributions to this project must be accompanied by a Contributor License +Agreement. You (or your employer) retain the copyright to your contribution; +this simply gives us permission to use and redistribute your contributions as +part of the project. Head over to to see +your current agreements on file or to sign a new one. + +You generally only need to submit a CLA once, so if you've already submitted one +(even if it was for a different project), you probably don't need to do it +again. + +## Code reviews + +All submissions, including submissions by project members, require review. We +use GitHub pull requests for this purpose. Consult +[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more +information on using pull requests. +For instructions for contributing code, please read: +https://github.com/google/pywebsocket/wiki/CodeReviewInstruction + +## Community Guidelines + +This project follows +[Google's Open Source Community Guidelines](https://opensource.google/conduct/). diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c91bea9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,28 @@ +Copyright 2020, Google Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..1925688 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,6 @@ +include COPYING +include MANIFEST.in +include README +recursive-include example *.py +recursive-include mod_pywebsocket *.py +recursive-include test *.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..8684f2c --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ + +# pywebsocket3 # + +The pywebsocket project aims to provide a [WebSocket](https://tools.ietf.org/html/rfc6455) standalone server. + +pywebsocket is intended for **testing** or **experimental** purposes. + +Run this to read the general document: +``` +$ pydoc mod_pywebsocket +``` + +Please see [Wiki](https://github.com/GoogleChromeLabs/pywebsocket3/wiki) for more details. + +# INSTALL # + +To install this package to the system, run this: +``` +$ python setup.py build +$ sudo python setup.py install +``` + +To install this package as a normal user, run this instead: + +``` +$ python setup.py build +$ python setup.py install --user +``` +# LAUNCH # + +To use pywebsocket as standalone server, run this to read the document: +``` +$ pydoc mod_pywebsocket.standalone +``` +# Disclaimer # +This is not an officially supported Google product diff --git a/example/abort_handshake_wsh.py b/example/abort_handshake_wsh.py new file mode 100644 index 0000000..1b719ca --- /dev/null +++ b/example/abort_handshake_wsh.py @@ -0,0 +1,43 @@ +# Copyright 2012, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from __future__ import absolute_import +from mod_pywebsocket import handshake + + +def web_socket_do_extra_handshake(request): + raise handshake.AbortedByUserException( + "Aborted in web_socket_do_extra_handshake") + + +def web_socket_transfer_data(request): + pass + + +# vi:sts=4 sw=4 et diff --git a/example/abort_wsh.py b/example/abort_wsh.py new file mode 100644 index 0000000..d4c240b --- /dev/null +++ b/example/abort_wsh.py @@ -0,0 +1,43 @@ +# Copyright 2012, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from __future__ import absolute_import +from mod_pywebsocket import handshake + + +def web_socket_do_extra_handshake(request): + pass + + +def web_socket_transfer_data(request): + raise handshake.AbortedByUserException( + "Aborted in web_socket_transfer_data") + + +# vi:sts=4 sw=4 et diff --git a/example/arraybuffer_benchmark.html b/example/arraybuffer_benchmark.html new file mode 100644 index 0000000..869cd7e --- /dev/null +++ b/example/arraybuffer_benchmark.html @@ -0,0 +1,134 @@ + + + + +ArrayBuffer benchmark + + + + + + + diff --git a/example/bench_wsh.py b/example/bench_wsh.py new file mode 100644 index 0000000..2df50e7 --- /dev/null +++ b/example/bench_wsh.py @@ -0,0 +1,59 @@ +# Copyright 2011, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +"""A simple load tester for WebSocket clients. + +A client program sends a message formatted as "