Skip to content

Commit cdc13c1

Browse files
committed
Move asyncio callback methods from CoreProtocol to Protocol
CoreProtocol is supposed to be I/O agnostic, and these methods were put there by an oversight.
1 parent d201868 commit cdc13c1

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

asyncpg/protocol/coreproto.pyx

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -924,34 +924,5 @@ cdef class CoreProtocol:
924924
cdef _on_connection_lost(self, exc):
925925
pass
926926

927-
# asyncio callbacks:
928-
929-
def data_received(self, data):
930-
self.buffer.feed_data(data)
931-
self._read_server_messages()
932-
933-
def connection_made(self, transport):
934-
self.transport = transport
935-
936-
sock = transport.get_extra_info('socket')
937-
if (sock is not None and
938-
(not hasattr(socket, 'AF_UNIX')
939-
or sock.family != socket.AF_UNIX)):
940-
sock.setsockopt(socket.IPPROTO_TCP,
941-
socket.TCP_NODELAY, 1)
942-
943-
try:
944-
self._connect()
945-
except Exception as ex:
946-
transport.abort()
947-
self.con_status = CONNECTION_BAD
948-
self._set_state(PROTOCOL_FAILED)
949-
self._on_error(ex)
950-
951-
def connection_lost(self, exc):
952-
self.con_status = CONNECTION_BAD
953-
self._set_state(PROTOCOL_FAILED)
954-
self._on_connection_lost(exc)
955-
956927

957928
cdef bytes SYNC_MESSAGE = bytes(WriteBuffer.new_message(b'S').end_message())

asyncpg/protocol/protocol.pyx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,35 @@ cdef class BaseProtocol(CoreProtocol):
883883
self.closing = True
884884
self._handle_waiter_on_connection_lost(exc)
885885

886+
# asyncio callbacks:
887+
888+
def data_received(self, data):
889+
self.buffer.feed_data(data)
890+
self._read_server_messages()
891+
892+
def connection_made(self, transport):
893+
self.transport = transport
894+
895+
sock = transport.get_extra_info('socket')
896+
if (sock is not None and
897+
(not hasattr(socket, 'AF_UNIX')
898+
or sock.family != socket.AF_UNIX)):
899+
sock.setsockopt(socket.IPPROTO_TCP,
900+
socket.TCP_NODELAY, 1)
901+
902+
try:
903+
self._connect()
904+
except Exception as ex:
905+
transport.abort()
906+
self.con_status = CONNECTION_BAD
907+
self._set_state(PROTOCOL_FAILED)
908+
self._on_error(ex)
909+
910+
def connection_lost(self, exc):
911+
self.con_status = CONNECTION_BAD
912+
self._set_state(PROTOCOL_FAILED)
913+
self._on_connection_lost(exc)
914+
886915
def pause_writing(self):
887916
self.writing_allowed.clear()
888917

0 commit comments

Comments
 (0)