-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ML-3730: fix support for client running on windows OS #106
base: development
Are you sure you want to change the base?
Changes from all commits
a45a9a3
191db24
5a5f8b4
3d76aeb
069f0a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2023 Iguazio | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2023 Iguazio | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
import unittest | ||
|
||
from v3io.common.helpers import url_join | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this file should be called |
||
|
||
|
||
class Test(unittest.TestCase): | ||
def test_url_join(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably better make this a parameterized test, so that we can see which test cases pass and which fail. |
||
self.assertEqual("a/b", url_join("a", "b")) # add just exactly one "/" between parts | ||
self.assertEqual("/a/b", url_join("/", "a", "b")) | ||
self.assertEqual("/a/b", url_join("/", "a", "/b")) | ||
self.assertEqual("/a/b", url_join("/", "/a", "b")) | ||
self.assertEqual("/a/b", url_join("/", "/a", "/b")) | ||
self.assertEqual("/a/b", url_join("/", "/a/", "b")) | ||
self.assertEqual("/a/b", url_join("/", "/a/", "/b")) | ||
self.assertEqual("a/b", url_join("a", "b")) # keep suffix "/" exist/not-exist invariant | ||
self.assertEqual("a/b/", url_join("a", "b/")) | ||
self.assertEqual("a/b//", url_join("a", "b//")) | ||
self.assertEqual("a/b//", url_join("a", "b//", "/")) # suffix "/" count (if > 0) may change (but we don"t care) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,16 +12,22 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
def url_join(base, *parts): | ||
result = base | ||
|
||
if result[0] != "/": | ||
result = "/" + base | ||
|
||
for part in parts: | ||
if part[0] != "/": | ||
def url_join(*parts): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this might be clearer: def url_join(*parts):
slash_suffix = False
result = ""
for part_index, part in enumerate(parts):
if part == "":
continue
if slash_suffix:
# if slash suffix existed in prev trim slash prefix from this part
result += part.lstrip("/")
else:
# add slash prefix before part if:
# 1. slash suffix did not exist in prev part and
# 2. slash prefix does not exist in this part and
# 3. part is not the first
if part[0] != "/" and part_index != 0:
result += "/"
result += part
slash_suffix = part[-1] == "/"
return result |
||
result = "" | ||
slash_suffix = False | ||
for part_index, part in enumerate(parts): | ||
if part == "": | ||
continue | ||
# add slash prefix before part if: | ||
# 1. slash suffix did not exit in prev part | ||
# 2. slash prefix does not exit in this part | ||
# 3. part is not the first | ||
Comment on lines
+23
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exit -> exist Need to make it clear that all 3 points need to be true (could be read as just one of them). |
||
if not slash_suffix and part[0] != "/" and part_index != 0: | ||
result += "/" + part | ||
else: | ||
result += part | ||
|
||
# if slash suffix existed in prev trim slash prefix from this part | ||
result += part if not slash_suffix else part.lstrip("/") | ||
slash_suffix = True if part[-1] == "/" else False | ||
return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want to put this in the readme? If so, we should put the import there as well.