KevinGG commented on a change in pull request #12372:
URL: https://github.com/apache/beam/pull/12372#discussion_r463183798



##########
File path: 
sdks/python/apache_beam/runners/interactive/extensions/apache-beam-jupyterlab-sidepanel/src/kernel/KernelModel.ts
##########
@@ -0,0 +1,161 @@
+// Licensed under the Apache License, Version 2.0 (the 'License'); you may not
+// use this file except in compliance with the License. You may obtain a copy 
of
+// the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations 
under
+// the License.
+
+/**
+ * The module holds the model that handles messaging between the frontend and
+ * the connected kernel.
+ */
+
+import { ISessionContext } from '@jupyterlab/apputils';
+
+import {
+  IDisplayData,
+  IDisplayUpdate,
+  IExecuteResult
+} from '@jupyterlab/nbformat';
+
+import { Kernel, KernelMessage } from '@jupyterlab/services';
+
+import { ISignal, Signal } from '@lumino/signaling';
+
+import { KernelCode } from '../kernel/KernelCode';
+
+export class KernelModel {
+  constructor(sessionContext: ISessionContext, enableConsoleLog = false) {
+    this._sessionContext = sessionContext;
+    this._enableConsoleLog = enableConsoleLog;
+  }
+
+  get future(): Kernel.IFuture<
+    KernelMessage.IExecuteRequestMsg,
+    KernelMessage.IExecuteReplyMsg
+  > | null {
+    return this._future;
+  }
+
+  set future(
+    value: Kernel.IFuture<
+      KernelMessage.IExecuteRequestMsg,
+      KernelMessage.IExecuteReplyMsg
+    > | null
+  ) {
+    if (this._future === value) {
+      return;
+    }
+
+    if (this._future) {
+      this._future.dispose();
+    }
+
+    this._future = value;
+
+    if (!value) {
+      return;
+    }
+
+    value.onIOPub = this._onIOPub.bind(this);
+  }
+
+  get executeResult(): object {
+    if (this._executeResult) {
+      const dataInPlainText = this._executeResult.data['text/plain'] as string;
+      if (dataInPlainText) {
+        try {
+          // The slice removes trailing single quotes from the nbformat output.
+          // The replace removes literal backslashes from the nbformat output.

Review comment:
       It's removing characters in nbformat texts.
   
   Kernel generates json.
   When messaged to frontend by Jupyter in nbformat, the text becomes 
'json_with_backslashes'.
   
   This removes the "'" from both ends of the string.
   Then removes all the backlashes.
   
   The result text will be a valid json that is parsable.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to