19 from urllib.request
import pathname2url
as path_to_url
23 from .encoding
import system_decode
24 from .platform
import WINDOWS
25 from .robottypes
import is_string
26 from .unic
import safe_str
30 CASE_INSENSITIVE_FILESYSTEM =
True
33 CASE_INSENSITIVE_FILESYSTEM = os.listdir(
'/tmp') == os.listdir(
'/TMP')
35 CASE_INSENSITIVE_FILESYSTEM =
False
50 path = os.path.normpath(path)
51 if case_normalize
and CASE_INSENSITIVE_FILESYSTEM:
53 if WINDOWS
and len(path) == 2
and path[1] ==
':':
66 path =
normpath(path, case_normalize)
67 return normpath(os.path.abspath(path), case_normalize)
80 url = path_to_url(path)
81 if os.path.isabs(path):
89 if os.path.isfile(base):
90 base = os.path.dirname(base)
93 base_drive, base_path = os.path.splitdrive(base)
95 if os.path.splitdrive(target)[0] != base_drive:
98 if base_path == os.sep:
99 return target[common_len:]
100 if common_len == len(base_drive) + len(os.sep):
101 common_len -= len(os.sep)
102 dirs_up = os.sep.join([os.pardir] * base[common_len:].count(os.sep))
103 path = os.path.join(dirs_up, target[common_len + len(os.sep):])
104 return os.path.normpath(path)
118 if p1.startswith(
'//'):
119 p1 =
'/' + p1.lstrip(
'/')
120 if p2.startswith(
'//'):
121 p2 =
'/' + p2.lstrip(
'/')
125 if len(p1) > len(p2):
126 p1 = os.path.dirname(p1)
128 p2 = os.path.dirname(p2)
133 path = os.path.normpath(path.replace(
'/', os.sep))
134 if os.path.isabs(path):
140 default = file_type
or 'File'
141 file_type = {
'Library':
'Library',
142 'Variables':
'Variable file',
143 'Resource':
'Resource file'}.get(file_type, default)
144 raise DataError(
"%s '%s' does not exist." % (file_type, path))
154 for base
in [basedir] + sys.path:
155 if not (base
and os.path.isdir(base)):
159 ret = os.path.abspath(os.path.join(base, path))
166 return os.path.isfile(path)
or \
167 (os.path.isdir(path)
and os.path.isfile(os.path.join(path,
'__init__.py')))
def system_decode(string)
def _find_absolute_path(path)
def abspath(path, case_normalize=False)
Replacement for os.path.abspath with some enhancements and bug fixes.
def find_file(path, basedir='.', file_type=None)
def get_link_path(target, base)
Returns a relative path to target from base.
def _find_relative_path(path, basedir)
def _get_link_path(target, base)
def _common_path(p1, p2)
Returns the longest path common to p1 and p2.
def normpath(path, case_normalize=False)
Replacement for os.path.normpath with some enhancements.