Lines Matching full:path
5 module as os.path.
23 # strings representing various path-related bits and pieces
49 # Return whether a path is absolute.
56 """Test whether a path is absolute"""
65 If any component is an absolute path, all previous path components
67 path = a
69 b_wins = 0 # set to 1 iff b makes path irrelevant
70 if path == "":
74 # This probably wipes out path so far. However, it's more
75 # complicated if path begins with a drive letter:
82 if path[1:2] != ":" or b[1:2] == ":":
83 # Path doesn't start with a drive letter, or cases 4 and 5.
86 # Else path has a drive letter, and b doesn't but is absolute.
87 elif len(path) > 3 or (len(path) == 3 and
88 path[-1] not in "/\\"):
93 path = b
96 assert len(path) > 0
97 if path[-1] in "/\\":
99 path += b[1:]
101 path += b
102 elif path[-1] == ":":
103 path += b
106 path += b
108 path += "\\" + b
110 # path is not empty and does not end with a backslash,
114 path += '\\'
116 return path
119 # Split a path in a drive specification (a drive letter followed by a
120 # colon) and the path specification.
123 """Split a pathname into drive and path specifiers. Returns a 2-tuple
124 "(drive,path)"; either part may be empty"""
132 """Split a pathname into UNC mount point and relative path specifiers.
136 using backslashes). unc+rest is always the input path.
143 # is a UNC path:
150 ##raise RuntimeError, 'illegal UNC path: "' + p + '"'
159 # Split a path in head (everything up to the last '/') and tail (the
184 # Split a path in root and extension.
194 # Return the tail (basename) part of a path.
201 # Return the head (dirname) part of a path.
207 # Is a path a symbolic link?
210 def islink(path):
219 # Is a path a mount point? Either a root (with or without drive letter)
220 # or an UNC path with at most a / or \ after the mount point.
222 def ismount(path):
223 """Test whether a path is a mount point (defined as root of drive)"""
224 unc, rest = splitunc(path)
227 p = splitdrive(path)[1]
253 warnings.warnpy3k("In 3.x, os.path.walk is removed in favor of os.walk.",
268 # If the path doesn't begin with '~', or if the user or $HOME is unknown,
269 # the path is returned unchanged (leaving error reporting to whatever
270 # function is called with the expanded path as argument).
275 def expanduser(path):
279 if path[:1] != '~':
280 return path
281 i, n = 1, len(path)
282 while i < n and path[i] not in '/\\':
290 return path
299 userhome = join(dirname(userhome), path[1:i])
301 return userhome + path[i:]
317 def expandvars(path):
321 if '$' not in path and '%' not in path:
322 return path
327 pathlen = len(path)
329 c = path[index]
331 path = path[index + 1:]
332 pathlen = len(path)
334 index = path.index('\'')
335 res = res + '\'' + path[:index + 1]
337 res = res + path
340 if path[index + 1:index + 2] == '%':
344 path = path[index+1:]
345 pathlen = len(path)
347 index = path.index('%')
349 res = res + '%' + path
352 var = path[:index]
358 if path[index + 1:index + 2] == '$':
361 elif path[index + 1:index + 2] == '{':
362 path = path[index+2:]
363 pathlen = len(path)
365 index = path.index('}')
366 var = path[:index]
372 res = res + '${' + path
377 c = path[index:index + 1]
381 c = path[index:index + 1]
394 # Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A\B.
398 def normpath(path):
399 """Normalize path, eliminating double slashes, etc."""
400 # Preserve unicode (if path is unicode)
401 backslash, dot = (u'\\', u'.') if isinstance(path, unicode) else ('\\', '.')
402 if path.startswith(('\\\\.\\', '\\\\?\\')):
406 # do not do any normalization, but return the path unchanged
407 return path
408 path = path.replace("/", "\\")
409 prefix, path = splitdrive(path)
410 # We need to be careful here. If the prefix is empty, and the path starts
411 # with a backslash, it could either be an absolute path on the current
421 while path[:1] == "\\":
423 path = path[1:]
426 if path.startswith("\\"):
428 path = path.lstrip("\\")
429 comps = path.split("\\")
444 # If the path is now empty, substitute '.'
450 # Return an absolute path.
455 def abspath(path):
456 """Return the absolute version of a path."""
457 if not isabs(path):
458 if isinstance(path, unicode):
462 path = join(cwd, path)
463 return normpath(path)
466 def abspath(path):
467 """Return the absolute version of a path."""
469 if path: # Empty path must return current working directory.
471 path = _getfullpathname(path)
473 pass # Bad path - return unchanged.
474 elif isinstance(path, unicode):
475 path = os.getcwdu()
477 path = os.getcwd()
478 path)
486 def _abspath_split(path):
487 abs = abspath(normpath(path))
494 def relpath(path, start=curdir):
495 """Return a relative version of a path"""
497 if not path:
498 raise ValueError("no path specified")
501 path_is_unc, path_prefix, path_list = _abspath_split(path)
505 % (path, start))
508 raise ValueError("path is on UNC root %s, start on UNC root %s"
511 raise ValueError("path is on drive %s, start on drive %s"
513 # Work out how much of the filepath is shared by start and path.
527 # attribute to tell whether or not the path is a directory.
528 # This is overkill on Windows - just pass the path to GetFileAttributes