+++ /dev/null
-"""\r
-Path operations common to more than one OS\r
-Do not use directly. The OS specific modules import the appropriate\r
-functions from this module themselves.\r
-"""\r
-import os\r
-import stat\r
-\r
-__all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime',\r
- 'getsize', 'isdir', 'isfile']\r
-\r
-\r
-try:\r
- _unicode = unicode\r
-except NameError:\r
- # If Python is built without Unicode support, the unicode type\r
- # will not exist. Fake one.\r
- class _unicode(object):\r
- pass\r
-\r
-# Does a path exist?\r
-# This is false for dangling symbolic links on systems that support them.\r
-def exists(path):\r
- """Test whether a path exists. Returns False for broken symbolic links"""\r
- try:\r
- os.stat(path)\r
- except os.error:\r
- return False\r
- return True\r
-\r
-\r
-# This follows symbolic links, so both islink() and isdir() can be true\r
-# for the same path on systems that support symlinks\r
-def isfile(path):\r
- """Test whether a path is a regular file"""\r
- try:\r
- st = os.stat(path)\r
- except os.error:\r
- return False\r
- return stat.S_ISREG(st.st_mode)\r
-\r
-\r
-# Is a path a directory?\r
-# This follows symbolic links, so both islink() and isdir()\r
-# can be true for the same path on systems that support symlinks\r
-def isdir(s):\r
- """Return true if the pathname refers to an existing directory."""\r
- try:\r
- st = os.stat(s)\r
- except os.error:\r
- return False\r
- return stat.S_ISDIR(st.st_mode)\r
-\r
-\r
-def getsize(filename):\r
- """Return the size of a file, reported by os.stat()."""\r
- return os.stat(filename).st_size\r
-\r
-\r
-def getmtime(filename):\r
- """Return the last modification time of a file, reported by os.stat()."""\r
- return os.stat(filename).st_mtime\r
-\r
-\r
-def getatime(filename):\r
- """Return the last access time of a file, reported by os.stat()."""\r
- return os.stat(filename).st_atime\r
-\r
-\r
-def getctime(filename):\r
- """Return the metadata change time of a file, reported by os.stat()."""\r
- return os.stat(filename).st_ctime\r
-\r
-\r
-# Return the longest prefix of all list elements.\r
-def commonprefix(m):\r
- "Given a list of pathnames, returns the longest common leading component"\r
- if not m: return ''\r
- s1 = min(m)\r
- s2 = max(m)\r
- for i, c in enumerate(s1):\r
- if c != s2[i]:\r
- return s1[:i]\r
- return s1\r
-\r
-# Split a path in root and extension.\r
-# The extension is everything starting at the last dot in the last\r
-# pathname component; the root is everything before that.\r
-# It is always true that root + ext == p.\r
-\r
-# Generic implementation of splitext, to be parametrized with\r
-# the separators\r
-def _splitext(p, sep, altsep, extsep):\r
- """Split the extension from a pathname.\r
-\r
- Extension is everything from the last dot to the end, ignoring\r
- leading dots. Returns "(root, ext)"; ext may be empty."""\r
-\r
- sepIndex = p.rfind(sep)\r
- if altsep:\r
- altsepIndex = p.rfind(altsep)\r
- sepIndex = max(sepIndex, altsepIndex)\r
-\r
- dotIndex = p.rfind(extsep)\r
- if dotIndex > sepIndex:\r
- # skip all leading dots\r
- filenameIndex = sepIndex + 1\r
- while filenameIndex < dotIndex:\r
- if p[filenameIndex] != extsep:\r
- return p[:dotIndex], p[dotIndex:]\r
- filenameIndex += 1\r
-\r
- return p, ''\r