MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / is_posixpath

Function is_posixpath

src/commoncode/fileutils.py:142–163  ·  view source on GitHub ↗

r""" Return True if the `location` path is likely a POSIX-like path using POSIX path separators (slash or "/")or has no path separator. Return False if the `location` path is likely a Windows-like path using backslash as path separators (e.g. "\").

(location)

Source from the content-addressed store, hash-verified

140
141
142def is_posixpath(location):
143 r"""
144 Return True if the `location` path is likely a POSIX-like path using POSIX path
145 separators (slash or "/")or has no path separator.
146
147 Return False if the `location` path is likely a Windows-like path using backslash
148 as path separators (e.g. "\").
149 """
150 has_slashes = "/" in location
151 has_backslashes = "\\" in location
152 # windows paths with drive
153 if location:
154 drive, _ = ntpath.splitdrive(location)
155 if drive:
156 return False
157
158 # a path is always POSIX unless it contains ONLY backslahes
159 # which is a rough approximation (it could still be posix)
160 is_posix = True
161 if has_backslashes and not has_slashes:
162 is_posix = False
163 return is_posix
164
165
166def as_posixpath(location):

Callers 5

safe_pathFunction · 0.90
path_handlersFunction · 0.90
resolveFunction · 0.90
split_parent_resourceFunction · 0.85
parent_directoryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected