當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript services.ServerConnection類代碼示例

本文整理匯總了TypeScript中@jupyterlab/services.ServerConnection的典型用法代碼示例。如果您正苦於以下問題:TypeScript ServerConnection類的具體用法?TypeScript ServerConnection怎麽用?TypeScript ServerConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ServerConnection類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: showDialog

 }).then(result => {
   if (result.button.accept) {
     let setting = ServerConnection.makeSettings();
     let apiURL = URLExt.join(setting.baseUrl, 'api/shutdown');
     ServerConnection.makeRequest(apiURL, { method: 'POST' }, setting)
       .then(result => {
         if (result.ok) {
           // Close this window if the shutdown request has been successful
           let body = document.createElement('div');
           body.innerHTML = `<p>You have shut down the Jupyter server. You can now close this tab.</p>
             <p>To use JupyterLab again, you will need to relaunch it.</p>`;
           showDialog({
             title: 'Server stopped',
             body: new Widget({ node: body }),
             buttons: []
           });
           window.close();
         } else {
           throw new ServerConnection.ResponseError(result);
         }
       })
       .catch(data => {
         throw new ServerConnection.NetworkError(data);
       });
   }
 });
開發者ID:SylvainCorlay,項目名稱:jupyterlab,代碼行數:26,代碼來源:index.ts

示例2: requestJsonPromise

function requestJsonPromise(url: string, argument: any): Promise<JSONObject> {
  let request = {
      method: 'POST',
      body: JSON.stringify(argument),
    };
  let settings = ServerConnection.makeSettings();
  return ServerConnection.makeRequest(url, request, settings)
    .then(handleError)
    .then((response) => {
      return response.json();
    });
}
開發者ID:vidartf,項目名稱:nbdime,代碼行數:12,代碼來源:index.ts

示例3: describe

  describe('#getDownloadUrl()', () => {
    const settings = ServerConnection.makeSettings({
      baseUrl: 'http://foo'
    });

    it('should get the url of a file', async () => {
      const drive = new Drive({ serverSettings: settings });
      const test1 = drive.getDownloadUrl('bar.txt');
      const test2 = drive.getDownloadUrl('fizz/buzz/bar.txt');
      const test3 = drive.getDownloadUrl('/bar.txt');
      const urls = await Promise.all([test1, test2, test3]);
      expect(urls[0]).to.equal('http://foo/files/bar.txt');
      expect(urls[1]).to.equal('http://foo/files/fizz/buzz/bar.txt');
      expect(urls[2]).to.equal('http://foo/files/bar.txt');
    });

    it('should encode characters', async () => {
      const drive = new Drive({ serverSettings: settings });
      const url = await drive.getDownloadUrl('b ar?3.txt');
      expect(url).to.equal('http://foo/files/b%20ar%3F3.txt');
    });

    it('should not handle relative paths', async () => {
      const drive = new Drive({ serverSettings: settings });
      const url = await drive.getDownloadUrl('fizz/../bar.txt');
      expect(url).to.equal('http://foo/files/fizz/../bar.txt');
    });
  });
開發者ID:afshin,項目名稱:jupyterlab,代碼行數:28,代碼來源:index.spec.ts

示例4: it

 it('should use baseUrl for wsUrl', () => {
   const conf: Partial<ServerConnection.ISettings> = {
     baseUrl: 'https://host/path'
   };
   const settings = ServerConnection.makeSettings(conf);
   expect(settings.baseUrl).to.equal(conf.baseUrl);
   expect(settings.wsUrl).to.equal('wss://host/path');
 });
開發者ID:afshin,項目名稱:jupyterlab,代碼行數:8,代碼來源:serverconnection.spec.ts

示例5: isNbInGit

function isNbInGit(args: {readonly path: string}): Promise<boolean> {
  let request = {
      method: 'POST',
      body: JSON.stringify(args),
    };
  let settings = ServerConnection.makeSettings();
  return ServerConnection.makeRequest(
    URLExt.join(urlRStrip(settings.baseUrl), '/nbdime/api/isgit'),
    request, settings).then((response) => {
      if (!response.ok) {
        return Promise.reject(response);
      }
      return response.json() as Promise<IApiResponse>;
    }).then((data) => {
      return data['is_git'];
    });
}
開發者ID:vidartf,項目名稱:nbdime,代碼行數:17,代碼來源:actions.ts

示例6: getStoredSettings

 getStoredSettings(): Promise<any> {
   return ServerConnection.makeRequest(
     this.settingsUrl,
     { method: 'GET' },
     this.serverSettings
   )
     .then(response => response.json())
     .catch(reason => { console.log(reason); });
 }
開發者ID:twosigma,項目名稱:beaker-notebook,代碼行數:9,代碼來源:gistPublishModal.ts

示例7:

 .then(storedSettings => {
   storedSettings.beakerx.githubPersonalAccessToken = githubPersonalAccessToken;
   return ServerConnection.makeRequest(
     this.settingsUrl,
     {
       method: 'POST',
       body: JSON.stringify({
         ...storedSettings
       })
     },
     this.serverSettings
   ).catch(reason => { console.log(reason); })
 });
開發者ID:twosigma,項目名稱:beaker-notebook,代碼行數:13,代碼來源:gistPublishModal.ts

示例8: function

document.addEventListener('DOMContentLoaded', function(event) {

    // Connect to the notebook webserver.
    let connectionInfo = ServerConnection.makeSettings({
        baseUrl: BASEURL,
        wsUrl: WSURL
    });
    Kernel.getSpecs(connectionInfo).then(kernelSpecs => {
        return Kernel.startNew({
            name: kernelSpecs.default,
            serverSettings: connectionInfo
        });
    }).then(kernel => {

        // Create a codemirror instance
        let code = require('../widget_code.json').join('\n');
        let inputarea = document.getElementsByClassName('inputarea')[0] as HTMLElement;
        let editor = CodeMirror(inputarea, {
            value: code,
            mode: 'python',
            tabSize: 4,
            showCursorWhenSelecting: true,
            viewportMargin: Infinity,
            readOnly: true
        });

        // Create the widget area and widget manager
        let widgetarea = document.getElementsByClassName('widgetarea')[0] as HTMLElement;
        let manager = new WidgetManager(kernel, widgetarea);

        // Run backend code to create the widgets.  You could also create the
        // widgets in the frontend, like the other widget examples demonstrate.
        let execution = kernel.requestExecute({ code: code });
        execution.onIOPub = (msg) => {
            // If we have a display message, display the widget.
            if (KernelMessage.isDisplayDataMsg(msg)) {
                let widgetData: any = msg.content.data['application/vnd.jupyter.widget-view+json'];
                if (widgetData !== undefined && widgetData.version_major === 2) {
                    let model = manager.get_model(widgetData.model_id);
                    if (model !== undefined) {
                        model.then(model => {
                            manager.display_model(msg, model);
                        });
                    }
                }
            }
        };
    });
});
開發者ID:SylvainCorlay,項目名稱:ipywidgets,代碼行數:49,代碼來源:index.ts


注:本文中的@jupyterlab/services.ServerConnection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。