class EnumValidator(JsonValidator):
def __init__(self, attribute: str, enum: Iterable[str]):
- super().__init__(f"{attribute} attribute must be one of the following values: " f"{', '.join(enum)}")
+ super().__init__(f"{attribute} attribute must be one of the following values: {', '.join(enum)}")
Decorate a method on a class to mark it as a JSON validator. Validation
functions should return true if valid, false if not.
self.options = options
self.confirm = ConfirmObject.parse(confirm) # type: ignore[arg-type]
- @JsonValidator(f"options attribute must have between {options_min_length} " f"and {options_max_length} items")
+ @JsonValidator(f"options attribute must have between {options_min_length} and {options_max_length} items")
def _validate_options_length(self) -> bool:
return self.options_min_length <= len(self.options) <= self.options_max_length
diff --git a/docs/reference/models/blocks/index.html b/docs/reference/models/blocks/index.html
index d6cae1dbc..b9f0e76d8 100644
--- a/docs/reference/models/blocks/index.html
+++ b/docs/reference/models/blocks/index.html
@@ -5414,7 +5414,7 @@
Inherited members
self.options = options
self.confirm = ConfirmObject.parse(confirm) # type: ignore[arg-type]
- @JsonValidator(f"options attribute must have between {options_min_length} " f"and {options_max_length} items")
+ @JsonValidator(f"options attribute must have between {options_min_length} and {options_max_length} items")
def _validate_options_length(self) -> bool:
return self.options_min_length <= len(self.options) <= self.options_max_length
diff --git a/docs/reference/models/index.html b/docs/reference/models/index.html
index dd6a05957..6fa4aeb15 100644
--- a/docs/reference/models/index.html
+++ b/docs/reference/models/index.html
@@ -183,7 +183,7 @@
Subclasses
class EnumValidator(JsonValidator):
def __init__(self, attribute: str, enum: Iterable[str]):
- super().__init__(f"{attribute} attribute must be one of the following values: " f"{', '.join(enum)}")
+ super().__init__(f"{attribute} attribute must be one of the following values: {', '.join(enum)}")
Decorate a method on a class to mark it as a JSON validator. Validation
functions should return true if valid, false if not.
if self.logger.level <= logging.DEBUG:
self.logger.debug(f"on_close invoked (session id: {self.session_id()})")
if self.auto_reconnect_enabled:
- self.logger.info("Received CLOSE event. Going to reconnect... " f"(session id: {self.session_id()})")
+ self.logger.info(f"Received CLOSE event. Going to reconnect... (session id: {self.session_id()})")
self.connect_to_new_endpoint()
for listener in self.on_close_listeners:
listener(code, reason)
@@ -403,14 +403,12 @@
Classes
if self.current_session is not None and self.current_session.is_active():
session_id = self.session_id()
try:
- self.logger.info("Starting to receive messages from a new connection" f" (session id: {session_id})")
+ self.logger.info(f"Starting to receive messages from a new connection (session id: {session_id})")
self.current_session_state.terminated = False
self.current_session.run_until_completion(self.current_session_state)
- self.logger.info("Stopped receiving messages from a connection" f" (session id: {session_id})")
+ self.logger.info(f"Stopped receiving messages from a connection (session id: {session_id})")
except Exception as e:
- self.logger.exception(
- "Failed to start or stop the current session" f" (session id: {session_id}, error: {e})"
- )
+ self.logger.exception(f"Failed to start or stop the current session (session id: {session_id}, error: {e})")
def _monitor_current_session(self):
if self.current_app_monitor_started:
@@ -419,7 +417,7 @@
Classes
if self.auto_reconnect_enabled and (self.current_session is None or not self.current_session.is_active()):
self.logger.info(
- "The session seems to be already closed. Going to reconnect... " f"(session id: {self.session_id()})"
+ f"The session seems to be already closed. Going to reconnect... (session id: {self.session_id()})"
)
self.connect_to_new_endpoint()
except Exception as e:
@@ -800,7 +798,7 @@
Methods
if self.logger.level <= logging.DEBUG:
self.logger.debug(f"on_close invoked (session id: {self.session_id()})")
if self.auto_reconnect_enabled:
- self.logger.info("Received CLOSE event. Going to reconnect... " f"(session id: {self.session_id()})")
+ self.logger.info(f"Received CLOSE event. Going to reconnect... (session id: {self.session_id()})")
self.connect_to_new_endpoint()
for listener in self.on_close_listeners:
listener(code, reason)
@@ -817,7 +815,7 @@
if self.logger.level <= logging.DEBUG:
self.logger.debug(f"on_close invoked (session id: {self.session_id()})")
if self.auto_reconnect_enabled:
- self.logger.info("Received CLOSE event. Going to reconnect... " f"(session id: {self.session_id()})")
+ self.logger.info(f"Received CLOSE event. Going to reconnect... (session id: {self.session_id()})")
self.connect_to_new_endpoint()
for listener in self.on_close_listeners:
listener(code, reason)
@@ -404,14 +404,12 @@
Classes
if self.current_session is not None and self.current_session.is_active():
session_id = self.session_id()
try:
- self.logger.info("Starting to receive messages from a new connection" f" (session id: {session_id})")
+ self.logger.info(f"Starting to receive messages from a new connection (session id: {session_id})")
self.current_session_state.terminated = False
self.current_session.run_until_completion(self.current_session_state)
- self.logger.info("Stopped receiving messages from a connection" f" (session id: {session_id})")
+ self.logger.info(f"Stopped receiving messages from a connection (session id: {session_id})")
except Exception as e:
- self.logger.exception(
- "Failed to start or stop the current session" f" (session id: {session_id}, error: {e})"
- )
+ self.logger.exception(f"Failed to start or stop the current session (session id: {session_id}, error: {e})")
def _monitor_current_session(self):
if self.current_app_monitor_started:
@@ -420,7 +418,7 @@
Classes
if self.auto_reconnect_enabled and (self.current_session is None or not self.current_session.is_active()):
self.logger.info(
- "The session seems to be already closed. Going to reconnect... " f"(session id: {self.session_id()})"
+ f"The session seems to be already closed. Going to reconnect... (session id: {self.session_id()})"
)
self.connect_to_new_endpoint()
except Exception as e:
@@ -801,7 +799,7 @@
Methods
if self.logger.level <= logging.DEBUG:
self.logger.debug(f"on_close invoked (session id: {self.session_id()})")
if self.auto_reconnect_enabled:
- self.logger.info("Received CLOSE event. Going to reconnect... " f"(session id: {self.session_id()})")
+ self.logger.info(f"Received CLOSE event. Going to reconnect... (session id: {self.session_id()})")
self.connect_to_new_endpoint()
for listener in self.on_close_listeners:
listener(code, reason)
@@ -818,7 +816,7 @@
# a new monitor and a new message receiver are also created.
# If a new session is created but we failed to create the new
# monitor or the new message, we should try it.
- while True:
+ while not self.closed:
try:
old_session: Optional[ClientWebSocketResponse] = (
None if self.current_session is None else self.current_session
@@ -438,6 +438,10 @@
Classes
self.logger.debug(f"A new receive_messages() executor has been recreated for {session_id}")
break
except Exception as e:
+ if self.closed:
+ if self.logger.level <= logging.DEBUG:
+ self.logger.debug(f"Stopped connecting because the client is closed (error: {e})")
+ return
self.logger.exception(f"Failed to connect (error: {e}); Retrying...")
await asyncio.sleep(self.ping_interval)
@@ -468,9 +472,7 @@
Classes
if await self.is_connected():
await self.current_session.send_str(message) # type: ignore[union-attr]
else:
- self.logger.warning(
- f"The current session ({session_id}) is no longer active. " "Failed to send a message"
- )
+ self.logger.warning(f"The current session ({session_id}) is no longer active. Failed to send a message")
raise e
finally:
if self.connect_operation_lock.locked() is True:
@@ -624,7 +626,7 @@
Methods
# a new monitor and a new message receiver are also created.
# If a new session is created but we failed to create the new
# monitor or the new message, we should try it.
- while True:
+ while not self.closed:
try:
old_session: Optional[ClientWebSocketResponse] = (
None if self.current_session is None else self.current_session
@@ -680,6 +682,10 @@
Methods
self.logger.debug(f"A new receive_messages() executor has been recreated for {session_id}")
break
except Exception as e:
+ if self.closed:
+ if self.logger.level <= logging.DEBUG:
+ self.logger.debug(f"Stopped connecting because the client is closed (error: {e})")
+ return
self.logger.exception(f"Failed to connect (error: {e}); Retrying...")
await asyncio.sleep(self.ping_interval)
@@ -975,9 +981,7 @@
Methods
if await self.is_connected():
await self.current_session.send_str(message) # type: ignore[union-attr]
else:
- self.logger.warning(
- f"The current session ({session_id}) is no longer active. " "Failed to send a message"
- )
+ self.logger.warning(f"The current session ({session_id}) is no longer active. Failed to send a message")
raise e
finally:
if self.connect_operation_lock.locked() is True:
diff --git a/docs/reference/socket_mode/async_client.html b/docs/reference/socket_mode/async_client.html
index 2dba67f84..e8f70035d 100644
--- a/docs/reference/socket_mode/async_client.html
+++ b/docs/reference/socket_mode/async_client.html
@@ -206,10 +206,7 @@
if self.logger.level <= logging.DEBUG:
self.logger.debug(f"on_close invoked (session id: {self.session_id()})")
if self.auto_reconnect_enabled:
- self.logger.info("Received CLOSE event. Reconnecting... " f"(session id: {self.session_id()})")
+ self.logger.info(f"Received CLOSE event. Reconnecting... (session id: {self.session_id()})")
self.connect_to_new_endpoint()
for listener in self.on_close_listeners:
listener(code, reason)
@@ -297,12 +297,12 @@
Classes
if self.current_session is not None and self.current_session.is_active():
session_id = self.session_id()
try:
- self.logger.info("Starting to receive messages from a new connection" f" (session id: {session_id})")
+ self.logger.info(f"Starting to receive messages from a new connection (session id: {session_id})")
self.current_session_state.terminated = False
self.current_session.run_until_completion(self.current_session_state)
- self.logger.info("Stopped receiving messages from a connection" f" (session id: {session_id})")
+ self.logger.info(f"Stopped receiving messages from a connection (session id: {session_id})")
except Exception as e:
- error_message = "Failed to start or stop the current session" f" (session id: {session_id}, error: {e})"
+ error_message = f"Failed to start or stop the current session (session id: {session_id}, error: {e})"
if self.trace_enabled:
self.logger.exception(error_message)
else:
@@ -315,7 +315,7 @@
Classes
if self.auto_reconnect_enabled and (self.current_session is None or not self.current_session.is_active()):
self.logger.info(
- "The session seems to be already closed. Reconnecting... " f"(session id: {self.session_id()})"
+ f"The session seems to be already closed. Reconnecting... (session id: {self.session_id()})"
)
self.connect_to_new_endpoint()
except Exception as e:
diff --git a/docs/reference/socket_mode/builtin/connection.html b/docs/reference/socket_mode/builtin/connection.html
index 5c85bef91..208e9a591 100644
--- a/docs/reference/socket_mode/builtin/connection.html
+++ b/docs/reference/socket_mode/builtin/connection.html
@@ -126,7 +126,7 @@
Classes
port: int = parsed_url.port or (443 if parsed_url.scheme == "wss" else 80)
if self.trace_enabled:
self.logger.debug(
- f"Connecting to the address for handshake: {hostname}:{port} " f"(session id: {self.session_id})"
+ f"Connecting to the address for handshake: {hostname}:{port} (session id: {self.session_id})"
)
sock: Union[ssl.SSLSocket, socket] = _establish_new_socket_connection( # type: ignore[valid-type]
session_id=self.session_id,
@@ -228,7 +228,7 @@
Classes
if self.trace_enabled and self.ping_pong_trace_enabled:
if isinstance(payload, bytes):
payload = payload.decode("utf-8")
- self.logger.debug("Sending a ping data frame " f"(session id: {self.session_id}, payload: {payload})")
+ self.logger.debug(f"Sending a ping data frame (session id: {self.session_id}, payload: {payload})")
data = _build_data_frame_for_sending(payload, FrameHeader.OPCODE_PING)
with self.sock_send_lock:
if self.sock is not None:
@@ -241,7 +241,7 @@
Classes
if self.trace_enabled and self.ping_pong_trace_enabled:
if isinstance(payload, bytes):
payload = payload.decode("utf-8")
- self.logger.debug("Sending a pong data frame " f"(session id: {self.session_id}, payload: {payload})")
+ self.logger.debug(f"Sending a pong data frame (session id: {self.session_id}, payload: {payload})")
data = _build_data_frame_for_sending(payload, FrameHeader.OPCODE_PONG)
with self.sock_send_lock:
if self.sock is not None:
@@ -254,7 +254,7 @@
Classes
if self.trace_enabled:
if isinstance(payload, bytes):
payload = payload.decode("utf-8")
- self.logger.debug("Sending a text data frame " f"(session id: {self.session_id}, payload: {payload})")
+ self.logger.debug(f"Sending a text data frame (session id: {self.session_id}, payload: {payload})")
data = _build_data_frame_for_sending(payload, FrameHeader.OPCODE_TEXT)
with self.sock_send_lock:
try:
@@ -302,12 +302,11 @@
Classes
self.disconnect()
return
else:
- self.logger.debug("This connection is already closed." f" (session id: {self.session_id})")
+ self.logger.debug(f"This connection is already closed. (session id: {self.session_id})")
self.consecutive_check_state_error_count = 0
except Exception as e:
error_message = (
- "Failed to check the state of sock "
- f"(session id: {self.session_id}, error: {type(e).__name__}, message: {e})"
+ f"Failed to check the state of sock (session id: {self.session_id}, error: {type(e).__name__}, message: {e})"
)
if self.trace_enabled:
self.logger.exception(error_message)
@@ -399,7 +398,7 @@
Classes
self.last_ping_pong_time = float(ping_time)
except Exception as e:
self.logger.debug(
- "Failed to parse a pong message " f" (message: {str_message}, error: {e}"
+ f"Failed to parse a pong message (message: {str_message}, error: {e}"
)
elif header.opcode == FrameHeader.OPCODE_TEXT:
if self.on_message_listener is not None:
@@ -437,13 +436,13 @@
Classes
# getting errno.EBADF and the socket is no longer available
if e.errno == 9 and state.terminated:
self.logger.debug(
- "The reason why you got [Errno 9] Bad file descriptor here is " "the socket is no longer available."
+ "The reason why you got [Errno 9] Bad file descriptor here is the socket is no longer available."
)
else:
if self.on_error_listener is not None:
self.on_error_listener(e)
else:
- error_message = "Got an OSError while receiving data" f" (session id: {self.session_id}, error: {e})"
+ error_message = f"Got an OSError while receiving data (session id: {self.session_id}, error: {e})"
if self.trace_enabled:
self.logger.exception(error_message)
else:
@@ -454,9 +453,7 @@
if self.on_error_listener is not None:
self.on_error_listener(e)
else:
- error_message = "Got an exception while receiving data" f" (session id: {self.session_id}, error: {e})"
+ error_message = f"Got an exception while receiving data (session id: {self.session_id}, error: {e})"
if self.trace_enabled:
self.logger.exception(error_message)
else:
@@ -570,12 +567,11 @@
Methods
self.disconnect()
return
else:
- self.logger.debug("This connection is already closed." f" (session id: {self.session_id})")
+ self.logger.debug(f"This connection is already closed. (session id: {self.session_id})")
self.consecutive_check_state_error_count = 0
except Exception as e:
error_message = (
- "Failed to check the state of sock "
- f"(session id: {self.session_id}, error: {type(e).__name__}, message: {e})"
+ f"Failed to check the state of sock (session id: {self.session_id}, error: {type(e).__name__}, message: {e})"
)
if self.trace_enabled:
self.logger.exception(error_message)
@@ -616,7 +612,7 @@
Methods
port: int = parsed_url.port or (443 if parsed_url.scheme == "wss" else 80)
if self.trace_enabled:
self.logger.debug(
- f"Connecting to the address for handshake: {hostname}:{port} " f"(session id: {self.session_id})"
+ f"Connecting to the address for handshake: {hostname}:{port} (session id: {self.session_id})"
)
sock: Union[ssl.SSLSocket, socket] = _establish_new_socket_connection( # type: ignore[valid-type]
session_id=self.session_id,
@@ -745,7 +741,7 @@
Methods
if self.trace_enabled and self.ping_pong_trace_enabled:
if isinstance(payload, bytes):
payload = payload.decode("utf-8")
- self.logger.debug("Sending a ping data frame " f"(session id: {self.session_id}, payload: {payload})")
+ self.logger.debug(f"Sending a ping data frame (session id: {self.session_id}, payload: {payload})")
data = _build_data_frame_for_sending(payload, FrameHeader.OPCODE_PING)
with self.sock_send_lock:
if self.sock is not None:
@@ -768,7 +764,7 @@
Methods
if self.trace_enabled and self.ping_pong_trace_enabled:
if isinstance(payload, bytes):
payload = payload.decode("utf-8")
- self.logger.debug("Sending a pong data frame " f"(session id: {self.session_id}, payload: {payload})")
+ self.logger.debug(f"Sending a pong data frame (session id: {self.session_id}, payload: {payload})")
data = _build_data_frame_for_sending(payload, FrameHeader.OPCODE_PONG)
with self.sock_send_lock:
if self.sock is not None:
@@ -868,7 +864,7 @@
Methods
self.last_ping_pong_time = float(ping_time)
except Exception as e:
self.logger.debug(
- "Failed to parse a pong message " f" (message: {str_message}, error: {e}"
+ f"Failed to parse a pong message (message: {str_message}, error: {e}"
)
elif header.opcode == FrameHeader.OPCODE_TEXT:
if self.on_message_listener is not None:
@@ -906,13 +902,13 @@
Methods
# getting errno.EBADF and the socket is no longer available
if e.errno == 9 and state.terminated:
self.logger.debug(
- "The reason why you got [Errno 9] Bad file descriptor here is " "the socket is no longer available."
+ "The reason why you got [Errno 9] Bad file descriptor here is the socket is no longer available."
)
else:
if self.on_error_listener is not None:
self.on_error_listener(e)
else:
- error_message = "Got an OSError while receiving data" f" (session id: {self.session_id}, error: {e})"
+ error_message = f"Got an OSError while receiving data (session id: {self.session_id}, error: {e})"
if self.trace_enabled:
self.logger.exception(error_message)
else:
@@ -923,9 +919,7 @@
if self.on_error_listener is not None:
self.on_error_listener(e)
else:
- error_message = "Got an exception while receiving data" f" (session id: {self.session_id}, error: {e})"
+ error_message = f"Got an exception while receiving data (session id: {self.session_id}, error: {e})"
if self.trace_enabled:
self.logger.exception(error_message)
else:
@@ -958,7 +952,7 @@
Methods
if self.trace_enabled:
if isinstance(payload, bytes):
payload = payload.decode("utf-8")
- self.logger.debug("Sending a text data frame " f"(session id: {self.session_id}, payload: {payload})")
+ self.logger.debug(f"Sending a text data frame (session id: {self.session_id}, payload: {payload})")
data = _build_data_frame_for_sending(payload, FrameHeader.OPCODE_TEXT)
with self.sock_send_lock:
try:
diff --git a/docs/reference/socket_mode/builtin/index.html b/docs/reference/socket_mode/builtin/index.html
index b24db1c9b..ce295e515 100644
--- a/docs/reference/socket_mode/builtin/index.html
+++ b/docs/reference/socket_mode/builtin/index.html
@@ -288,7 +288,7 @@
if self.logger.level <= logging.DEBUG:
self.logger.debug(f"on_close invoked (session id: {self.session_id()})")
if self.auto_reconnect_enabled:
- self.logger.info("Received CLOSE event. Reconnecting... " f"(session id: {self.session_id()})")
+ self.logger.info(f"Received CLOSE event. Reconnecting... (session id: {self.session_id()})")
self.connect_to_new_endpoint()
for listener in self.on_close_listeners:
listener(code, reason)
@@ -311,12 +311,12 @@
Classes
if self.current_session is not None and self.current_session.is_active():
session_id = self.session_id()
try:
- self.logger.info("Starting to receive messages from a new connection" f" (session id: {session_id})")
+ self.logger.info(f"Starting to receive messages from a new connection (session id: {session_id})")
self.current_session_state.terminated = False
self.current_session.run_until_completion(self.current_session_state)
- self.logger.info("Stopped receiving messages from a connection" f" (session id: {session_id})")
+ self.logger.info(f"Stopped receiving messages from a connection (session id: {session_id})")
except Exception as e:
- error_message = "Failed to start or stop the current session" f" (session id: {session_id}, error: {e})"
+ error_message = f"Failed to start or stop the current session (session id: {session_id}, error: {e})"
if self.trace_enabled:
self.logger.exception(error_message)
else:
@@ -329,7 +329,7 @@
Classes
if self.auto_reconnect_enabled and (self.current_session is None or not self.current_session.is_active()):
self.logger.info(
- "The session seems to be already closed. Reconnecting... " f"(session id: {self.session_id()})"
+ f"The session seems to be already closed. Reconnecting... (session id: {self.session_id()})"
)
self.connect_to_new_endpoint()
except Exception as e:
diff --git a/docs/reference/socket_mode/index.html b/docs/reference/socket_mode/index.html
index 1fb84832e..64788cd30 100644
--- a/docs/reference/socket_mode/index.html
+++ b/docs/reference/socket_mode/index.html
@@ -325,7 +325,7 @@
if self.logger.level <= logging.DEBUG:
self.logger.debug(f"on_close invoked (session id: {self.session_id()})")
if self.auto_reconnect_enabled:
- self.logger.info("Received CLOSE event. Reconnecting... " f"(session id: {self.session_id()})")
+ self.logger.info(f"Received CLOSE event. Reconnecting... (session id: {self.session_id()})")
self.connect_to_new_endpoint()
for listener in self.on_close_listeners:
listener(code, reason)
@@ -348,12 +348,12 @@
Classes
if self.current_session is not None and self.current_session.is_active():
session_id = self.session_id()
try:
- self.logger.info("Starting to receive messages from a new connection" f" (session id: {session_id})")
+ self.logger.info(f"Starting to receive messages from a new connection (session id: {session_id})")
self.current_session_state.terminated = False
self.current_session.run_until_completion(self.current_session_state)
- self.logger.info("Stopped receiving messages from a connection" f" (session id: {session_id})")
+ self.logger.info(f"Stopped receiving messages from a connection (session id: {session_id})")
except Exception as e:
- error_message = "Failed to start or stop the current session" f" (session id: {session_id}, error: {e})"
+ error_message = f"Failed to start or stop the current session (session id: {session_id}, error: {e})"
if self.trace_enabled:
self.logger.exception(error_message)
else:
@@ -366,7 +366,7 @@
Classes
if self.auto_reconnect_enabled and (self.current_session is None or not self.current_session.is_active()):
self.logger.info(
- "The session seems to be already closed. Reconnecting... " f"(session id: {self.session_id()})"
+ f"The session seems to be already closed. Reconnecting... (session id: {self.session_id()})"
)
self.connect_to_new_endpoint()
except Exception as e:
diff --git a/docs/reference/web/index.html b/docs/reference/web/index.html
index 8c42b1030..aea748acf 100644
--- a/docs/reference/web/index.html
+++ b/docs/reference/web/index.html
@@ -93,7 +93,7 @@