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

[PR #6539/6681a460 backport][3.8] Recover missing import in circular import test #6540

4 changes: 2 additions & 2 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def __init__(
trust_env: bool = False,
requote_redirect_url: bool = True,
trace_configs: Optional[List[TraceConfig]] = None,
read_bufsize: int = 2 ** 16,
read_bufsize: int = 2**16,
) -> None:
if loop is None:
if connector is not None:
Expand Down Expand Up @@ -866,7 +866,7 @@ async def _ws_connect(
transport = conn.transport
assert transport is not None
reader: FlowControlDataQueue[WSMessage] = FlowControlDataQueue(
conn_proto, 2 ** 16, loop=self._loop
conn_proto, 2**16, loop=self._loop
)
conn_proto.set_parser(WebSocketReader(reader, max_msg_size), reader)
writer = WebSocketWriter(
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/client_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def set_response_params(
read_until_eof: bool = False,
auto_decompress: bool = True,
read_timeout: Optional[float] = None,
read_bufsize: int = 2 ** 16,
read_bufsize: int = 2**16,
) -> None:
self._skip_payload = skip_payload

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CookieJar(AbstractCookieJar):

MAX_TIME = datetime.datetime.max.replace(tzinfo=datetime.timezone.utc)

MAX_32BIT_TIME = datetime.datetime.utcfromtimestamp(2 ** 31 - 1)
MAX_32BIT_TIME = datetime.datetime.utcfromtimestamp(2**31 - 1)

def __init__(
self,
Expand Down
5 changes: 2 additions & 3 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def all_tasks(
tasks = list(asyncio.Task.all_tasks(loop))
return {t for t in tasks if not t.done()}


else:
all_tasks = asyncio.all_tasks

Expand Down Expand Up @@ -845,9 +844,9 @@ def __repr__(self) -> str:
# https://tools.ietf.org/html/rfc7232#section-2.3
_ETAGC = r"[!#-}\x80-\xff]+"
_ETAGC_RE = re.compile(_ETAGC)
_QUOTED_ETAG = fr'(W/)?"({_ETAGC})"'
_QUOTED_ETAG = rf'(W/)?"({_ETAGC})"'
QUOTED_ETAG_RE = re.compile(_QUOTED_ETAG)
LIST_QUOTED_ETAG_RE = re.compile(fr"({_QUOTED_ETAG})(?:\s*,\s*|$)|(.)")
LIST_QUOTED_ETAG_RE = re.compile(rf"({_QUOTED_ETAG})(?:\s*,\s*|$)|(.)")

ETAG_ANY = "*"

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def __init__(
self,
protocol: Optional[BaseProtocol] = None,
loop: Optional[asyncio.AbstractEventLoop] = None,
limit: int = 2 ** 16,
limit: int = 2**16,
max_line_size: int = 8190,
max_headers: int = 32768,
max_field_size: int = 8190,
Expand Down
4 changes: 2 additions & 2 deletions aiohttp/http_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class WSMsgType(IntEnum):
PACK_LEN2 = Struct("!BBH").pack
PACK_LEN3 = Struct("!BBQ").pack
PACK_CLOSE_CODE = Struct("!H").pack
MSG_SIZE: Final[int] = 2 ** 14
DEFAULT_LIMIT: Final[int] = 2 ** 16
MSG_SIZE: Final[int] = 2**14
DEFAULT_LIMIT: Final[int] = 2**16


_WSMessageBase = collections.namedtuple("_WSMessageBase", ["type", "data", "extra"])
Expand Down
8 changes: 4 additions & 4 deletions aiohttp/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,10 @@ def __init__(self, value: BodyPartReader, *args: Any, **kwargs: Any) -> None:

async def write(self, writer: Any) -> None:
field = self._value
chunk = await field.read_chunk(size=2 ** 16)
chunk = await field.read_chunk(size=2**16)
while chunk:
await writer.write(field.decode(chunk))
chunk = await field.read_chunk(size=2 ** 16)
chunk = await field.read_chunk(size=2**16)


class MultipartReader:
Expand Down Expand Up @@ -747,8 +747,8 @@ def __len__(self) -> int:
def __bool__(self) -> bool:
return True

_valid_tchar_regex = re.compile(br"\A[!#$%&'*+\-.^_`|~\w]+\Z")
_invalid_qdtext_char_regex = re.compile(br"[\x00-\x08\x0A-\x1F\x7F]")
_valid_tchar_regex = re.compile(rb"\A[!#$%&'*+\-.^_`|~\w]+\Z")
_invalid_qdtext_char_regex = re.compile(rb"[\x00-\x08\x0A-\x1F\x7F]")

@property
def _boundary_value(self) -> str:
Expand Down
10 changes: 5 additions & 5 deletions aiohttp/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"AsyncIterablePayload",
)

TOO_LARGE_BYTES_BODY: Final[int] = 2 ** 20 # 1 MB
TOO_LARGE_BYTES_BODY: Final[int] = 2**20 # 1 MB

if TYPE_CHECKING: # pragma: no cover
from typing import List
Expand Down Expand Up @@ -301,10 +301,10 @@ def __init__(
async def write(self, writer: AbstractStreamWriter) -> None:
loop = asyncio.get_event_loop()
try:
chunk = await loop.run_in_executor(None, self._value.read, 2 ** 16)
chunk = await loop.run_in_executor(None, self._value.read, 2**16)
while chunk:
await writer.write(chunk)
chunk = await loop.run_in_executor(None, self._value.read, 2 ** 16)
chunk = await loop.run_in_executor(None, self._value.read, 2**16)
finally:
await loop.run_in_executor(None, self._value.close)

Expand Down Expand Up @@ -350,15 +350,15 @@ def size(self) -> Optional[int]:
async def write(self, writer: AbstractStreamWriter) -> None:
loop = asyncio.get_event_loop()
try:
chunk = await loop.run_in_executor(None, self._value.read, 2 ** 16)
chunk = await loop.run_in_executor(None, self._value.read, 2**16)
while chunk:
data = (
chunk.encode(encoding=self._encoding)
if self._encoding
else chunk.encode()
)
await writer.write(data)
chunk = await loop.run_in_executor(None, self._value.read, 2 ** 16)
chunk = await loop.run_in_executor(None, self._value.read, 2**16)
finally:
await loop.run_in_executor(None, self._value.close)

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def __repr__(self) -> str:
info.append("%d bytes" % self._size)
if self._eof:
info.append("eof")
if self._low_water != 2 ** 16: # default limit
if self._low_water != 2**16: # default limit
info.append("low=%d high=%d" % (self._low_water, self._high_water))
if self._waiter:
info.append("w=%r" % self._waiter)
Expand Down
1 change: 0 additions & 1 deletion aiohttp/tcp_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def tcp_keepalive(transport: asyncio.Transport) -> None:
if sock is not None:
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)


else:

def tcp_keepalive(transport: asyncio.Transport) -> None: # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ def make_mocked_request(
transport: Any = sentinel,
payload: Any = sentinel,
sslcontext: Optional[SSLContext] = None,
client_max_size: int = 1024 ** 2,
client_max_size: int = 1024**2,
loop: Any = ...,
) -> Request:
"""Creates mocked web.Request testing purposes.
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def __init__(
router: Optional[UrlDispatcher] = None,
middlewares: Iterable[_Middleware] = (),
handler_args: Optional[Mapping[str, Any]] = None,
client_max_size: int = 1024 ** 2,
client_max_size: int = 1024**2,
loop: Optional[asyncio.AbstractEventLoop] = None,
debug: Any = ..., # mypy doesn't support ellipsis
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def __init__(
max_headers: int = 32768,
max_field_size: int = 8190,
lingering_time: float = 10.0,
read_bufsize: int = 2 ** 16,
read_bufsize: int = 2**16,
auto_decompress: bool = True,
):
super().__init__(loop)
Expand Down
8 changes: 4 additions & 4 deletions aiohttp/web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class FileField:
_TCHAR: Final[str] = string.digits + string.ascii_letters + r"!#$%&'*+.^_`|~-"
# '-' at the end to prevent interpretation as range in a char class

_TOKEN: Final[str] = fr"[{_TCHAR}]+"
_TOKEN: Final[str] = rf"[{_TCHAR}]+"

_QDTEXT: Final[str] = r"[{}]".format(
r"".join(chr(c) for c in (0x09, 0x20, 0x21) + tuple(range(0x23, 0x7F)))
Expand Down Expand Up @@ -148,7 +148,7 @@ def __init__(
task: "asyncio.Task[None]",
loop: asyncio.AbstractEventLoop,
*,
client_max_size: int = 1024 ** 2,
client_max_size: int = 1024**2,
state: Optional[Dict[str, Any]] = None,
scheme: Optional[str] = None,
host: Optional[str] = None,
Expand Down Expand Up @@ -712,7 +712,7 @@ async def post(self) -> "MultiDictProxy[Union[str, bytes, FileField]]":
if field.filename:
# store file in temp file
tmp = tempfile.TemporaryFile()
chunk = await field.read_chunk(size=2 ** 16)
chunk = await field.read_chunk(size=2**16)
while chunk:
chunk = field.decode(chunk)
tmp.write(chunk)
Expand All @@ -722,7 +722,7 @@ async def post(self) -> "MultiDictProxy[Union[str, bytes, FileField]]":
raise HTTPRequestEntityTooLarge(
max_size=max_size, actual_size=size
)
chunk = await field.read_chunk(size=2 ** 16)
chunk = await field.read_chunk(size=2**16)
tmp.seek(0)

if field_ct is None:
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def _post_start(

loop = self._loop
assert loop is not None
self._reader = FlowControlDataQueue(request._protocol, 2 ** 16, loop=loop)
self._reader = FlowControlDataQueue(request._protocol, 2**16, loop=loop)
request.protocol.set_parser(
WebSocketReader(self._reader, self._max_msg_size, compress=self._compress)
)
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def tls_certificate_fingerprint_sha256(tls_certificate_pem_bytes):

@pytest.fixture
def pipe_name():
name = fr"\\.\pipe\{uuid.uuid4().hex}"
name = rf"\\.\pipe\{uuid.uuid4().hex}"
return name


Expand Down
2 changes: 1 addition & 1 deletion tests/test_circular_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ def test_no_warnings(import_path: str) -> None:
This is seeking for any import errors including ones caused
by circular imports.
"""
imp_cmd = sys.executable, "-W", "error"
imp_cmd = sys.executable, "-W", "error", "-c", f"import {import_path!s}"

subprocess.check_call(imp_cmd)
2 changes: 1 addition & 1 deletion tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ async def handler(request):


async def test_POST_bytes_too_large(aiohttp_client) -> None:
body = b"0" * (2 ** 20 + 1)
body = b"0" * (2**20 + 1)

async def handler(request):
data = await request.content.read()
Expand Down
Loading