本文整理汇总了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);
});
}
});
示例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();
});
}
示例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');
});
});
示例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');
});
示例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'];
});
}
示例6: getStoredSettings
getStoredSettings(): Promise<any> {
return ServerConnection.makeRequest(
this.settingsUrl,
{ method: 'GET' },
this.serverSettings
)
.then(response => response.json())
.catch(reason => { console.log(reason); });
}
示例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); })
});
示例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);
});
}
}
}
};
});
});