• Home
  • Raw
  • Download

Lines Matching +full:path +full:- +full:is +full:- +full:absolute

1 # Module 'ntpath' -- common operations on WinNT/Win95 pathnames
5 module as os.path.
24 # strings representing various path-related bits and pieces
41 # (this is done by normpath).
50 # Return whether a path is absolute.
51 # Trivial in Posix, harder on the Mac or MS-DOS.
52 # For DOS it is absolute if it starts with a slash or backslash (current
57 """Test whether a path is absolute"""
63 def join(path, *paths): argument
65 result_drive, result_path = splitdrive(path)
69 # Second path is absolute
76 # Different drives => ignore the first path entirely
82 # Second path is relative to the first
83 if result_path and result_path[-1] not in '\\/':
86 ## add separator between UNC and non-absolute path
88 result_drive and result_drive[-1:] != ':'):
93 # Split a path in a drive specification (a drive letter followed by a
94 # colon) and the path specification.
95 # It is always true that drivespec + pathspec == p
97 """Split a pathname into drive/UNC sharepoint and relative path specifiers.
98 Returns a 2-tuple (drive_or_unc, path); either part may be empty.
102 It is always true that:
105 If the path contained a drive letter, drive_or_unc will contain everything
108 If the path contained a UNC path, the drive_or_unc will contain the host name
112 Paths cannot contain both a drive letter and a UNC path.
118 # is a UNC path:
119 # vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
123 if index == -1:
126 # a UNC path can't have two slashes in a row
130 if index2 == -1:
139 """Split a pathname into UNC mount point and relative path specifiers.
141 Return a 2-tuple (unc, rest); either part may be empty.
142 If unc is not empty, it has the form '//host/mount' (or similar
143 using backslashes). unc+rest is always the input path.
150 # is a UNC path:
159 # a UNC path can't have two slashes in a row
163 if index2 == -1:
169 # Split a path in head (everything up to the last '/') and tail (the
170 # rest). After the trailing '/' is stripped, the invariant
172 # The resulting head won't end in '/' unless it is the root.
177 Return tuple (head, tail) where tail is everything after the final slash.
183 while i and p[i-1] not in '/\\':
184 i = i - 1
188 while head2 and head2[-1] in '/\\':
189 head2 = head2[:-1]
194 # Split a path in root and extension.
195 # The extension is everything starting at the last dot in the last
196 # pathname component; the root is everything before that.
197 # It is always true that root + ext == p.
204 # Return the tail (basename) part of a path.
211 # Return the head (dirname) part of a path.
217 # Is a path a symbolic link?
220 def islink(path): argument
229 # Is a path a mount point? Either a root (with or without drive letter)
230 # or a UNC path with at most a / or \ after the mount point.
232 def ismount(path): argument
233 """Test whether a path is a mount point (defined as root of drive)"""
234 unc, rest = splitunc(path)
237 p = splitdrive(path)[1]
243 # '.' and '..'), func(arg, dirname, filenames) is called, where
244 # dirname is the name of the directory and filenames is the list
254 dirname is the name of the directory, and fnames a list of the names of
256 may modify the fnames list in-place (e.g. via del or slice assignment),
260 beyond that arg is always passed to func. It can be used, e.g., to pass
262 statistics. Passing None for arg is common."""
263 warnings.warnpy3k("In 3.x, os.path.walk is removed in favor of os.walk.",
278 # If the path doesn't begin with '~', or if the user or $HOME is unknown,
279 # the path is returned unchanged (leaving error reporting to whatever
280 # function is called with the expanded path as argument).
282 # (A function should also be defined to do full *sh-style environment
285 def expanduser(path): argument
288 If user or $HOME is unknown, do nothing."""
289 if path[:1] != '~':
290 return path
291 i, n = 1, len(path)
292 while i < n and path[i] not in '/\\':
300 return path
309 userhome = join(dirname(userhome), path[1:i])
311 return userhome + path[i:]
316 # - no expansion within single quotes
317 # - '$$' is translated into '$'
318 # - '%%' is translated into '%' if '%%' are not seen in %var1%%var2%
319 # - ${varname} is accepted.
320 # - $varname is accepted.
321 # - %varname% is accepted.
322 # - varnames can be made out of letters, digits and the characters '_-'
323 # (though is not verified in the ${varname} and %varname% cases)
327 def expandvars(path): argument
331 if '$' not in path and '%' not in path:
332 return path
334 varchars = string.ascii_letters + string.digits + '_-'
335 if isinstance(path, _unicode):
344 pathlen = len(path)
346 c = path[index]
348 path = path[index + 1:]
349 pathlen = len(path)
351 index = path.index('\'')
352 res = res + '\'' + path[:index + 1]
354 res = res + c + path
355 index = pathlen - 1
357 if path[index + 1:index + 2] == '%':
361 path = path[index+1:]
362 pathlen = len(path)
364 index = path.index('%')
366 res = res + '%' + path
367 index = pathlen - 1
369 var = path[:index]
375 if path[index + 1:index + 2] == '$':
378 elif path[index + 1:index + 2] == '{':
379 path = path[index+2:]
380 pathlen = len(path)
382 index = path.index('}')
383 var = path[:index]
389 res = res + '${' + path
390 index = pathlen - 1
394 c = path[index:index + 1]
398 c = path[index:index + 1]
404 index = index - 1
411 # Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A\B.
413 # but as this module is called "ntpath", that's obviously wrong!
415 def normpath(path): argument
416 """Normalize path, eliminating double slashes, etc."""
417 # Preserve unicode (if path is unicode)
418 backslash, dot = (u'\\', u'.') if isinstance(path, _unicode) else ('\\', '.')
419 if path.startswith(('\\\\.\\', '\\\\?\\')):
421 # \\.\ -> device names
422 # \\?\ -> literal paths
423 # do not do any normalization, but return the path unchanged
424 return path
425 path = path.replace("/", "\\")
426 prefix, path = splitdrive(path)
427 # We need to be careful here. If the prefix is empty, and the path starts
428 # with a backslash, it could either be an absolute path on the current
430 # is therefore imperative NOT to collapse multiple backslashes blindly in
432 # The code below preserves multiple backslashes when there is no drive
433 # letter. This means that the invalid filename \\\a\b is preserved
434 # unchanged, where a\\\b is normalised to a\b. It's not clear that there
435 # is any better behaviour for such edge cases.
437 # No drive letter - preserve initial backslashes
438 while path[:1] == "\\":
440 path = path[1:]
442 # We have a drive letter - collapse initial backslashes
443 if path.startswith("\\"):
445 path = path.lstrip("\\")
446 comps = path.split("\\")
452 if i > 0 and comps[i-1] != '..':
453 del comps[i-1:i+1]
454 i -= 1
461 # If the path is now empty, substitute '.'
467 # Return an absolute path.
471 except ImportError: # not running on Windows - mock up something sensible
472 def abspath(path): argument
473 """Return the absolute version of a path."""
474 if not isabs(path):
475 if isinstance(path, _unicode):
479 path = join(cwd, path)
480 return normpath(path)
483 def abspath(path): argument
484 """Return the absolute version of a path."""
486 if path: # Empty path must return current working directory.
488 path = _getfullpathname(path)
490 pass # Bad path - return unchanged.
491 elif isinstance(path, _unicode):
492 path = os.getcwdu()
494 path = os.getcwd()
495 return normpath(path)
497 # realpath is a no-op on systems without islink support
503 def _abspath_split(path): argument
504 abs = abspath(normpath(path))
511 def relpath(path, start=curdir): argument
512 """Return a relative version of a path"""
514 if not path:
515 raise ValueError("no path specified")
518 path_is_unc, path_prefix, path_list = _abspath_split(path)
521 raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)"
522 % (path, start))
525 raise ValueError("path is on UNC root %s, start on UNC root %s"
528 raise ValueError("path is on drive %s, start on drive %s"
530 # Work out how much of the filepath is shared by start and path.
537 rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
544 # attribute to tell whether or not the path is a directory.
545 # This is overkill on Windows - just pass the path to GetFileAttributes