Lines Matching refs:path

4 this module as os.path.  The "os.path" name is an alias for this
6 os.path provides the same operations in a manner specific to that
13 # Strings representing various path-related bits and pieces.
41 def _get_sep(path):
42 if isinstance(path, bytes):
57 # Return whether a path is absolute.
61 """Test whether a path is absolute"""
73 If any component is an absolute path, all previous path components
74 will be discarded. An empty last part will result in a path that
78 path = a
81 path[:0] + sep #23780: Ensure compatible data type even if p is null.
84 path = b
85 elif not path or path.endswith(sep):
86 path += b
88 path += sep + b
92 return path
95 # Split a path in head (everything up to the last '/') and tail (the
96 # rest). If the path ends in '/', tail will be empty. If there is no
97 # '/' in the path, head will be empty.
112 # Split a path in root and extension.
129 # path. Useful on DOS/Windows/NT; on Unix, the drive is always empty.
132 """Split a pathname into drive and path. On Posix, drive is always
138 # Return the tail (basename) part of a path, same as split(path)[1].
148 # Return the head (dirname) part of a path, same as split(path)[0].
161 # Is a path a symbolic link?
164 def islink(path):
165 """Test whether a path is a symbolic link"""
167 st = os.lstat(path)
174 def lexists(path):
175 """Test whether a path exists. Returns True for broken symbolic links"""
177 os.lstat(path)
183 # Is a path a mount point?
186 def ismount(path):
187 """Test whether a path is a mount point"""
189 s1 = os.lstat(path)
198 path = os.fspath(path)
199 if isinstance(path, bytes):
200 parent = join(path, b'..')
202 parent = join(path, '..')
212 return True # path/.. on a different device as path
216 return True # path/.. is the same i-node as path
222 # If the path doesn't begin with '~', or if the user or $HOME is unknown,
223 # the path is returned unchanged (leaving error reporting to whatever
224 # function is called with the expanded path as argument).
229 def expanduser(path):
232 path = os.fspath(path)
233 if isinstance(path, bytes):
237 if not path.startswith(tilde):
238 return path
239 sep = _get_sep(path)
240 i = path.find(sep, 1)
242 i = len(path)
248 # pwd module unavailable, return path unchanged
249 return path
254 # password database, return the path unchanged
255 return path
262 # pwd module unavailable, return path unchanged
263 return path
264 name = path[1:i]
270 # bpo-10496: if the user name from the path doesn't exist in the
271 # password database, return the path unchanged
272 return path
274 # if no user home, return the path unchanged on VxWorks
276 return path
277 if isinstance(path, bytes):
283 return (userhome + path[i:]) or root
293 def expandvars(path):
296 path = os.fspath(path)
298 if isinstance(path, bytes):
299 if b'$' not in path:
300 return path
309 if '$' not in path:
310 return path
320 m = search(path, i)
335 tail = path[j:]
336 path = path[:i] + value
337 i = len(path)
338 path += tail
339 return path
342 # Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A/B.
343 # It should be understood that this may change the meaning of the path
350 def normpath(path):
351 """Normalize path, eliminating double slashes, etc."""
352 path = os.fspath(path)
353 if isinstance(path, bytes):
363 if path == empty:
365 initial_slashes = path.startswith(sep)
370 path.startswith(sep*2) and not path.startswith(sep*3)):
372 comps = path.split(sep)
383 path = sep.join(comps)
385 path = sep*initial_slashes + path
386 return path or dot
389 def normpath(path):
390 """Normalize path, eliminating double slashes, etc."""
391 path = os.fspath(path)
392 if isinstance(path, bytes):
393 return os.fsencode(_path_normpath(os.fsdecode(path))) or b"."
394 return _path_normpath(path) or "."
397 def abspath(path):
398 """Return an absolute path."""
399 path = os.fspath(path)
400 if not isabs(path):
401 if isinstance(path, bytes):
405 path = join(cwd, path)
406 return normpath(path)
409 # Return a canonical path (i.e. the absolute location of a file on the
413 """Return the canonical path of the specified filename, eliminating any
414 symbolic links encountered in the path."""
416 path, ok = _joinrealpath(filename[:0], filename, strict, {})
417 return abspath(path)
420 # encountered in the second path.
421 def _joinrealpath(path, rest, strict, seen):
422 if isinstance(path, bytes):
433 path = sep
442 if path:
443 path, name = split(path)
445 path = join(path, pardir, pardir)
447 path = pardir
449 newpath = join(path, name)
459 path = newpath
463 # Already seen this path
464 path = seen[newpath]
465 if path is not None:
473 # Return already resolved part + rest of the path unchanged.
476 path, ok = _joinrealpath(path, os.readlink(newpath), strict, seen)
478 return join(path, rest), False
479 seen[newpath] = path # resolved symlink
481 return path, True
486 def relpath(path, start=None):
487 """Return a relative version of a path"""
489 if not path:
490 raise ValueError("no path specified")
492 path = os.fspath(path)
493 if isinstance(path, bytes):
509 path_list = [x for x in abspath(path).split(sep) if x]
510 # Work out how much of the filepath is shared by start and path.
518 genericpath._check_arg_types('relpath', path, start)
522 # Return the longest common sub-path of the sequence of paths given as input.
525 # returned path.
528 """Given a sequence of path names, returns the longest common sub-path."""
542 split_paths = [path.split(sep) for path in paths]