MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / data_received

Method data_received

asyncpg/connect_utils.py:943–968  ·  view source on GitHub ↗
(self, data: bytes)

Source from the content-addressed store, hash-verified

941 self.ssl_is_advisory = ssl_is_advisory
942
943 def data_received(self, data: bytes) -> None:
944 if self.on_data.done():
945 return
946 if data == b'S':
947 self.on_data.set_result(True)
948 elif (self.ssl_is_advisory and
949 self.ssl_context.verify_mode == ssl_module.CERT_NONE and
950 data == b'N'):
951 # ssl_is_advisory will imply that ssl.verify_mode == CERT_NONE,
952 # since the only way to get ssl_is_advisory is from
953 # sslmode=prefer. But be extra sure to disallow insecure
954 # connections when the ssl context asks for real security.
955 self.on_data.set_result(False)
956 elif data.startswith(b'E'):
957 # Never trust or expose pre-TLS ErrorResponse fields
958 # (including SQLSTATE). See CVE-2024-10977.
959 self.on_data.set_exception(ConnectionError(
960 f'PostgreSQL server at "{self.host}:{self.port}": '
961 'server sent an error response during SSL exchange; '
962 'check the server logs for details'))
963 else:
964 self.on_data.set_exception(
965 ConnectionError(
966 'PostgreSQL server at "{host}:{port}" '
967 'rejected SSL upgrade'.format(
968 host=self.host, port=self.port)))
969
970 def connection_lost(self, exc: typing.Optional[Exception]) -> None:
971 if not self.on_data.done():

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected