Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
in_file = sys.stdin
def process_all(c):
while True:
event = c.next_event()
if event is h11.NEED_DATA or event is h11.PAUSED:
break
if type(event) is h11.ConnectionClosed:
break
afl.init()
data = in_file.read()
# one big chunk
server1 = h11.Connection(h11.SERVER)
try:
server1.receive_data(data)
process_all(server1)
server1.receive_data(b"")
process_all(server1)
except h11.RemoteProtocolError:
pass
# byte at a time
server2 = h11.Connection(h11.SERVER)
try:
for i in range(len(data)):
server2.receive_data(data[i:i + 1])
process_all(server2)
server2.receive_data(b"")
process_all(server2)
def __init__(self, config, server_state, _loop=None):
if not config.loaded:
config.load()
self.config = config
self.app = config.loaded_app
self.loop = _loop or asyncio.get_event_loop()
self.logger = logging.getLogger("uvicorn.error")
self.access_logger = logging.getLogger("uvicorn.access")
self.access_log = self.access_logger.hasHandlers()
self.conn = h11.Connection(h11.SERVER)
self.ws_protocol_class = config.ws_protocol_class
self.root_path = config.root_path
self.limit_concurrency = config.limit_concurrency
# Timeouts
self.timeout_keep_alive_task = None
self.timeout_keep_alive = config.timeout_keep_alive
# Shared server state
self.server_state = server_state
self.connections = server_state.connections
self.tasks = server_state.tasks
self.default_headers = server_state.default_headers
# Per-connection state
self.transport = None
def __init__(self, stream):
self.stream = stream
self.conn = h11.Connection(h11.SERVER)
# Our Server: header
self.ident = " ".join([
"h11-example-trio-server/{}".format(h11.__version__),
h11.PRODUCT_ID,
]).encode("ascii")
# A unique id for this connection, to include in debugging output
# (useful for understanding what's going on if there are multiple
# simultaneous clients).
self._obj_id = next(TrioHTTPWrapper._next_id)
def __init__(
self,
app: ASGIFramework,
loop: asyncio.AbstractEventLoop,
config: Config,
transport: asyncio.BaseTransport,
) -> None:
super().__init__(loop, config, transport, "h11")
self.app = app
self.connection = h11.Connection(
h11.SERVER, max_incomplete_event_size=self.config.h11_max_incomplete_size
)
self.app_queue: asyncio.Queue = asyncio.Queue(loop=loop)
self.response: Optional[dict] = None
self.scope: Optional[dict] = None
self.state = ASGIHTTPState.REQUEST
self.task: Optional[asyncio.Future] = None
def __init__(self, connection_type: ConnectionType) -> None:
self.client = connection_type is ConnectionType.CLIENT
self._state = ConnectionState.CONNECTING
if self.client:
self._h11_connection = h11.Connection(h11.CLIENT)
else:
self._h11_connection = h11.Connection(h11.SERVER)
self._connection: Optional[Connection] = None
self._events: Deque[Event] = deque()
self._initiating_request: Optional[Request] = None
self._nonce: Optional[bytes] = None
code=str(event.status_code),
headers=event.headers))
elif isinstance(event, Response):
self._resp = event
if self.our_state is h11.SWITCHED_PROTOCOL:
self.on_response(HttpResponse(
version=self._parse_version(self._resp),
reason=self._resp.reason,
code=str(self._resp.status_code),
headers=self._resp.headers,
body=b"".join(self._body_chunks)))
self._cleanup_after_received()
elif isinstance(event, Data):
self._body_chunks.append(bytes(event.data))
elif isinstance(event, EndOfMessage):
if self.our_role is h11.SERVER:
if not self._req: # pragma: no cover
# NOTE: guess that never happen because h11 should help us handle http state
raise ProtocolError("EndOfMessage received, but not request found")
self.on_request(HttpRequest(
version=self._parse_version(self._req),
method=self._req.method,
path=self._req.target,
headers=self._req.headers,
body=b"".join(self._body_chunks)))
else:
if not self._resp: # pragma: no cover
# NOTE: guess that never happen because h11 should help us handle http state
raise ProtocolError("EndOfMessage received, but not response found")
self.on_response(HttpResponse(
version=self._parse_version(self._resp),
reason=self._resp.reason,
def setup(self):
super().setup()
self._logger = getNextLogger('turq.connection')
self._socket = self.request # To reduce confusion with HTTP requests
self._hconn = h11.Connection(our_role=h11.SERVER)
def __init__(self, stream):
self.stream = stream
self.conn = h11.Connection(h11.SERVER)
# Our Server: header
self.ident = " ".join([
"trio-asgi/0.0.1",
h11.PRODUCT_ID,
]).encode("ascii")
# A unique id for this connection, to include in debugging output
# (useful for understanding what's going on if there are multiple
# simultaneous clients).
self._obj_id = next(TrioHTTPWrapper._next_id)