diff --git a/projects/jupyter-server-ydoc/jupyter_server_ydoc/handlers.py b/projects/jupyter-server-ydoc/jupyter_server_ydoc/handlers.py index 3010904c..e06a8204 100644 --- a/projects/jupyter-server-ydoc/jupyter_server_ydoc/handlers.py +++ b/projects/jupyter-server-ydoc/jupyter_server_ydoc/handlers.py @@ -224,9 +224,7 @@ async def open(self, room_id): self.log.error(f"File {file.path} not found.\n{e!r}", exc_info=e) self.close(1004, f"File {file.path} not found.") else: - self.log.error( - f"Error initializing: {file.path}\n{e!r}", exc_info=e - ) + self.log.error(f"Error initializing: {file.path}\n{e!r}", exc_info=e) self.close( 1003, f"Error initializing: {file.path}. You need to close the document.", @@ -306,14 +304,10 @@ async def on_message(self, message): for client in self.room.clients: if client != self: task = asyncio.create_task( - client.send( - bytes([MessageType.CHAT]) + write_var_uint(len(data)) + data - ) + client.send(bytes([MessageType.CHAT]) + write_var_uint(len(data)) + data) ) self._websocket_server.background_tasks.add(task) - task.add_done_callback( - self._websocket_server.background_tasks.discard - ) + task.add_done_callback(self._websocket_server.background_tasks.discard) self._message_queue.put_nowait(message) self._websocket_server.ypatch_nb += 1 @@ -332,9 +326,7 @@ def on_close(self) -> None: if self._room_id != "JupyterLab:globalAwareness": self._emit_awareness_event(self.current_user.username, "leave") - def _emit( - self, level: LogLevel, action: str | None = None, msg: str | None = None - ) -> None: + def _emit(self, level: LogLevel, action: str | None = None, msg: str | None = None) -> None: _, _, file_id = decode_file_path(self._room_id) path = self._file_id_manager.get_path(file_id) @@ -346,16 +338,12 @@ def _emit( self.event_logger.emit(schema_id=JUPYTER_COLLABORATION_EVENTS_URI, data=data) - def _emit_awareness_event( - self, username: str, action: str, msg: str | None = None - ) -> None: + def _emit_awareness_event(self, username: str, action: str, msg: str | None = None) -> None: data = {"roomid": self._room_id, "username": username, "action": action} if msg: data["msg"] = msg - self.event_logger.emit( - schema_id=JUPYTER_COLLABORATION_AWARENESS_EVENTS_URI, data=data - ) + self.event_logger.emit(schema_id=JUPYTER_COLLABORATION_AWARENESS_EVENTS_URI, data=data) async def _clean_room(self) -> None: """ diff --git a/projects/jupyter-server-ydoc/jupyter_server_ydoc/rooms.py b/projects/jupyter-server-ydoc/jupyter_server_ydoc/rooms.py index 55dccad7..7b5e5ca1 100644 --- a/projects/jupyter-server-ydoc/jupyter_server_ydoc/rooms.py +++ b/projects/jupyter-server-ydoc/jupyter_server_ydoc/rooms.py @@ -150,9 +150,7 @@ async def initialize(self) -> None: self.ready = True self._emit(LogLevel.INFO, "initialize", "Room initialized") - def _emit( - self, level: LogLevel, action: str | None = None, msg: str | None = None - ) -> None: + def _emit(self, level: LogLevel, action: str | None = None, msg: str | None = None) -> None: data = {"level": level.value, "room": self._room_id, "path": self._file.path} if action: data["action"] = action @@ -186,12 +184,8 @@ async def _on_outofband_change(self) -> None: """ Called when the file got out-of-band changes. """ - self.log.info( - "Out-of-band changes. Overwriting the content in room %s", self._room_id - ) - self._emit( - LogLevel.INFO, "overwrite", "Out-of-band changes. Overwriting the room." - ) + self.log.info("Out-of-band changes. Overwriting the content in room %s", self._room_id) + self._emit(LogLevel.INFO, "overwrite", "Out-of-band changes. Overwriting the room.") try: model = await self._file.load_content(self._file_format, self._file_type) @@ -267,13 +261,9 @@ async def _maybe_save_document(self, saving_document: asyncio.Task | None) -> No return except OutOfBandChanges: - self.log.info( - "Out-of-band changes. Overwriting the content in room %s", self._room_id - ) + self.log.info("Out-of-band changes. Overwriting the content in room %s", self._room_id) try: - model = await self._file.load_content( - self._file_format, self._file_type - ) + model = await self._file.load_content(self._file_format, self._file_type) except Exception as e: msg = f"Error loading content from file: {self._file.path}\n{e!r}" self.log.error(msg, exc_info=e)