Home | History | Annotate | Download | only in Lib

Lines Matching full: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
29 # strings representing various path-related bits and pieces
49 # Return whether a path is absolute.
53 """Test whether a path is absolute"""
63 If any component is an absolute path, all previous path components
64 will be discarded. An empty last part will result in a path that
66 path = a
69 path = b
70 elif path == '' or path.endswith('/'):
71 path += b
73 path += '/' + b
74 return path
77 # Split a path in head (everything up to the last '/') and tail (the
78 # rest). If the path ends in '/', tail will be empty. If there is no
79 # '/' in the path, head will be empty.
92 # Split a path in root and extension.
102 # path. Useful on DOS/Windows/NT; on Unix, the drive is always empty.
105 """Split a pathname into drive and path. On Posix, drive is always
110 # Return the tail (basename) part of a path, same as split(path)[1].
118 # Return the head (dirname) part of a path, same as split(path)[0].
129 # Is a path a symbolic link?
132 def islink(path):
133 """Test whether a path is a symbolic link"""
135 st = os.lstat(path)
142 def lexists(path):
143 """Test whether a path exists. Returns True for broken symbolic links"""
145 os.lstat(path)
179 # Is a path a mount point?
182 def ismount(path):
183 """Test whether a path is a mount point"""
184 if islink(path):
188 s1 = os.lstat(path)
189 s2 = os.lstat(realpath(join(path, '..')))
195 return True # path/.. on a different device as path
199 return True # path/.. is the same i-node as path
225 warnings.warnpy3k("In 3.x, os.path.walk is removed in favor of os.walk.",
244 # If the path doesn't begin with '~', or if the user or $HOME is unknown,
245 # the path is returned unchanged (leaving error reporting to whatever
246 # function is called with the expanded path as argument).
251 def expanduser(path):
254 if not path.startswith('~'):
255 return path
256 i = path.find('/', 1)
258 i = len(path)
268 pwent = pwd.getpwnam(path[1:i])
270 return path
273 return (userhome + path[i:]) or '/'
283 def expandvars(path):
287 if '$' not in path:
288 return path
289 if isinstance(path, _unicode):
303 m = varprog.search(path, i)
313 tail = path[j:]
317 path = path[:i] + value
318 i = len(path)
319 path += tail
322 return path
325 # Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A/B.
326 # It should be understood that this may change the meaning of the path
329 def normpath(path):
330 """Normalize path, eliminating double slashes, etc."""
331 # Preserve unicode (if path is unicode)
332 slash, dot = (u'/', u'.') if isinstance(path, _unicode) else ('/', '.')
333 if path == '':
335 initial_slashes = path.startswith('/')
339 path.startswith('//') and not path.startswith('///')):
341 comps = path.split('/')
352 path = slash.join(comps)
354 path = slash*initial_slashes + path
355 return path or dot
358 def abspath(path):
359 """Return an absolute path."""
360 if not isabs(path):
361 if isinstance(path, _unicode):
365 path = join(cwd, path)
366 return normpath(path)
369 # Return a canonical path (i.e. the absolute location of a file on the
373 """Return the canonical path of the specified filename, eliminating any
374 symbolic links encountered in the path."""
375 path, ok = _joinrealpath('', filename, {})
376 return abspath(path)
379 # encountered in the second path.
380 def _joinrealpath(path, rest, seen):
383 path = sep
392 if path:
393 path, name = split(path)
395 path = join(path, pardir, pardir)
397 path = pardir
399 newpath = join(path, name)
401 path = newpath
405 # Already seen this path
406 path = seen[newpath]
407 if path is not None:
411 # Return already resolved part + rest of the path unchanged.
414 path, ok = _joinrealpath(path, os.readlink(newpath), seen)
416 return join(path, rest), False
417 seen[newpath] = path # resolved symlink
419 return path, True
424 def relpath(path, start=curdir):
425 """Return a relative version of a path"""
427 if not path:
428 raise ValueError("no path specified")
431 path_list = [x for x in abspath(path).split(sep) if x]
433 # Work out how much of the filepath is shared by start and path.