Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
emptyMessage: "No sessions available"
});
const gatewayOptions = Object.assign(
{
xhrFactory: () => new xhr.XMLHttpRequest(),
wsFactory: (url, protocol) => new ws(url, protocol)
},
gatewayInfo.options
);
let serverSettings = ServerConnection.makeSettings(gatewayOptions);
let specModels;
try {
specModels = await Kernel.getSpecs(serverSettings);
} catch (error) {
// The error types you get back at this stage are fairly opaque. In
// particular, having invalid credentials typically triggers ECONNREFUSED
// rather than 403 Forbidden. This does some basic checks and then assumes
// that all remaining error types could be caused by invalid credentials.
if (!error.xhr || !error.xhr.responseText) {
throw error;
} else if (error.xhr.responseText.includes("ETIMEDOUT")) {
atom.notifications.addError("Connection to gateway failed");
this.listView.cancel();
return;
} else {
const promptSucceeded = await this.promptForCredentials(gatewayOptions);
if (!promptSucceeded) {
return;
}
it('should omit an invalid kernelspec', async () => {
const R_SPEC = JSON.parse(JSON.stringify(PYTHON_SPEC));
R_SPEC.name = 1;
const serverSettings = getRequestHandler(200, {
default: 'python',
kernelspecs: {
R: R_SPEC,
python: PYTHON_SPEC
}
});
const specs = await Kernel.getSpecs(serverSettings);
expect(specs.default).to.equal('python');
expect(specs.kernelspecs['R']).to.be.undefined;
});
it('should handle a missing default parameter', async () => {
const serverSettings = getRequestHandler(200, {
kernelspecs: { python: PYTHON_SPEC }
});
const specs = await Kernel.getSpecs(serverSettings);
expect(specs.default).to.be.ok;
});
it('should load the kernelspecs', async () => {
const specs = await Kernel.getSpecs();
expect(specs.default).to.be.ok;
});
it('should accept ajax options', async () => {
const serverSettings = makeSettings();
const specs = await Kernel.getSpecs(serverSettings);
expect(specs.default).to.be.ok;
});
it('should handle an improper display_name', async () => {
const R_SPEC = JSON.parse(JSON.stringify(PYTHON_SPEC));
R_SPEC.spec.display_name = ['hello'];
const serverSettings = getRequestHandler(200, {
default: 'R',
kernelspecs: { R: R_SPEC }
});
const promise = Kernel.getSpecs(serverSettings);
await expectFailure(promise, 'No valid kernelspecs found');
});
it('should load the kernelspecs', async () => {
const specs = await Kernel.getSpecs();
expect(specs.default).to.be.ok;
});
it('should handle an improper language', async () => {
const R_SPEC = JSON.parse(JSON.stringify(PYTHON_SPEC));
R_SPEC.spec.language = 1;
const serverSettings = getRequestHandler(200, {
default: 'R',
kernelspecs: { R: R_SPEC }
});
const promise = Kernel.getSpecs(serverSettings);
await expectFailure(promise, 'No valid kernelspecs found');
});
it('should handle a missing default parameter', async () => {
const serverSettings = getRequestHandler(200, {
kernelspecs: { python: PYTHON_SPEC }
});
const specs = await Kernel.getSpecs(serverSettings);
expect(specs.default).to.be.ok;
});
async renderWidgets() {
let connectionInfo = ServerConnection.makeSettings({
baseUrl : this._baseUrl,
wsUrl : this._wsUrl
});
const kernelSpecs = await Kernel.getSpecs(connectionInfo)
console.log(`Starting kernel ${kernelSpecs.default}`)
const kernel = await Kernel.startNew({
name: kernelSpecs.default,
serverSettings: connectionInfo
});
this._kernel = kernel;
const el = document.getElementById('ipywidget-server-result')
const manager = new WidgetManager(kernel, el, this._loader);
const errorEl = document.getElementById('ipywidget-server-errors')
const errorView = new ErrorView(errorEl);
manager.onError.connect((sender, msg) => errorView.showError(msg.content))