Skip to content

Commit c2174dd

Browse files
138: Properly scope all internal functions in S2Connection. (#140)
1 parent ed4a196 commit c2174dd

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

src/s2python/s2_connection.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def __init__(self, connection: "S2Connection", subject_message_id: uuid.UUID):
102102
async def run_async(self) -> None:
103103
self.status_is_send.set()
104104

105-
await self.connection.respond_with_reception_status(
105+
await self.connection._respond_with_reception_status( # pylint: disable=protected-access
106106
subject_message_id=self.subject_message_id,
107107
status=ReceptionStatusValues.OK,
108108
diagnostic_label="Processed okay.",
@@ -168,7 +168,7 @@ def do_message() -> None:
168168
await eventloop.run_in_executor(executor=None, func=do_message)
169169
except Exception:
170170
if not send_okay.status_is_send.is_set():
171-
await connection.respond_with_reception_status(
171+
await connection._respond_with_reception_status( # pylint: disable=protected-access
172172
subject_message_id=msg.message_id, # type: ignore[attr-defined, union-attr]
173173
status=ReceptionStatusValues.PERMANENT_ERROR,
174174
diagnostic_label=f"While processing message {msg.message_id} " # type: ignore[attr-defined, union-attr] # pylint: disable=line-too-long
@@ -241,10 +241,10 @@ def __init__( # pylint: disable=too-many-arguments
241241
self._verify_certificate = verify_certificate
242242

243243
self._handlers.register_handler(
244-
SelectControlType, self.handle_select_control_type_as_rm
244+
SelectControlType, self._handle_select_control_type_as_rm
245245
)
246-
self._handlers.register_handler(Handshake, self.handle_handshake)
247-
self._handlers.register_handler(HandshakeResponse, self.handle_handshake_response_as_rm)
246+
self._handlers.register_handler(Handshake, self._handle_handshake)
247+
self._handlers.register_handler(HandshakeResponse, self._handle_handshake_response_as_rm)
248248
self._bearer_token = bearer_token
249249

250250
def start_as_rm(self) -> None:
@@ -359,7 +359,7 @@ async def _connect_ws(self) -> None:
359359
logger.info("Could not connect due to: %s", str(e))
360360

361361
async def _connect_as_rm(self) -> None:
362-
await self.send_msg_and_await_reception_status_async(
362+
await self._send_msg_and_await_reception_status_async(
363363
Handshake(
364364
message_id=uuid.uuid4(),
365365
role=self.role,
@@ -372,7 +372,7 @@ async def _connect_as_rm(self) -> None:
372372

373373
await self._handle_received_messages()
374374

375-
async def handle_handshake(
375+
async def _handle_handshake(
376376
self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None]
377377
) -> None:
378378
if not isinstance(message, Handshake):
@@ -389,7 +389,7 @@ async def handle_handshake(
389389
)
390390
await send_okay
391391

392-
async def handle_handshake_response_as_rm(
392+
async def _handle_handshake_response_as_rm(
393393
self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None]
394394
) -> None:
395395
if not isinstance(message, HandshakeResponse):
@@ -407,11 +407,11 @@ async def handle_handshake_response_as_rm(
407407
await send_okay
408408
logger.debug("Handshake complete. Sending first ResourceManagerDetails.")
409409

410-
await self.send_msg_and_await_reception_status_async(
410+
await self._send_msg_and_await_reception_status_async(
411411
self.asset_details.to_resource_manager_details(self.control_types)
412412
)
413413

414-
async def handle_select_control_type_as_rm(
414+
async def _handle_select_control_type_as_rm(
415415
self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None]
416416
) -> None:
417417
if not isinstance(message, SelectControlType):
@@ -476,13 +476,13 @@ async def _receive_messages(self) -> None:
476476
json_msg = json.loads(message)
477477
message_id = json_msg.get("message_id")
478478
if message_id:
479-
await self.respond_with_reception_status(
479+
await self._respond_with_reception_status(
480480
subject_message_id=message_id,
481481
status=ReceptionStatusValues.INVALID_MESSAGE,
482482
diagnostic_label=str(e),
483483
)
484484
else:
485-
await self.respond_with_reception_status(
485+
await self._respond_with_reception_status(
486486
subject_message_id=uuid.UUID("00000000-0000-0000-0000-000000000000"),
487487
status=ReceptionStatusValues.INVALID_DATA,
488488
diagnostic_label="Message appears valid json but could not find a message_id field.",
@@ -513,7 +513,7 @@ async def _send_and_forget(self, s2_msg: S2Message) -> None:
513513
logger.error("Unable to send message %s due to %s", s2_msg, str(e))
514514
self._restart_connection_event.set()
515515

516-
async def respond_with_reception_status(
516+
async def _respond_with_reception_status(
517517
self, subject_message_id: uuid.UUID, status: ReceptionStatusValues, diagnostic_label: str
518518
) -> None:
519519
logger.debug(
@@ -531,13 +531,13 @@ def respond_with_reception_status_sync(
531531
self, subject_message_id: uuid.UUID, status: ReceptionStatusValues, diagnostic_label: str
532532
) -> None:
533533
asyncio.run_coroutine_threadsafe(
534-
self.respond_with_reception_status(
534+
self._respond_with_reception_status(
535535
subject_message_id, status, diagnostic_label
536536
),
537537
self._eventloop,
538538
).result()
539539

540-
async def send_msg_and_await_reception_status_async(
540+
async def _send_msg_and_await_reception_status_async(
541541
self,
542542
s2_msg: S2Message,
543543
timeout_reception_status: float = 5.0,
@@ -575,7 +575,7 @@ def send_msg_and_await_reception_status_sync(
575575
raise_on_error: bool = True,
576576
) -> ReceptionStatus:
577577
return asyncio.run_coroutine_threadsafe(
578-
self.send_msg_and_await_reception_status_async(
578+
self._send_msg_and_await_reception_status_async(
579579
s2_msg, timeout_reception_status, raise_on_error
580580
),
581581
self._eventloop,

0 commit comments

Comments
 (0)