mirror of
https://github.com/frappe/gunicorn.git
synced 2026-07-07 21:21:30 +08:00
Fix lint issues in ASGI parser and protocol
This commit is contained in:
parent
8ad49b8df3
commit
86c0baf933
@ -12,7 +12,6 @@ or the pure Python PythonProtocol fallback.
|
|||||||
|
|
||||||
class ParseError(Exception):
|
class ParseError(Exception):
|
||||||
"""Error raised during HTTP parsing."""
|
"""Error raised during HTTP parsing."""
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class PythonProtocol:
|
class PythonProtocol:
|
||||||
|
|||||||
@ -124,7 +124,6 @@ class FlowControl:
|
|||||||
def _get_cached_date_header():
|
def _get_cached_date_header():
|
||||||
"""Get cached Date header, updating once per second."""
|
"""Get cached Date header, updating once per second."""
|
||||||
global _cached_date_header, _cached_date_time # pylint: disable=global-statement
|
global _cached_date_header, _cached_date_time # pylint: disable=global-statement
|
||||||
import time
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
if now - _cached_date_time >= 1.0:
|
if now - _cached_date_time >= 1.0:
|
||||||
# Update date header
|
# Update date header
|
||||||
@ -199,7 +198,7 @@ class BodyReceiver:
|
|||||||
if self._waiter is not None and not self._waiter.done():
|
if self._waiter is not None and not self._waiter.done():
|
||||||
self._waiter.set_result(None)
|
self._waiter.set_result(None)
|
||||||
|
|
||||||
async def receive(self):
|
async def receive(self): # pylint: disable=too-many-return-statements
|
||||||
"""ASGI receive callable - returns body chunks or disconnect."""
|
"""ASGI receive callable - returns body chunks or disconnect."""
|
||||||
# Already disconnected or body finished
|
# Already disconnected or body finished
|
||||||
if self._closed or self._body_finished:
|
if self._closed or self._body_finished:
|
||||||
@ -207,11 +206,7 @@ class BodyReceiver:
|
|||||||
|
|
||||||
# Fast path: chunk already available
|
# Fast path: chunk already available
|
||||||
if self._chunks:
|
if self._chunks:
|
||||||
chunk = self._chunks.pop(0)
|
return self._pop_chunk()
|
||||||
more = bool(self._chunks) or not self._complete
|
|
||||||
if not more:
|
|
||||||
self._body_finished = True
|
|
||||||
return {"type": "http.request", "body": chunk, "more_body": more}
|
|
||||||
|
|
||||||
# Body complete with no more chunks
|
# Body complete with no more chunks
|
||||||
if self._complete:
|
if self._complete:
|
||||||
@ -232,28 +227,33 @@ class BodyReceiver:
|
|||||||
# Wait for body chunk to arrive via callback
|
# Wait for body chunk to arrive via callback
|
||||||
try:
|
try:
|
||||||
await self._wait_for_data()
|
await self._wait_for_data()
|
||||||
|
return self._build_receive_result()
|
||||||
# Check what arrived
|
|
||||||
if self._closed:
|
|
||||||
return {"type": "http.disconnect"}
|
|
||||||
|
|
||||||
if self._chunks:
|
|
||||||
chunk = self._chunks.pop(0)
|
|
||||||
more = bool(self._chunks) or not self._complete
|
|
||||||
if not more:
|
|
||||||
self._body_finished = True
|
|
||||||
return {"type": "http.request", "body": chunk, "more_body": more}
|
|
||||||
|
|
||||||
if self._complete:
|
|
||||||
self._body_finished = True
|
|
||||||
return {"type": "http.request", "body": b"", "more_body": False}
|
|
||||||
|
|
||||||
# Timeout or other condition - return empty with more_body=True
|
|
||||||
return {"type": "http.request", "body": b"", "more_body": True}
|
|
||||||
|
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
return {"type": "http.disconnect"}
|
return {"type": "http.disconnect"}
|
||||||
|
|
||||||
|
def _pop_chunk(self):
|
||||||
|
"""Pop a chunk and return the appropriate message."""
|
||||||
|
chunk = self._chunks.pop(0)
|
||||||
|
more = bool(self._chunks) or not self._complete
|
||||||
|
if not more:
|
||||||
|
self._body_finished = True
|
||||||
|
return {"type": "http.request", "body": chunk, "more_body": more}
|
||||||
|
|
||||||
|
def _build_receive_result(self):
|
||||||
|
"""Build receive result after waiting for data."""
|
||||||
|
if self._closed:
|
||||||
|
return {"type": "http.disconnect"}
|
||||||
|
|
||||||
|
if self._chunks:
|
||||||
|
return self._pop_chunk()
|
||||||
|
|
||||||
|
if self._complete:
|
||||||
|
self._body_finished = True
|
||||||
|
return {"type": "http.request", "body": b"", "more_body": False}
|
||||||
|
|
||||||
|
# Timeout or other condition - return empty with more_body=True
|
||||||
|
return {"type": "http.request", "body": b"", "more_body": True}
|
||||||
|
|
||||||
async def _wait_for_data(self):
|
async def _wait_for_data(self):
|
||||||
"""Wait for body data to arrive via callback."""
|
"""Wait for body data to arrive via callback."""
|
||||||
if self._chunks or self._complete or self._closed:
|
if self._chunks or self._complete or self._closed:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user