Home | History | Annotate | Download | only in python2.7

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
36 # strings representing various path-related bits and pieces
56 # Return whether a path is absolute.
60 """Test whether a path is absolute"""
70 If any component is an absolute path, all previous path components
71 will be discarded. An empty last part will result in a path that
73 path = a
76 path = b
77 elif path == '' or path.endswith('/'):
78 path += b
80 path += '/' + b
81 return path
84 # Split a path in head (everything up to the last '/') and tail (the
85 # rest). If the path ends in '/', tail will be empty. If there is no
86 # '/' in the path, head will be empty.
99 # Split a path in root and extension.
109 # path. Useful on DOS/Windows/NT; on Unix, the drive is always empty.
112 """Split a pathname into drive and path. On Posix, drive is always
117 # Return the tail (basename) part of a path, same as split(path)[1].
125 # Return the head (dirname) part of a path, same as split(path)[0].
136 # Is a path a symbolic link?
139 def islink(path):
140 """Test whether a path is a symbolic link"""
142 st = os.lstat(path)
149 def lexists(path):
150 """Test whether a path exists. Returns True for broken symbolic links"""
152 os.lstat(path)
186 # Is a path a mount point?
189 def ismount(path):
190 """Test whether a path is a mount point"""
191 if islink(path):
195 s1 = os.lstat(path)
196 s2 = os.lstat(join(path, '..'))
202 return True # path/.. on a different device as path
206 return True # path/.. is the same i-node as path
232 warnings.warnpy3k("In 3.x, os.path.walk is removed in favor of os.walk.",
251 # If the path doesn't begin with '~', or if the user or $HOME is unknown,
252 # the path is returned unchanged (leaving error reporting to whatever
253 # function is called with the expanded path as argument).
258 def expanduser(path):
261 if not path.startswith('~'):
262 return path
263 i = path.find('/', 1)
265 i = len(path)
275 pwent = pwd.getpwnam(path[1:i])
277 return path
280 return (userhome + path[i:]) or '/'
289 def expandvars(path):
293 if '$' not in path:
294 return path
300 m = _varprog.search(path, i)
308 tail = path[j:]
309 path = path[:i] + os.environ[name]
310 i = len(path)
311 path += tail
314 return path
317 # Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A/B.
318 # It should be understood that this may change the meaning of the path
321 def normpath(path):
322 """Normalize path, eliminating double slashes, etc."""
323 # Preserve unicode (if path is unicode)
324 slash, dot = (u'/', u'.') if isinstance(path, _unicode) else ('/', '.')
325 if path == '':
327 initial_slashes = path.startswith('/')
331 path.startswith('//') and not path.startswith('///')):
333 comps = path.split('/')
344 path = slash.join(comps)
346 path = slash*initial_slashes + path
347 return path or dot
350 def abspath(path):
351 """Return an absolute path."""
352 if not isabs(path):
353 if isinstance(path, _unicode):
357 path = join(cwd, path)
358 return normpath(path)
361 # Return a canonical path (i.e. the absolute location of a file on the
365 """Return the canonical path of the specified filename, eliminating any
366 symbolic links encountered in the path."""
367 path, ok = _joinrealpath('', filename, {})
368 return abspath(path)
371 # encountered in the second path.
372 def _joinrealpath(path, rest, seen):
375 path = sep
384 if path:
385 path, name = split(path)
387 path = join(path, pardir, pardir)
389 path = pardir
391 newpath = join(path, name)
393 path = newpath
397 # Already seen this path
398 path = seen[newpath]
399 if path is not None:
403 # Return already resolved part + rest of the path unchanged.
406 path, ok = _joinrealpath(path, os.readlink(newpath), seen)
408 return join(path, rest), False
409 seen[newpath] = path # resolved symlink
411 return path, True
416 def relpath(path, start=curdir):
417 """Return a relative version of a path"""
419 if not path:
420 raise ValueError("no path specified")
423 path_list = [x for x in abspath(path).split(sep) if x]
425 # Work out how much of the filepath is shared by start and path.