Skip to content
Myr

Drop write_no_block from backends. (#594)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Drop write_no_block * Drop redundant code from Trio backend

authored by Tom Christie · committed by GitHub · parent fc95c7e · Browse files · 4 files+20 added−32 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+20 added−32 removed

  • other:+20 added−32 removed

4 files+20 added−32 removed

modified:httpx/concurrency/asyncio.py-3 removed
160 unmodified lines
161 break162163 return data164165 def write_no_block(self, data: bytes) -> None:166 self.stream_writer.write(data) # pragma: nocover167165 async def write(166 self, data: bytes, timeout: Timeout = None, flag: TimeoutFlag = None167 ) -> None:168 if not data:
182 unmodified lines
modified:httpx/concurrency/base.py-3 removed
75 unmodified lines
7677 async def read(self, n: int, timeout: Timeout, flag: typing.Any = None) -> bytes:78 raise NotImplementedError() # pragma: no cover7980 def write_no_block(self, data: bytes) -> None:81 raise NotImplementedError() # pragma: no cover8280 async def write(self, data: bytes, timeout: Timeout) -> None:81 raise NotImplementedError() # pragma: no cover8283 async def close(self) -> None:
97 unmodified lines
modified:httpx/concurrency/trio.py-19 removed
25 unmodified lines
26 self, stream: typing.Union[trio.SocketStream, trio.SSLStream], timeout: Timeout,27 ) -> None:28 self.stream = stream29 self.timeout = timeout30 self.write_buffer = b""30 self.read_lock = trio.Lock()31 self.write_lock = trio.Lock()3233 async def start_tls(34 self, hostname: str, ssl_context: ssl.SSLContext, timeout: Timeout35 ) -> "SocketStream":37 # Check that the write buffer is empty. We should never start a TLS stream38 # while there is still pending data to write.39 assert self.write_buffer == b""4036 connect_timeout = _or_inf(timeout.connect_timeout)37 ssl_stream = trio.SSLStream(38 self.stream, ssl_context=ssl_context, server_hostname=hostname39 )
46 unmodified lines
86 # called `.recv()` on it, indicating that the other end has closed the socket.87 # See: https://github.com/encode/httpx/pull/143#issuecomment-51518177888 return stream.socket.is_readable()8995 def write_no_block(self, data: bytes) -> None:96 self.write_buffer += data # pragma: no cover9790 async def write(91 self, data: bytes, timeout: Timeout = None, flag: TimeoutFlag = None92 ) -> None:101 if self.write_buffer:102 previous_data = self.write_buffer103 # Reset before recursive call, otherwise we'll go through104 # this branch indefinitely.105 self.write_buffer = b""106 try:107 await self.write(previous_data, timeout=timeout, flag=flag)108 except WriteTimeout:109 self.writer_buffer = previous_data110 raise11193 if not data:94 return9596 if timeout is None:
161 unmodified lines
modified:httpx/dispatch/http2.py+20 added-7 removed
33 unmodified lines
34 self.on_release = on_release35 self.h2_state = h2.connection.H2Connection()36 self.events = {} # type: typing.Dict[int, typing.List[h2.events.Event]]37 self.timeout_flags = {} # type: typing.Dict[int, TimeoutFlag]38 self.initialized = False38 self.window_update_received = {} # type: typing.Dict[int, BaseEvent]3940 self.init_started = False4142 @property43 def init_complete(self) -> BaseEvent:44 # We do this lazily, to make sure backend autodetection always45 # runs within an async context.46 if not hasattr(self, "_initialization_complete"):47 self._initialization_complete = self.backend.create_event()48 return self._initialization_complete4950 async def send(self, request: Request, timeout: Timeout = None) -> Response:51 timeout = Timeout() if timeout is None else timeout5244 # Start sending the request.45 if not self.initialized:46 self.initiate_connection()53 if not self.init_started:54 # The very first stream is responsible for initiating the connection.55 self.init_started = True56 await self.send_connection_init(timeout)57 self.init_complete.set()58 else:59 # All other streams need to wait until the connection is established.60 await self.init_complete.wait()6162 stream_id = await self.send_headers(request, timeout)6364 self.events[stream_id] = []
17 unmodified lines
8283 async def close(self) -> None:84 await self.stream.close()8572 def initiate_connection(self) -> None:86 async def send_connection_init(self, timeout: Timeout) -> None:87 # Need to set these manually here instead of manipulating via88 # __setitem__() otherwise the H2Connection will emit SettingsUpdate89 # frames in addition to sending the undesired defaults.90 self.h2_state.local_settings = Settings(
16 unmodified lines
107 ]108109 self.h2_state.initiate_connection()110 data_to_send = self.h2_state.data_to_send()97 self.stream.write_no_block(data_to_send)98 self.initialized = True111 await self.stream.write(data_to_send, timeout)112113 async def send_headers(self, request: Request, timeout: Timeout) -> int:114 stream_id = self.h2_state.get_next_available_stream_id()115 headers = [
144 unmodified lines