Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install six yapf setuptools
python3 -m pip install yapf setuptools

# Build and create dist
- name: Build Package
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.10", "3.11"]
exclude:
- os: macos-latest
python-version: "3.7"
python-version: ["3.9", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -26,7 +23,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install six yapf
python -m pip install yapf
- name: Run test
run: |
python test/run_all.py
2 changes: 0 additions & 2 deletions example/bench_wsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

import time

from six.moves import range


def web_socket_do_extra_handshake(request):
pass # Always accept.
Expand Down
4 changes: 1 addition & 3 deletions example/benchmark_helper_wsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

from __future__ import absolute_import

import six


def web_socket_do_extra_handshake(request):
# Turn off compression.
Expand All @@ -46,7 +44,7 @@ def web_socket_transfer_data(request):
if command is None:
return

if not isinstance(command, six.text_type):
if not isinstance(command, str):
raise ValueError('Invalid command data:' + command)
commands = command.split(' ')
if len(commands) == 0:
Expand Down
5 changes: 2 additions & 3 deletions example/cookie_wsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from __future__ import absolute_import

from six.moves import urllib
from urllib.parse import urlparse


def _add_set_cookie(request, value):
request.extra_headers.append(('Set-Cookie', value))


def web_socket_do_extra_handshake(request):
components = urllib.parse.urlparse(request.uri)
components = urlparse(request.uri)
command = components[4]

ONE_DAY_LIFE = 'Max-Age=86400'
Expand Down
21 changes: 5 additions & 16 deletions example/echo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,13 @@

import argparse
import base64
import codecs
import logging
import os
import re
import socket
import ssl
import sys
from hashlib import sha1

import six

from pywebsocket3 import common, util
from pywebsocket3.extensions import (
Expand Down Expand Up @@ -599,14 +596,6 @@ def _do_closing_handshake(self):


def main():
# Force Python 2 to use the locale encoding, even when the output is not a
# tty. This makes the behaviour the same as Python 3. The encoding won't
# necessarily support all unicode characters. This problem is particularly
# prevalent on Windows.
if six.PY2:
import locale
encoding = locale.getpreferredencoding()
sys.stdout = codecs.getwriter(encoding)(sys.stdout)

parser = argparse.ArgumentParser()
# We accept --command_line_flag style flags which is the same as Google
Expand All @@ -615,7 +604,7 @@ def main():
'--server-host',
'--server_host',
dest='server_host',
type=six.text_type,
type=str,
default='localhost',
help='server host')
parser.add_argument('-p',
Expand All @@ -628,20 +617,20 @@ def main():
parser.add_argument('-o',
'--origin',
dest='origin',
type=six.text_type,
type=str,
default=None,
help='origin')
parser.add_argument('-r',
'--resource',
dest='resource',
type=six.text_type,
type=str,
default='/echo',
help='resource path')
parser.add_argument(
'-m',
'--message',
dest='message',
type=six.text_type,
type=str,
default=u'Hello,<>',
help=('comma-separated messages to send. '
'%s will force close the connection from server.' %
Expand Down Expand Up @@ -673,7 +662,7 @@ def main():
help='Use the permessage-deflate extension.')
parser.add_argument('--log-level',
'--log_level',
type=six.text_type,
type=str,
dest='log_level',
default='warn',
choices=['debug', 'info', 'warn', 'error', 'critical'],
Expand Down
4 changes: 1 addition & 3 deletions example/echo_noext_wsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import six

_GOODBYE_MESSAGE = u'Goodbye'


Expand All @@ -51,7 +49,7 @@ def web_socket_transfer_data(request):
line = request.ws_stream.receive_message()
if line is None:
return
if isinstance(line, six.text_type):
if isinstance(line, str):
request.ws_stream.send_message(line, binary=False)
if line == _GOODBYE_MESSAGE:
return
Expand Down
4 changes: 1 addition & 3 deletions example/echo_wsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import six

_GOODBYE_MESSAGE = u'Goodbye'


Expand All @@ -44,7 +42,7 @@ def web_socket_transfer_data(request):
line = request.ws_stream.receive_message()
if line is None:
return
if isinstance(line, six.text_type):
if isinstance(line, str):
request.ws_stream.send_message(line, binary=False)
if line == _GOODBYE_MESSAGE:
return
Expand Down
2 changes: 0 additions & 2 deletions pywebsocket3/handshake/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
from pywebsocket3.extensions import get_extension_processor
from pywebsocket3.stream import Stream, StreamOptions

from six.moves import map, range


# Defining aliases for values used frequently.
_VERSION_LATEST = common.VERSION_HYBI_LATEST
Expand Down
5 changes: 2 additions & 3 deletions pywebsocket3/http_header_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
"""

from __future__ import absolute_import

import six.moves.urllib.parse
from urllib.parse import urlsplit


_SEPARATORS = '()<>@,;:\\"/[]?={} \t'
Expand Down Expand Up @@ -216,7 +215,7 @@ def quote_if_necessary(s):
def parse_uri(uri):
"""Parse absolute URI then return host, port and resource."""

parsed = six.moves.urllib.parse.urlsplit(uri)
parsed = urlsplit(uri)
if parsed.scheme != 'wss' and parsed.scheme != 'ws':
# |uri| must be a relative URI.
# TODO(toyoshim): Should validate |uri|.
Expand Down
8 changes: 4 additions & 4 deletions pywebsocket3/msgutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

import threading

import six.moves.queue
import queue

# Export Exception symbols from msgutil for backward compatibility
from pywebsocket3._stream_exceptions import (
Expand Down Expand Up @@ -124,7 +124,7 @@ def __init__(self, request, onmessage=None):

threading.Thread.__init__(self)
self._request = request
self._queue = six.moves.queue.Queue()
self._queue = queue.Queue()
self._onmessage = onmessage
self._stop_requested = False
self.setDaemon(True)
Expand Down Expand Up @@ -157,7 +157,7 @@ def receive_nowait(self):
"""
try:
message = self._queue.get_nowait()
except six.moves.queue.Empty:
except queue.Empty:
message = None
return message

Expand Down Expand Up @@ -189,7 +189,7 @@ def __init__(self, request):
"""
threading.Thread.__init__(self)
self._request = request
self._queue = six.moves.queue.Queue()
self._queue = queue.Queue()
self.setDaemon(True)
self.start()

Expand Down
6 changes: 3 additions & 3 deletions pywebsocket3/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"""Request Handler and Request/Connection classes for standalone server.
"""

import http
import os

from six.moves import CGIHTTPServer
from six.moves import http_client
from http.server import CGIHTTPServer

from pywebsocket3 import (
common,
Expand Down Expand Up @@ -152,7 +152,7 @@ class WebSocketRequestHandler(CGIHTTPServer.CGIHTTPRequestHandler):
"""CGIHTTPRequestHandler specialized for WebSocket."""

# Use httplib.HTTPMessage instead of mimetools.Message.
MessageClass = http_client.HTTPMessage
MessageClass = http.client.HTTPMessage

def setup(self):
"""Override SocketServer.StreamRequestHandler.setup to wrap rfile
Expand Down
11 changes: 5 additions & 6 deletions pywebsocket3/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@
import sys
import traceback

import six
from six.moves import configparser
import configparser

from pywebsocket3 import common, server_util, util
from pywebsocket3.websocket_server import WebSocketServer
Expand All @@ -181,7 +180,7 @@ def _build_option_parser():
parser.add_argument(
'--config',
dest='config_file',
type=six.text_type,
type=str,
default=None,
help=('Path to configuration file. See the file comment '
'at the top of this file for the configuration '
Expand Down Expand Up @@ -318,7 +317,7 @@ def _build_option_parser():
# - FINE: Prints status of each frame processing step
parser.add_argument('--log-level',
'--log_level',
type=six.text_type,
type=str,
dest='log_level',
default='warn',
choices=[
Expand All @@ -329,7 +328,7 @@ def _build_option_parser():
parser.add_argument(
'--deflate-log-level',
'--deflate_log_level',
type=six.text_type,
type=str,
dest='deflate_log_level',
default='warn',
choices=['debug', 'info', 'warning', 'warn', 'error', 'critical'],
Expand Down Expand Up @@ -366,7 +365,7 @@ def _build_option_parser():
'--handler-encoding',
'--handler_encoding',
dest='handler_encoding',
type=six.text_type,
type=str,
default=None,
help=('Text encoding used for loading handlers. '
'By default, the encoding from the locale is used when '
Expand Down
7 changes: 3 additions & 4 deletions pywebsocket3/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import time
from collections import deque

import six

from pywebsocket3 import common, util
from pywebsocket3._stream_exceptions import (
Expand Down Expand Up @@ -564,7 +563,7 @@ def send_message(self, message, end=True, binary=False):
raise BadOperationException(
'Requested send_message after sending out a closing handshake')

if binary and isinstance(message, six.text_type):
if binary and isinstance(message, str):
raise BadOperationException(
'Message for binary frame must not be instance of Unicode')

Expand Down Expand Up @@ -897,7 +896,7 @@ def close_connection(self,
reason = ''
else:
if not isinstance(reason, bytes) and not isinstance(
reason, six.text_type):
reason, str):
raise BadOperationException(
'close reason must be an instance of bytes or unicode')

Expand Down Expand Up @@ -926,7 +925,7 @@ def close_connection(self,
# note: mod_python Connection (mp_conn) doesn't have close method.

def send_ping(self, body, binary=False):
if not binary and isinstance(body, six.text_type):
if not binary and isinstance(body, str):
body = body.encode('UTF-8')
frame = create_ping_frame(body, self._options.mask_send,
self._options.outgoing_frame_filters)
Expand Down
8 changes: 3 additions & 5 deletions pywebsocket3/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import struct
import zlib

import six
from six.moves import map, range

try:
from pywebsocket3 import fast_masking
Expand Down Expand Up @@ -96,7 +94,7 @@ def get_script_interp(script_path, cygwin_path=None):


def hexify(s):
return ' '.join(['%02x' % x for x in six.iterbytes(s)])
return ' '.join(['%02x' % x for x in iter(s)])


def get_class_logger(o):
Expand Down Expand Up @@ -147,15 +145,15 @@ def _mask_using_swig(self, s):

def _mask_using_array(self, s):
"""Perform the mask via python."""
if isinstance(s, six.text_type):
if isinstance(s, str):
raise Exception(
'Masking Operation should not process unicode strings')

result = bytearray(s)

# Use temporary local variables to eliminate the cost to access
# attributes
masking_key = [c for c in six.iterbytes(self._masking_key)]
masking_key = [c for c in iter(self._masking_key)]
masking_key_size = len(masking_key)
masking_key_index = self._masking_key_index

Expand Down
Loading