Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

really drop python <=3.7 support #1476

Closed
wants to merge 2 commits into from
Closed
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 compliance/test_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio
import json
import logging
import urllib.parse

import asyncio
import websockets


Expand Down
2 changes: 1 addition & 1 deletion compliance/test_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import logging

import asyncio
import websockets


Expand Down
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import importlib
import inspect
import os
import subprocess
import sys


# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
Expand All @@ -25,7 +25,6 @@
copyright = f"2013-{datetime.date.today().year}, Aymeric Augustin and contributors"
author = "Aymeric Augustin"

from websockets.version import tag as version, version as release
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will break generating the docs.



# -- General configuration ---------------------------------------------------
Expand Down Expand Up @@ -79,6 +78,7 @@
# Workaround for https://github.com/sphinx-doc/sphinx/issues/9560
from sphinx.domains.python import PythonDomain


assert PythonDomain.object_types["data"].roles == ("data", "obj")
PythonDomain.object_types["data"].roles = ("data", "class", "obj")

Expand All @@ -97,6 +97,7 @@
# Configure viewcode extension.
from websockets.version import commit


code_url = f"https://github.com/python-websockets/websockets/blob/{commit}"

def linkcode_resolve(domain, info):
Expand Down
2 changes: 1 addition & 1 deletion example/deployment/heroku/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python

import asyncio
import signal
import os
import signal

import websockets

Expand Down
1 change: 1 addition & 0 deletions example/deployment/kubernetes/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import sys

import websockets


Expand Down
1 change: 1 addition & 0 deletions example/django/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import django
import websockets


django.setup()

from sesame.utils import get_user
Expand Down
1 change: 1 addition & 0 deletions example/django/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import django
import websockets


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid gratuitous formatting changes. Also, probably the autoformatter built into the project would revert it at the next commit.

django.setup()

from django.contrib.contenttypes.models import ContentType
Expand Down
1 change: 0 additions & 1 deletion example/django/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.contrib.admin.models import LogEntry
from django.db.models.signals import post_save
from django.dispatch import receiver

from django_redis import get_redis_connection


Expand Down
2 changes: 2 additions & 0 deletions example/echo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python

import asyncio

from websockets.server import serve


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, gratuitous change that will make the docs look worse.

async def echo(websocket):
async for message in websocket:
await websocket.send(message)
Expand Down
2 changes: 2 additions & 0 deletions example/faq/health_check_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import asyncio
import http

import websockets


async def health_check(path, request_headers):
if path == "/healthz":
return http.HTTPStatus.OK, [], b"OK\n"
Expand Down
2 changes: 2 additions & 0 deletions example/faq/shutdown_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import asyncio
import signal

import websockets


async def client():
uri = "ws://localhost:8765"
async with websockets.connect(uri) as websocket:
Expand Down
2 changes: 2 additions & 0 deletions example/faq/shutdown_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import asyncio
import signal

import websockets


async def echo(websocket):
async for message in websocket:
await websocket.send(message)
Expand Down
2 changes: 1 addition & 1 deletion example/hello.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python

import asyncio
from websockets.sync.client import connect


def hello():
with connect("ws://localhost:8765") as websocket:
websocket.send("Hello world!")
Expand Down
2 changes: 2 additions & 0 deletions example/legacy/basic_auth_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# WS client example with HTTP Basic Authentication

import asyncio

import websockets


async def hello():
uri = "ws://mary:p@ssw0rd@localhost:8765"
async with websockets.connect(uri) as websocket:
Expand Down
2 changes: 2 additions & 0 deletions example/legacy/basic_auth_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# Server example with HTTP Basic Authentication over TLS

import asyncio

import websockets


async def hello(websocket):
greeting = f"Hello {websocket.username}!"
await websocket.send(greeting)
Expand Down
2 changes: 2 additions & 0 deletions example/legacy/unix_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import asyncio
import os.path

import websockets


async def hello():
socket_path = os.path.join(os.path.dirname(__file__), "socket")
async with websockets.unix_connect(socket_path) as websocket:
Expand Down
2 changes: 2 additions & 0 deletions example/legacy/unix_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import asyncio
import os.path

import websockets


async def hello(websocket):
name = await websocket.recv()
print(f"<<< {name}")
Expand Down
3 changes: 2 additions & 1 deletion example/logging/json_log_formatter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import json
import logging
import datetime


class JSONFormatter(logging.Formatter):
"""
Expand Down
2 changes: 2 additions & 0 deletions example/quickstart/client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python

import asyncio

import websockets


async def hello():
uri = "ws://localhost:8765"
async with websockets.connect(uri) as websocket:
Expand Down
2 changes: 2 additions & 0 deletions example/quickstart/client_secure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import asyncio
import pathlib
import ssl

import websockets


ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
localhost_pem = pathlib.Path(__file__).with_name("localhost.pem")
ssl_context.load_verify_locations(localhost_pem)
Expand Down
2 changes: 2 additions & 0 deletions example/quickstart/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import asyncio
import json
import logging

import websockets


logging.basicConfig()

USERS = set()
Expand Down
2 changes: 2 additions & 0 deletions example/quickstart/server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python

import asyncio

import websockets


async def hello(websocket):
name = await websocket.recv()
print(f"<<< {name}")
Expand Down
2 changes: 2 additions & 0 deletions example/quickstart/server_secure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import asyncio
import pathlib
import ssl

import websockets


async def hello(websocket):
name = await websocket.recv()
print(f"<<< {name}")
Expand Down
2 changes: 2 additions & 0 deletions example/quickstart/show_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import asyncio
import datetime
import random

import websockets


async def show_time(websocket):
while True:
message = datetime.datetime.utcnow().isoformat() + "Z"
Expand Down
2 changes: 2 additions & 0 deletions example/quickstart/show_time_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import asyncio
import datetime
import random

import websockets


CONNECTIONS = set()

async def register(websocket):
Expand Down
1 change: 0 additions & 1 deletion example/tutorial/step1/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import json

import websockets

from connect4 import PLAYER1, PLAYER2, Connect4


Expand Down
1 change: 0 additions & 1 deletion example/tutorial/step2/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import secrets

import websockets

from connect4 import PLAYER1, PLAYER2, Connect4


Expand Down
1 change: 0 additions & 1 deletion example/tutorial/step3/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import signal

import websockets

from connect4 import PLAYER1, PLAYER2, Connect4


Expand Down
26 changes: 13 additions & 13 deletions src/websockets/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import warnings
from typing import Any, Generator, List, Optional, Sequence
from typing import Any, Generator, Sequence

from .datastructures import Headers, MultipleValuesError
from .exceptions import (
Expand Down Expand Up @@ -73,12 +73,12 @@ def __init__(
self,
wsuri: WebSocketURI,
*,
origin: Optional[Origin] = None,
extensions: Optional[Sequence[ClientExtensionFactory]] = None,
subprotocols: Optional[Sequence[Subprotocol]] = None,
origin: Origin | None = None,
extensions: Sequence[ClientExtensionFactory] | None = None,
subprotocols: Sequence[Subprotocol] | None = None,
state: State = CONNECTING,
max_size: Optional[int] = 2**20,
logger: Optional[LoggerLike] = None,
max_size: int | None = 2**20,
logger: LoggerLike | None = None,
):
super().__init__(
side=CLIENT,
Expand Down Expand Up @@ -153,7 +153,7 @@ def process_response(self, response: Response) -> None:

headers = response.headers

connection: List[ConnectionOption] = sum(
connection: list[ConnectionOption] = sum(
[parse_connection(value) for value in headers.get_all("Connection")], []
)

Expand All @@ -162,7 +162,7 @@ def process_response(self, response: Response) -> None:
"Connection", ", ".join(connection) if connection else None
)

upgrade: List[UpgradeProtocol] = sum(
upgrade: list[UpgradeProtocol] = sum(
[parse_upgrade(value) for value in headers.get_all("Upgrade")], []
)

Expand All @@ -188,7 +188,7 @@ def process_response(self, response: Response) -> None:

self.subprotocol = self.process_subprotocol(headers)

def process_extensions(self, headers: Headers) -> List[Extension]:
def process_extensions(self, headers: Headers) -> list[Extension]:
"""
Handle the Sec-WebSocket-Extensions HTTP response header.

Expand Down Expand Up @@ -219,15 +219,15 @@ def process_extensions(self, headers: Headers) -> List[Extension]:
InvalidHandshake: To abort the handshake.

"""
accepted_extensions: List[Extension] = []
accepted_extensions: list[Extension] = []

extensions = headers.get_all("Sec-WebSocket-Extensions")

if extensions:
if self.available_extensions is None:
raise InvalidHandshake("no extensions supported")

parsed_extensions: List[ExtensionHeader] = sum(
parsed_extensions: list[ExtensionHeader] = sum(
[parse_extension(header_value) for header_value in extensions], []
)

Expand Down Expand Up @@ -261,7 +261,7 @@ def process_extensions(self, headers: Headers) -> List[Extension]:

return accepted_extensions

def process_subprotocol(self, headers: Headers) -> Optional[Subprotocol]:
def process_subprotocol(self, headers: Headers) -> Subprotocol | None:
"""
Handle the Sec-WebSocket-Protocol HTTP response header.

Expand All @@ -274,7 +274,7 @@ def process_subprotocol(self, headers: Headers) -> Optional[Subprotocol]:
Subprotocol, if one was selected.

"""
subprotocol: Optional[Subprotocol] = None
subprotocol: Subprotocol | None = None

subprotocols = headers.get_all("Sec-WebSocket-Protocol")

Expand Down
Loading
Loading