Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
228 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import re | ||
import six | ||
import platform | ||
|
||
|
||
_WINDOWS_PLATFORM = platform.system() == "Windows" | ||
|
||
|
||
def url_quote(path_snippet): | ||
""" | ||
On Windows, it will separate drive letter and quote windows | ||
path alone. No magic on Unix-alie path, just pythonic | ||
`pathname2url` | ||
Arguments: | ||
path_snippet: a file path, relative or absolute. | ||
""" | ||
# type: (Text) -> Text | ||
if _WINDOWS_PLATFORM and _has_drive_letter(path_snippet): | ||
drive_letter, path = path_snippet.split(":", 1) | ||
if six.PY2: | ||
path = path.encode("utf-8") | ||
path = six.moves.urllib.request.pathname2url(path) | ||
path_snippet = "{}:{}".format(drive_letter, path) | ||
else: | ||
if six.PY2: | ||
path_snippet = path_snippet.encode("utf-8") | ||
path_snippet = six.moves.urllib.request.pathname2url(path_snippet) | ||
return path_snippet | ||
|
||
|
||
def _has_drive_letter(path_snippet): | ||
""" | ||
The following path will get True | ||
D:/Data | ||
C:\\My Dcouments\\ test | ||
And will get False | ||
/tmp/abc:test | ||
Arguments: | ||
path_snippet: a file path, relative or absolute. | ||
""" | ||
# type: (Text) -> Text | ||
windows_drive_pattern = ".:[/\\\\].*$" | ||
return re.match(windows_drive_pattern, path_snippet) is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.