22 from .encoding
import system_decode
23 from .platform
import IRONPYTHON, PY_VERSION, PY2, WINDOWS
24 from .robottypes
import is_unicode
25 from .unic
import unic
28 if IRONPYTHON
and PY_VERSION == (2, 7, 8):
31 if os.path.isabs(path):
32 if not os.path.splitdrive(path)[0]:
33 drive = os.path.splitdrive(os.getcwd())[0]
36 return os.path.abspath(path)
41 _abspath = os.path.abspath
44 from urllib
import pathname2url
47 return pathname2url(path.encode(
'UTF-8'))
49 from urllib.request
import pathname2url
as path_to_url
52 CASE_INSENSITIVE_FILESYSTEM =
True
55 CASE_INSENSITIVE_FILESYSTEM = os.listdir(
'/tmp') == os.listdir(
'/TMP')
57 CASE_INSENSITIVE_FILESYSTEM =
False
72 path = os.path.normpath(path)
73 if case_normalize
and CASE_INSENSITIVE_FILESYSTEM:
75 if WINDOWS
and len(path) == 2
and path[1] ==
':':
88 path =
normpath(path, case_normalize)
103 if os.path.isabs(path):
110 if os.path.isfile(base):
111 base = os.path.dirname(base)
114 base_drive, base_path = os.path.splitdrive(base)
116 if os.path.splitdrive(target)[0] != base_drive:
119 if base_path == os.sep:
120 return target[common_len:]
121 if common_len == len(base_drive) + len(os.sep):
122 common_len -= len(os.sep)
123 dirs_up = os.sep.join([os.pardir] * base[common_len:].count(os.sep))
124 path = os.path.join(dirs_up, target[common_len + len(os.sep):])
125 return os.path.normpath(path)
139 if len(p1) > len(p2):
140 p1 = os.path.dirname(p1)
142 p2 = os.path.dirname(p2)
147 path = os.path.normpath(path.replace(
'/', os.sep))
148 if os.path.isabs(path):
154 default = file_type
or 'File'
155 file_type = {
'Library':
'Test library',
156 'Variables':
'Variable file',
157 'Resource':
'Resource file'}.get(file_type, default)
158 raise DataError(
"%s '%s' does not exist." % (file_type, path))
168 for base
in [basedir] + sys.path:
169 if not (base
and os.path.isdir(base)):
173 ret = os.path.abspath(os.path.join(base, path))
180 return os.path.isfile(path)
or \
181 (os.path.isdir(path)
and os.path.isfile(os.path.join(path,
'__init__.py')))
Used when variable does not exist.
def system_decode(string)
Decodes bytes from system (e.g.
def _common_path(p1, p2)
Returns the longest path common to p1 and p2.
def _get_link_path(target, base)
def _find_relative_path(path, basedir)
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 normpath(path, case_normalize=False)
Replacement for os.path.normpath with some enhancements.
def get_link_path(target, base)
Returns a relative path to target from base.