From 2ff093f583bd82f342541bb8536f95bec9a36e78 Mon Sep 17 00:00:00 2001 From: "Nikita.Ashihmin" Date: Fri, 29 Nov 2024 22:57:55 +0400 Subject: [PATCH] PY-77275 Jupyter(task): Rework Jupyter Settings GitOrigin-RevId: 23bfec771f48e3bdec14ef19ab6f07153b6861b2 --- .../jupyter/core/jupyter/preview/JupyterHttpUtils.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jupyter/src/com/intellij/notebooks/jupyter/core/jupyter/preview/JupyterHttpUtils.kt b/jupyter/src/com/intellij/notebooks/jupyter/core/jupyter/preview/JupyterHttpUtils.kt index 31724a5cb242..e78a21f18e7d 100644 --- a/jupyter/src/com/intellij/notebooks/jupyter/core/jupyter/preview/JupyterHttpUtils.kt +++ b/jupyter/src/com/intellij/notebooks/jupyter/core/jupyter/preview/JupyterHttpUtils.kt @@ -13,6 +13,10 @@ fun getJupyterBaseUrl(scheme: String): URIBuilder = fun URIBuilder.addPathSegment(string: String): URIBuilder = setPath("${path ?: ""}/${string.trimStart('/')}") fun URIBuilder.addParameter(name: String, value: Boolean): URIBuilder = addParameter(name, value.toString()) +fun URIBuilder.dropLastPathSegment(): URIBuilder { + val newPath = path.removeSuffix("/").dropLastWhile { it != '/' }.removeSuffix("/") + return setPath(newPath) +} /** * In contrast with [URI.resolve], this method resolves paths like it happens in filesystems. @@ -24,4 +28,7 @@ fun URIBuilder.addParameter(name: String, value: Boolean): URIBuilder = addParam * URI("http://example.com/foo").addPathSegment("bar/baz") == URI("http://example.com/foo/bar/baz") * ``` */ -fun URI.addPathSegment(string: String): URI = URIBuilder(this).addPathSegment(string).build() \ No newline at end of file +fun URI.addPathSegment(string: String): URI = URIBuilder(this).addPathSegment(string).build() +fun URI.getPathSegments(): List = path.split("/") +fun URI.dropLastPathSegment(): URI = URIBuilder(this).dropLastPathSegment().build() +fun URI.addQuery(name: String, value: String): URI = URIBuilder(this).addParameter(name, value).build() \ No newline at end of file