forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjupyterHelpers.ts
More file actions
29 lines (24 loc) · 1.08 KB
/
jupyterHelpers.ts
File metadata and controls
29 lines (24 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
// IP = * format is a bit different from localhost format
export function getIPConnectionInfo(output: string): string | undefined {
// String format: http://(NAME or IP):PORT/
const nameAndPortRegEx = /(https?):\/\/\(([^\s]*) or [0-9.]*\):([0-9]*)\/(?:\?token=)?([a-zA-Z0-9]*)?/;
const urlMatch = nameAndPortRegEx.exec(output);
if (urlMatch && !urlMatch[4]) {
return `${urlMatch[1]}://${urlMatch[2]}:${urlMatch[3]}/`;
} else if (urlMatch && urlMatch.length === 5) {
return `${urlMatch[1]}://${urlMatch[2]}:${urlMatch[3]}/?token=${urlMatch[4]}`;
}
// In Notebook 6.0 instead of the above format it returns a single valid web address so just return that
return getConnectionInfo(output);
}
export function getConnectionInfo(output: string): string | undefined {
const UrlPatternRegEx = /(https?:\/\/[^\s]+)/;
const urlMatch = UrlPatternRegEx.exec(output);
if (urlMatch) {
return urlMatch[0];
}
return undefined;
}