Skip to content

Commit

Permalink
Runs pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hbcarlos committed Feb 23, 2023
1 parent f82b680 commit a7bb5da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
11 changes: 6 additions & 5 deletions jupyter_collaboration/handlers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

import uuid
import asyncio
import json
import uuid
from logging import Logger
from pathlib import Path
from typing import Any, Dict, Optional, Set, Tuple
Expand All @@ -27,6 +27,7 @@

DOCUMENT_SESSION = str(uuid.uuid4())


class TempFileYStore(_TempFileYStore):
prefix_dir = "jupyter_ystore_"

Expand Down Expand Up @@ -202,9 +203,9 @@ async def open(self, path):
task = asyncio.create_task(self.websocket_server.serve(self))
self.websocket_server.background_tasks.add(task)
task.add_done_callback(self.websocket_server.background_tasks.discard)

# Close the connection if the document session expired
session = self.get_query_argument('session', "")
session = self.get_query_argument("session", "")
if isinstance(self.room, DocumentRoom) and not DOCUMENT_SESSION == session:
self.close(1, "Document session expired")

Expand Down Expand Up @@ -400,7 +401,7 @@ async def put(self, path):
# index already exists
self.set_status(200)
self.log.info("Request for Y document '%s' with room ID: %s", path, idx)
data = json.dumps({ 'file_id': idx, 'session': DOCUMENT_SESSION })
data = json.dumps({"file_id": idx, "session": DOCUMENT_SESSION})
return self.finish(data)

# try indexing
Expand All @@ -412,5 +413,5 @@ async def put(self, path):
# index successfully created
self.set_status(201)
self.log.info("Request for Y document '%s' with room ID: %s", path, idx)
data = json.dumps({ 'file_id': idx, 'session': DOCUMENT_SESSION })
data = json.dumps({"file_id": idx, "session": DOCUMENT_SESSION})
return self.finish(data)
18 changes: 11 additions & 7 deletions packages/docprovider/src/yprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ export class WebSocketProvider implements IDocumentProvider {
}
);

this._yWebsocketProvider.on('connection-close', this._onConnectionClosed);
this._yWebsocketProvider.on(
'connection-close',
this._onConnectionClosed
);
})
.then(() => this._ready.resolve())
.catch(reason => console.warn(reason));
Expand Down Expand Up @@ -126,15 +129,16 @@ export class WebSocketProvider implements IDocumentProvider {
}

private _onConnectionClosed(event: any): void {
if (event.code == 1) {
console.error("Document provider closed:", event.reason);
if (event.code === 1) {
console.error('Document provider closed:', event.reason);

showErrorMessage(
"Session expired",
"The document session expired. We need to reload this browser tab.",
'Session expired',
'The document session expired. We need to reload this browser tab.',
[Dialog.okButton()]
).then(r => window.location.reload())
.catch(e => window.location.reload());
)
.then(r => window.location.reload())
.catch(e => window.location.reload());
// Dispose shared model immediately. Better break the document model,
// than overriding data on disk
this._sharedModel.dispose();
Expand Down

0 comments on commit a7bb5da

Please sign in to comment.