Back to index

python3.2  3.2.2
Functions | Variables
ntpath Namespace Reference

Functions

def _get_empty
def _get_sep
def _get_altsep
def _get_bothseps
def _get_dot
def _get_colon
def _get_special
def normcase
def isabs
def join
def splitdrive
def splitunc
def split
def splitext
def basename
def dirname
def islink
def lexists
def ismount
def expanduser
def expandvars
def normpath
def abspath
def relpath
def _getfinalpathname
def samefile
def _getfileinformation
def sameopenfile

Variables

list __all__
string curdir = '.'
string pardir = '..'
string extsep = '.'
string sep = '\\'
string pathsep = ';'
string altsep = '/'
string defpath = '.;C:\\bin'
string devnull = 'nul'
 realpath = abspath
tuple supports_unicode_filenames

Function Documentation

def ntpath._get_altsep (   path) [private]

Definition at line 50 of file ntpath.py.

00050 
00051 def _get_altsep(path):
00052     if isinstance(path, bytes):
00053         return b'/'
00054     else:
00055         return '/'

Here is the caller graph for this function:

def ntpath._get_bothseps (   path) [private]

Definition at line 56 of file ntpath.py.

00056 
00057 def _get_bothseps(path):
00058     if isinstance(path, bytes):
00059         return b'\\/'
00060     else:
00061         return '\\/'

Here is the caller graph for this function:

def ntpath._get_colon (   path) [private]

Definition at line 68 of file ntpath.py.

00068 
00069 def _get_colon(path):
00070     if isinstance(path, bytes):
00071         return b':'
00072     else:
00073         return ':'

Here is the caller graph for this function:

def ntpath._get_dot (   path) [private]

Definition at line 62 of file ntpath.py.

00062 
00063 def _get_dot(path):
00064     if isinstance(path, bytes):
00065         return b'.'
00066     else:
00067         return '.'

Here is the caller graph for this function:

def ntpath._get_empty (   path) [private]

Definition at line 38 of file ntpath.py.

00038 
00039 def _get_empty(path):
00040     if isinstance(path, bytes):
00041         return b''
00042     else:
00043         return ''

Here is the caller graph for this function:

def ntpath._get_sep (   path) [private]

Definition at line 44 of file ntpath.py.

00044 
00045 def _get_sep(path):
00046     if isinstance(path, bytes):
00047         return b'\\'
00048     else:
00049         return '\\'

Here is the caller graph for this function:

def ntpath._get_special (   path) [private]

Definition at line 74 of file ntpath.py.

00074 
00075 def _get_special(path):
00076     if isinstance(path, bytes):
00077         return (b'\\\\.\\', b'\\\\?\\')
00078     else:
00079         return ('\\\\.\\', '\\\\?\\')
00080 
00081 # Normalize the case of a pathname and map slashes to backslashes.
00082 # Other normalizations (such as optimizing '../' away) are not done
00083 # (this is done by normpath).

Here is the caller graph for this function:

def ntpath._getfileinformation (   fd) [private]

Definition at line 669 of file ntpath.py.

00669 
00670     def _getfileinformation(fd):
00671         return fd

Here is the caller graph for this function:

def ntpath._getfinalpathname (   f) [private]

Definition at line 656 of file ntpath.py.

00656 
00657     def _getfinalpathname(f):
00658         return normcase(abspath(f))

Here is the call graph for this function:

Here is the caller graph for this function:

def ntpath.abspath (   path)
Return the absolute version of a path.

Definition at line 574 of file ntpath.py.

00574 
00575     def abspath(path):
00576         """Return the absolute version of a path."""
00577         if not isabs(path):
00578             if isinstance(path, bytes):
00579                 cwd = os.getcwdb()
00580             else:
00581                 cwd = os.getcwd()
00582             path = join(cwd, path)
00583         return normpath(path)
00584 
else:  # use native Windows method on Windows

Here is the call graph for this function:

Here is the caller graph for this function:

def ntpath.basename (   p)
Returns the final component of a pathname

Definition at line 307 of file ntpath.py.

00307 
00308 def basename(p):
00309     """Returns the final component of a pathname"""
00310     return split(p)[1]
00311 
00312 
00313 # Return the head (dirname) part of a path.

Here is the call graph for this function:

def ntpath.dirname (   p)
Returns the directory component of a pathname

Definition at line 314 of file ntpath.py.

00314 
00315 def dirname(p):
00316     """Returns the directory component of a pathname"""
00317     return split(p)[0]
00318 
00319 # Is a path a symbolic link?
00320 # This will always return false on systems where os.lstat doesn't exist.

Here is the call graph for this function:

Here is the caller graph for this function:

def ntpath.expanduser (   path)
Expand ~ and ~user constructs.

If user or $HOME is unknown, do nothing.

Definition at line 363 of file ntpath.py.

00363 
00364 def expanduser(path):
00365     """Expand ~ and ~user constructs.
00366 
00367     If user or $HOME is unknown, do nothing."""
00368     if isinstance(path, bytes):
00369         tilde = b'~'
00370     else:
00371         tilde = '~'
00372     if not path.startswith(tilde):
00373         return path
00374     i, n = 1, len(path)
00375     while i < n and path[i] not in _get_bothseps(path):
00376         i += 1
00377 
00378     if 'HOME' in os.environ:
00379         userhome = os.environ['HOME']
00380     elif 'USERPROFILE' in os.environ:
00381         userhome = os.environ['USERPROFILE']
00382     elif not 'HOMEPATH' in os.environ:
00383         return path
00384     else:
00385         try:
00386             drive = os.environ['HOMEDRIVE']
00387         except KeyError:
00388             drive = ''
00389         userhome = join(drive, os.environ['HOMEPATH'])
00390 
00391     if isinstance(path, bytes):
00392         userhome = userhome.encode(sys.getfilesystemencoding())
00393 
00394     if i != 1: #~user
00395         userhome = join(dirname(userhome), path[1:i])
00396 
00397     return userhome + path[i:]
00398 
00399 
00400 # Expand paths containing shell variable substitutions.
00401 # The following rules apply:
00402 #       - no expansion within single quotes
00403 #       - '$$' is translated into '$'
00404 #       - '%%' is translated into '%' if '%%' are not seen in %var1%%var2%
00405 #       - ${varname} is accepted.
00406 #       - $varname is accepted.
00407 #       - %varname% is accepted.
00408 #       - varnames can be made out of letters, digits and the characters '_-'
00409 #         (though is not verified in the ${varname} and %varname% cases)
00410 # XXX With COMMAND.COM you can use any characters in a variable name,
00411 # XXX except '^|<>='.

Here is the call graph for this function:

def ntpath.expandvars (   path)
Expand shell variables of the forms $var, ${var} and %var%.

Unknown variables are left unchanged.

Definition at line 412 of file ntpath.py.

00412 
00413 def expandvars(path):
00414     """Expand shell variables of the forms $var, ${var} and %var%.
00415 
00416     Unknown variables are left unchanged."""
00417     if isinstance(path, bytes):
00418         if ord('$') not in path and ord('%') not in path:
00419             return path
00420         import string
00421         varchars = bytes(string.ascii_letters + string.digits + '_-', 'ascii')
00422         quote = b'\''
00423         percent = b'%'
00424         brace = b'{'
00425         dollar = b'$'
00426     else:
00427         if '$' not in path and '%' not in path:
00428             return path
00429         import string
00430         varchars = string.ascii_letters + string.digits + '_-'
00431         quote = '\''
00432         percent = '%'
00433         brace = '{'
00434         dollar = '$'
00435     res = path[:0]
00436     index = 0
00437     pathlen = len(path)
00438     while index < pathlen:
00439         c = path[index:index+1]
00440         if c == quote:   # no expansion within single quotes
00441             path = path[index + 1:]
00442             pathlen = len(path)
00443             try:
00444                 index = path.index(c)
00445                 res += c + path[:index + 1]
00446             except ValueError:
00447                 res += path
00448                 index = pathlen - 1
00449         elif c == percent:  # variable or '%'
00450             if path[index + 1:index + 2] == percent:
00451                 res += c
00452                 index += 1
00453             else:
00454                 path = path[index+1:]
00455                 pathlen = len(path)
00456                 try:
00457                     index = path.index(percent)
00458                 except ValueError:
00459                     res += percent + path
00460                     index = pathlen - 1
00461                 else:
00462                     var = path[:index]
00463                     if isinstance(path, bytes):
00464                         var = var.decode('ascii')
00465                     if var in os.environ:
00466                         value = os.environ[var]
00467                     else:
00468                         value = '%' + var + '%'
00469                     if isinstance(path, bytes):
00470                         value = value.encode('ascii')
00471                     res += value
00472         elif c == dollar:  # variable or '$$'
00473             if path[index + 1:index + 2] == dollar:
00474                 res += c
00475                 index += 1
00476             elif path[index + 1:index + 2] == brace:
00477                 path = path[index+2:]
00478                 pathlen = len(path)
00479                 try:
00480                     if isinstance(path, bytes):
00481                         index = path.index(b'}')
00482                     else:
00483                         index = path.index('}')
00484                     var = path[:index]
00485                     if isinstance(path, bytes):
00486                         var = var.decode('ascii')
00487                     if var in os.environ:
00488                         value = os.environ[var]
00489                     else:
00490                         value = '${' + var + '}'
00491                     if isinstance(path, bytes):
00492                         value = value.encode('ascii')
00493                     res += value
00494                 except ValueError:
00495                     if isinstance(path, bytes):
00496                         res += b'${' + path
00497                     else:
00498                         res += '${' + path
00499                     index = pathlen - 1
00500             else:
00501                 var = ''
00502                 index += 1
00503                 c = path[index:index + 1]
00504                 while c and c in varchars:
00505                     if isinstance(path, bytes):
00506                         var += c.decode('ascii')
00507                     else:
00508                         var += c
00509                     index += 1
00510                     c = path[index:index + 1]
00511                 if var in os.environ:
00512                     value = os.environ[var]
00513                 else:
00514                     value = '$' + var
00515                 if isinstance(path, bytes):
00516                     value = value.encode('ascii')
00517                 res += value
00518                 if c:
00519                     index -= 1
00520         else:
00521             res += c
00522         index += 1
00523     return res
00524 
00525 
00526 # Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A\B.
00527 # Previously, this function also truncated pathnames to 8+3 format,
00528 # but as this module is called "ntpath", that's obviously wrong!

Here is the call graph for this function:

def ntpath.isabs (   s)
Test whether a path is absolute

Definition at line 100 of file ntpath.py.

00100 
00101 def isabs(s):
00102     """Test whether a path is absolute"""
00103     s = splitdrive(s)[1]
00104     return len(s) > 0 and s[:1] in _get_bothseps(s)
00105 
00106 
00107 # Join two (or more) paths.

Here is the call graph for this function:

Here is the caller graph for this function:

def ntpath.islink (   path)
Test whether a path is a symbolic link.
This will always return false for Windows prior to 6.0
and for OS/2.

Definition at line 321 of file ntpath.py.

00321 
00322 def islink(path):
00323     """Test whether a path is a symbolic link.
00324     This will always return false for Windows prior to 6.0
00325     and for OS/2.
00326     """
00327     try:
00328         st = os.lstat(path)
00329     except (os.error, AttributeError):
00330         return False
00331     return stat.S_ISLNK(st.st_mode)
00332 
00333 # Being true for dangling symbolic links is also useful.

Here is the call graph for this function:

def ntpath.ismount (   path)
Test whether a path is a mount point (defined as root of drive)

Definition at line 345 of file ntpath.py.

00345 
00346 def ismount(path):
00347     """Test whether a path is a mount point (defined as root of drive)"""
00348     seps = _get_bothseps(path)
00349     root, rest = splitdrive(path)
00350     if root and root[0] in seps:
00351         return (not rest) or (rest in seps)
00352     return rest in seps
00353 
00354 
00355 # Expand paths beginning with '~' or '~user'.
00356 # '~' means $HOME; '~user' means that user's home directory.
00357 # If the path doesn't begin with '~', or if the user or $HOME is unknown,
00358 # the path is returned unchanged (leaving error reporting to whatever
00359 # function is called with the expanded path as argument).
00360 # See also module 'glob' for expansion of *, ? and [...] in pathnames.
00361 # (A function should also be defined to do full *sh-style environment
00362 # variable expansion.)

Here is the call graph for this function:

def ntpath.join (   a,
  p 
)
Join two or more pathname components, inserting "\\" as needed.
If any component is an absolute path, all previous path components
will be discarded.

Definition at line 108 of file ntpath.py.

00108 
00109 def join(a, *p):
00110     """Join two or more pathname components, inserting "\\" as needed.
00111     If any component is an absolute path, all previous path components
00112     will be discarded."""
00113     sep = _get_sep(a)
00114     seps = _get_bothseps(a)
00115     colon = _get_colon(a)
00116     path = a
00117     for b in p:
00118         b_wins = 0  # set to 1 iff b makes path irrelevant
00119         if not path:
00120             b_wins = 1
00121 
00122         elif isabs(b):
00123             # This probably wipes out path so far.  However, it's more
00124             # complicated if path begins with a drive letter.  You get a+b
00125             # (minus redundant slashes) in these four cases:
00126             #     1. join('c:', '/a') == 'c:/a'
00127             #     2. join('//computer/share', '/a') == '//computer/share/a'
00128             #     3. join('c:/', '/a') == 'c:/a'
00129             #     4. join('//computer/share/', '/a') == '//computer/share/a'
00130             # But b wins in all of these cases:
00131             #     5. join('c:/a', '/b') == '/b'
00132             #     6. join('//computer/share/a', '/b') == '/b'
00133             #     7. join('c:', 'd:/') == 'd:/'
00134             #     8. join('c:', '//computer/share/') == '//computer/share/'
00135             #     9. join('//computer/share', 'd:/') == 'd:/'
00136             #    10. join('//computer/share', '//computer/share/') == '//computer/share/'
00137             #    11. join('c:/', 'd:/') == 'd:/'
00138             #    12. join('c:/', '//computer/share/') == '//computer/share/'
00139             #    13. join('//computer/share/', 'd:/') == 'd:/'
00140             #    14. join('//computer/share/', '//computer/share/') == '//computer/share/'
00141             b_prefix, b_rest = splitdrive(b)
00142 
00143             # if b has a prefix, it always wins.
00144             if b_prefix:
00145                 b_wins = 1
00146             else:
00147                 # b doesn't have a prefix.
00148                 # but isabs(b) returned true.
00149                 # and therefore b_rest[0] must be a slash.
00150                 # (but let's check that.)
00151                 assert(b_rest and b_rest[0] in seps)
00152 
00153                 # so, b still wins if path has a rest that's more than a sep.
00154                 # you get a+b if path_rest is empty or only has a sep.
00155                 # (see cases 1-4 for times when b loses.)
00156                 path_rest = splitdrive(path)[1]
00157                 b_wins = path_rest and path_rest not in seps
00158 
00159         if b_wins:
00160             path = b
00161         else:
00162             # Join, and ensure there's a separator.
00163             assert len(path) > 0
00164             if path[-1:] in seps:
00165                 if b and b[:1] in seps:
00166                     path += b[1:]
00167                 else:
00168                     path += b
00169             elif path[-1:] == colon:
00170                 path += b
00171             elif b:
00172                 if b[:1] in seps:
00173                     path += b
00174                 else:
00175                     path += sep + b
00176             else:
00177                 # path is not empty and does not end with a backslash,
00178                 # but b is empty; since, e.g., split('a/') produces
00179                 # ('a', ''), it's best if join() adds a backslash in
00180                 # this case.
00181                 path += sep
00182 
00183     return path
00184 
00185 
00186 # Split a path in a drive specification (a drive letter followed by a
00187 # colon) and the path specification.
# It is always true that drivespec + pathspec == p

Here is the call graph for this function:

Here is the caller graph for this function:

def ntpath.lexists (   path)
Test whether a path exists.  Returns True for broken symbolic links

Definition at line 334 of file ntpath.py.

00334 
00335 def lexists(path):
00336     """Test whether a path exists.  Returns True for broken symbolic links"""
00337     try:
00338         st = os.lstat(path)
00339     except (os.error, WindowsError):
00340         return False
00341     return True
00342 
00343 # Is a path a mount point?  Either a root (with or without drive letter)
00344 # or an UNC path with at most a / or \ after the mount point.

def ntpath.normcase (   s)
Normalize case of pathname.

Makes all characters lowercase and all slashes into backslashes.

Definition at line 84 of file ntpath.py.

00084 
00085 def normcase(s):
00086     """Normalize case of pathname.
00087 
00088     Makes all characters lowercase and all slashes into backslashes."""
00089     if not isinstance(s, (bytes, str)):
00090         raise TypeError("normcase() argument must be str or bytes, "
00091                         "not '{}'".format(s.__class__.__name__))
00092     return s.replace(_get_altsep(s), _get_sep(s)).lower()
00093 
00094 
00095 # Return whether a path is absolute.
00096 # Trivial in Posix, harder on Windows.
00097 # For Windows it is absolute if it starts with a slash or backslash (current
00098 # volume), or if a pathname after the volume-letter-and-colon or UNC-resource
00099 # starts with a slash or backslash.

Here is the call graph for this function:

Here is the caller graph for this function:

def ntpath.normpath (   path)
Normalize path, eliminating double slashes, etc.

Definition at line 529 of file ntpath.py.

00529 
00530 def normpath(path):
00531     """Normalize path, eliminating double slashes, etc."""
00532     sep = _get_sep(path)
00533     dotdot = _get_dot(path) * 2
00534     special_prefixes = _get_special(path)
00535     if path.startswith(special_prefixes):
00536         # in the case of paths with these prefixes:
00537         # \\.\ -> device names
00538         # \\?\ -> literal paths
00539         # do not do any normalization, but return the path unchanged
00540         return path
00541     path = path.replace(_get_altsep(path), sep)
00542     prefix, path = splitdrive(path)
00543 
00544     # collapse initial backslashes
00545     if path.startswith(sep):
00546         prefix += sep
00547         path = path.lstrip(sep)
00548 
00549     comps = path.split(sep)
00550     i = 0
00551     while i < len(comps):
00552         if not comps[i] or comps[i] == _get_dot(path):
00553             del comps[i]
00554         elif comps[i] == dotdot:
00555             if i > 0 and comps[i-1] != dotdot:
00556                 del comps[i-1:i+1]
00557                 i -= 1
00558             elif i == 0 and prefix.endswith(_get_sep(path)):
00559                 del comps[i]
00560             else:
00561                 i += 1
00562         else:
00563             i += 1
00564     # If the path is now empty, substitute '.'
00565     if not prefix and not comps:
00566         comps.append(_get_dot(path))
00567     return prefix + sep.join(comps)
00568 
00569 
00570 # Return an absolute path.
00571 try:
00572     from nt import _getfullpathname

Here is the call graph for this function:

Here is the caller graph for this function:

def ntpath.relpath (   path,
  start = curdir 
)
Return a relative version of a path

Definition at line 605 of file ntpath.py.

00605 
00606 def relpath(path, start=curdir):
00607     """Return a relative version of a path"""
00608     sep = _get_sep(path)
00609 
00610     if start is curdir:
00611         start = _get_dot(path)
00612 
00613     if not path:
00614         raise ValueError("no path specified")
00615 
00616     start_abs = abspath(normpath(start))
00617     path_abs = abspath(normpath(path))
00618     start_drive, start_rest = splitdrive(start_abs)
00619     path_drive, path_rest = splitdrive(path_abs)
00620     if normcase(start_drive) != normcase(path_drive):
00621         error = "path is on mount '{0}', start on mount '{1}'".format(
00622             path_drive, start_drive)
00623         raise ValueError(error)
00624 
00625     start_list = [x for x in start_rest.split(sep) if x]
00626     path_list = [x for x in path_rest.split(sep) if x]
00627     # Work out how much of the filepath is shared by start and path.
00628     i = 0
00629     for e1, e2 in zip(start_list, path_list):
00630         if normcase(e1) != normcase(e2):
00631             break
00632         i += 1
00633 
00634     if isinstance(path, bytes):
00635         pardir = b'..'
00636     else:
00637         pardir = '..'
00638     rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
00639     if not rel_list:
00640         return _get_dot(path)
00641     return join(*rel_list)
00642 
00643 
00644 # determine if two files are in fact the same file
00645 try:
00646     # GetFinalPathNameByHandle is available starting with Windows 6.0.
00647     # Windows XP and non-Windows OS'es will mock _getfinalpathname.
00648     if sys.getwindowsversion()[:2] >= (6, 0):
00649         from nt import _getfinalpathname
00650     else:
        raise ImportError

Here is the call graph for this function:

def ntpath.samefile (   f1,
  f2 
)

Definition at line 659 of file ntpath.py.

00659 
00660 def samefile(f1, f2):
00661     "Test whether two pathnames reference the same actual file"
00662     return _getfinalpathname(f1) == _getfinalpathname(f2)
00663 
00664 
00665 try:
    from nt import _getfileinformation

Here is the call graph for this function:

def ntpath.sameopenfile (   f1,
  f2 
)
Test whether two file objects reference the same file

Definition at line 672 of file ntpath.py.

00672 
00673 def sameopenfile(f1, f2):
00674     """Test whether two file objects reference the same file"""
00675     return _getfileinformation(f1) == _getfileinformation(f2)
00676 
00677 
00678 try:
00679     # The genericpath.isdir implementation uses os.stat and checks the mode
00680     # attribute to tell whether or not the path is a directory.
00681     # This is overkill on Windows - just pass the path to GetFileAttributes
00682     # and check the attribute from there.
    from nt import _isdir as isdir

Here is the call graph for this function:

Here is the caller graph for this function:

def ntpath.split (   p)
Split a pathname.

Return tuple (head, tail) where tail is everything after the final slash.
Either part may be empty.

Definition at line 273 of file ntpath.py.

00273 
00274 def split(p):
00275     """Split a pathname.
00276 
00277     Return tuple (head, tail) where tail is everything after the final slash.
00278     Either part may be empty."""
00279 
00280     seps = _get_bothseps(p)
00281     d, p = splitdrive(p)
00282     # set i to index beyond p's last slash
00283     i = len(p)
00284     while i and p[i-1] not in seps:
00285         i -= 1
00286     head, tail = p[:i], p[i:]  # now tail has no slashes
00287     # remove trailing slashes from head, unless it's all slashes
00288     head2 = head
00289     while head2 and head2[-1:] in seps:
00290         head2 = head2[:-1]
00291     head = head2 or head
00292     return d + head, tail
00293 
00294 
00295 # Split a path in root and extension.
00296 # The extension is everything starting at the last dot in the last
00297 # pathname component; the root is everything before that.
00298 # It is always true that root + ext == p.

Here is the call graph for this function:

Here is the caller graph for this function:

def ntpath.splitdrive (   p)
Split a pathname into drive/UNC sharepoint and relative path specifiers.
Returns a 2-tuple (drive_or_unc, path); either part may be empty.

If you assign
    result = splitdrive(p)
It is always true that:
    result[0] + result[1] == p

If the path contained a drive letter, drive_or_unc will contain everything
up to and including the colon.  e.g. splitdrive("c:/dir") returns ("c:", "/dir")

If the path contained a UNC path, the drive_or_unc will contain the host name
and share up to but not including the fourth directory separator character.
e.g. splitdrive("//host/computer/dir") returns ("//host/computer", "/dir")

Paths cannot contain both a drive letter and a UNC path.

Definition at line 188 of file ntpath.py.

00188 
00189 def splitdrive(p):
00190     """Split a pathname into drive/UNC sharepoint and relative path specifiers.
00191     Returns a 2-tuple (drive_or_unc, path); either part may be empty.
00192 
00193     If you assign
00194         result = splitdrive(p)
00195     It is always true that:
00196         result[0] + result[1] == p
00197 
00198     If the path contained a drive letter, drive_or_unc will contain everything
00199     up to and including the colon.  e.g. splitdrive("c:/dir") returns ("c:", "/dir")
00200 
00201     If the path contained a UNC path, the drive_or_unc will contain the host name
00202     and share up to but not including the fourth directory separator character.
00203     e.g. splitdrive("//host/computer/dir") returns ("//host/computer", "/dir")
00204 
00205     Paths cannot contain both a drive letter and a UNC path.
00206 
00207     """
00208     empty = _get_empty(p)
00209     if len(p) > 1:
00210         sep = _get_sep(p)
00211         normp = normcase(p)
00212         if (normp[0:2] == sep*2) and (normp[2:3] != sep):
00213             # is a UNC path:
00214             # vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
00215             # \\machine\mountpoint\directory\etc\...
00216             #           directory ^^^^^^^^^^^^^^^
00217             index = normp.find(sep, 2)
00218             if index == -1:
00219                 return empty, p
00220             index2 = normp.find(sep, index + 1)
00221             # a UNC path can't have two slashes in a row
00222             # (after the initial two)
00223             if index2 == index + 1:
00224                 return empty, p
00225             if index2 == -1:
00226                 index2 = len(p)
00227             return p[:index2], p[index2:]
00228         if normp[1:2] == _get_colon(p):
00229             return p[:2], p[2:]
00230     return empty, p
00231 
00232 
# Parse UNC paths

Here is the call graph for this function:

Here is the caller graph for this function:

def ntpath.splitext (   p)

Definition at line 299 of file ntpath.py.

00299 
00300 def splitext(p):
00301     return genericpath._splitext(p, _get_sep(p), _get_altsep(p),
00302                                  _get_dot(p))
00303 splitext.__doc__ = genericpath._splitext.__doc__
00304 
00305 
00306 # Return the tail (basename) part of a path.

Here is the call graph for this function:

def ntpath.splitunc (   p)
Deprecated since Python 3.1.  Please use splitdrive() instead;
it now handles UNC paths.

Split a pathname into UNC mount point and relative path specifiers.

Return a 2-tuple (unc, rest); either part may be empty.
If unc is not empty, it has the form '//host/mount' (or similar
using backslashes).  unc+rest is always the input path.
Paths containing drive letters never have an UNC part.

Definition at line 233 of file ntpath.py.

00233 
00234 def splitunc(p):
00235     """Deprecated since Python 3.1.  Please use splitdrive() instead;
00236     it now handles UNC paths.
00237 
00238     Split a pathname into UNC mount point and relative path specifiers.
00239 
00240     Return a 2-tuple (unc, rest); either part may be empty.
00241     If unc is not empty, it has the form '//host/mount' (or similar
00242     using backslashes).  unc+rest is always the input path.
00243     Paths containing drive letters never have an UNC part.
00244     """
00245     import warnings
00246     warnings.warn("ntpath.splitunc is deprecated, use ntpath.splitdrive instead",
00247                   DeprecationWarning)
00248     sep = _get_sep(p)
00249     if not p[1:2]:
00250         return p[:0], p # Drive letter present
00251     firstTwo = p[0:2]
00252     if normcase(firstTwo) == sep + sep:
00253         # is a UNC path:
00254         # vvvvvvvvvvvvvvvvvvvv equivalent to drive letter
00255         # \\machine\mountpoint\directories...
00256         #           directory ^^^^^^^^^^^^^^^
00257         normp = normcase(p)
00258         index = normp.find(sep, 2)
00259         if index == -1:
00260             ##raise RuntimeError, 'illegal UNC path: "' + p + '"'
00261             return (p[:0], p)
00262         index = normp.find(sep, index + 1)
00263         if index == -1:
00264             index = len(p)
00265         return p[:index], p[index:]
00266     return p[:0], p
00267 
00268 
00269 # Split a path in head (everything up to the last '/') and tail (the
00270 # rest).  After the trailing '/' is stripped, the invariant
00271 # join(head, tail) == p holds.
00272 # The resulting head won't end in '/' unless it is the root.

Here is the call graph for this function:


Variable Documentation

Initial value:
00001 ["normcase","isabs","join","splitdrive","split","splitext",
00002            "basename","dirname","commonprefix","getsize","getmtime",
00003            "getatime","getctime", "islink","exists","lexists","isdir","isfile",
00004            "ismount", "expanduser","expandvars","normpath","abspath",
00005            "splitunc","curdir","pardir","sep","pathsep","defpath","altsep",
00006            "extsep","devnull","realpath","supports_unicode_filenames","relpath",
00007            "samefile", "sameopenfile",]

Definition at line 14 of file ntpath.py.

Definition at line 29 of file ntpath.py.

Definition at line 24 of file ntpath.py.

string ntpath.defpath = '.;C:\\bin'

Definition at line 30 of file ntpath.py.

Definition at line 36 of file ntpath.py.

Definition at line 26 of file ntpath.py.

Definition at line 25 of file ntpath.py.

Definition at line 28 of file ntpath.py.

Definition at line 600 of file ntpath.py.

Definition at line 27 of file ntpath.py.

Initial value:
00001 (hasattr(sys, "getwindowsversion") and
00002                               sys.getwindowsversion()[3] >= 2)

Definition at line 602 of file ntpath.py.