mirror of https://github.com/python/cpython.git
Replaced obsolete stat module constants with equivalent attributes
This commit is contained in:
parent
16e3c427f3
commit
32200aeac6
|
@ -308,7 +308,7 @@ def executable(path):
|
|||
st = os.stat(path)
|
||||
except os.error:
|
||||
return False
|
||||
return st[0] & 0111 != 0
|
||||
return st.st_mode & 0111 != 0
|
||||
|
||||
|
||||
def test(HandlerClass = CGIHTTPRequestHandler,
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
"""
|
||||
|
||||
import os
|
||||
import stat
|
||||
import sys
|
||||
import py_compile
|
||||
|
||||
|
@ -56,8 +55,8 @@ def compile_dir(dir, maxlevels=10, ddir=None,
|
|||
head, tail = name[:-3], name[-3:]
|
||||
if tail == '.py':
|
||||
cfile = fullname + (__debug__ and 'c' or 'o')
|
||||
ftime = os.stat(fullname)[stat.ST_MTIME]
|
||||
try: ctime = os.stat(cfile)[stat.ST_MTIME]
|
||||
ftime = os.stat(fullname).st_mtime
|
||||
try: ctime = os.stat(cfile).st_mtime
|
||||
except os.error: ctime = 0
|
||||
if (ctime > ftime) and not force: continue
|
||||
if not quiet:
|
||||
|
|
|
@ -23,7 +23,7 @@ def listdir(path):
|
|||
except KeyError:
|
||||
cached_mtime, list = -1, []
|
||||
try:
|
||||
mtime = os.stat(path)[8]
|
||||
mtime = os.stat(path).st_mtime
|
||||
except os.error:
|
||||
return []
|
||||
if mtime != cached_mtime:
|
||||
|
|
|
@ -123,19 +123,16 @@ def commonprefix(m):
|
|||
|
||||
def getsize(filename):
|
||||
"""Return the size of a file, reported by os.stat()."""
|
||||
st = os.stat(filename)
|
||||
return st[stat.ST_SIZE]
|
||||
return os.stat(filename).st_size
|
||||
|
||||
def getmtime(filename):
|
||||
"""Return the last modification time of a file, reported by os.stat()."""
|
||||
st = os.stat(filename)
|
||||
return st[stat.ST_MTIME]
|
||||
return os.stat(filename).st_mtime
|
||||
|
||||
def getatime(filename):
|
||||
"""Return the last access time of a file, reported by os.stat()."""
|
||||
st = os.stat(filename)
|
||||
return st[stat.ST_ATIME]
|
||||
|
||||
return os.stat(filename).st_atime
|
||||
|
||||
def islink(path):
|
||||
"""Is a path a symbolic link?
|
||||
|
@ -162,7 +159,7 @@ def isdir(path):
|
|||
st = os.stat(path)
|
||||
except os.error:
|
||||
return False
|
||||
return stat.S_ISDIR(st[stat.ST_MODE])
|
||||
return stat.S_ISDIR(st.st_mode)
|
||||
|
||||
|
||||
def isfile(path):
|
||||
|
@ -172,7 +169,7 @@ def isfile(path):
|
|||
st = os.stat(path)
|
||||
except os.error:
|
||||
return False
|
||||
return stat.S_ISREG(st[stat.ST_MODE])
|
||||
return stat.S_ISREG(st.st_mode)
|
||||
|
||||
|
||||
def ismount(path):
|
||||
|
|
|
@ -64,9 +64,9 @@ def cmp(f1, f2, shallow=1, use_statcache=0):
|
|||
return outcome
|
||||
|
||||
def _sig(st):
|
||||
return (stat.S_IFMT(st[stat.ST_MODE]),
|
||||
st[stat.ST_SIZE],
|
||||
st[stat.ST_MTIME])
|
||||
return (stat.S_IFMT(st.st_mode),
|
||||
st.st_size,
|
||||
st.st_mtime)
|
||||
|
||||
def _do_cmp(f1, f2):
|
||||
bufsize = BUFSIZE
|
||||
|
@ -199,8 +199,8 @@ def phase2(self): # Distinguish files, directories, funnies
|
|||
ok = 0
|
||||
|
||||
if ok:
|
||||
a_type = stat.S_IFMT(a_stat[stat.ST_MODE])
|
||||
b_type = stat.S_IFMT(b_stat[stat.ST_MODE])
|
||||
a_type = stat.S_IFMT(a_stat.st_mode)
|
||||
b_type = stat.S_IFMT(b_stat.st_mode)
|
||||
if a_type != b_type:
|
||||
self.common_funny.append(x)
|
||||
elif stat.S_ISDIR(a_type):
|
||||
|
|
|
@ -484,7 +484,7 @@ def _os_path_isdir(pathname):
|
|||
s = _os_stat(pathname)
|
||||
except OSError:
|
||||
return None
|
||||
return (s[0] & 0170000) == 0040000
|
||||
return (s.st_mode & 0170000) == 0040000
|
||||
|
||||
def _timestamp(pathname):
|
||||
"Return the file modification time as a Long."
|
||||
|
@ -492,7 +492,7 @@ def _timestamp(pathname):
|
|||
s = _os_stat(pathname)
|
||||
except OSError:
|
||||
return None
|
||||
return long(s[8])
|
||||
return long(s.st_mtime)
|
||||
|
||||
|
||||
######################################################################
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
import sys
|
||||
import os
|
||||
from stat import *
|
||||
|
||||
__all__ = ["getline","clearcache","checkcache"]
|
||||
|
||||
|
@ -52,7 +51,7 @@ def checkcache():
|
|||
except os.error:
|
||||
del cache[filename]
|
||||
continue
|
||||
if size != stat[ST_SIZE] or mtime != stat[ST_MTIME]:
|
||||
if size != stat.st_size or mtime != stat.st_mtime:
|
||||
del cache[filename]
|
||||
|
||||
|
||||
|
@ -96,6 +95,6 @@ def updatecache(filename):
|
|||
except IOError, msg:
|
||||
## print '*** Cannot open', fullname, ':', msg
|
||||
return []
|
||||
size, mtime = stat[ST_SIZE], stat[ST_MTIME]
|
||||
size, mtime = stat.st_size, stat.st_mtime
|
||||
cache[filename] = size, mtime, lines, fullname
|
||||
return lines
|
||||
|
|
|
@ -100,25 +100,22 @@ def isdir(s):
|
|||
st = os.stat(s)
|
||||
except os.error:
|
||||
return 0
|
||||
return S_ISDIR(st[ST_MODE])
|
||||
return S_ISDIR(st.st_mode)
|
||||
|
||||
|
||||
# Get size, mtime, atime of files.
|
||||
|
||||
def getsize(filename):
|
||||
"""Return the size of a file, reported by os.stat()."""
|
||||
st = os.stat(filename)
|
||||
return st[ST_SIZE]
|
||||
return os.stat(filename).st_size
|
||||
|
||||
def getmtime(filename):
|
||||
"""Return the last modification time of a file, reported by os.stat()."""
|
||||
st = os.stat(filename)
|
||||
return st[ST_MTIME]
|
||||
return os.stat(filename).st_mtime
|
||||
|
||||
def getatime(filename):
|
||||
"""Return the last access time of a file, reported by os.stat()."""
|
||||
st = os.stat(filename)
|
||||
return st[ST_ATIME]
|
||||
return os.stat(filename).st_atime
|
||||
|
||||
|
||||
def islink(s):
|
||||
|
@ -138,7 +135,7 @@ def isfile(s):
|
|||
st = os.stat(s)
|
||||
except os.error:
|
||||
return False
|
||||
return S_ISREG(st[ST_MODE])
|
||||
return S_ISREG(st.st_mode)
|
||||
|
||||
|
||||
def exists(s):
|
||||
|
|
|
@ -74,7 +74,6 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
from stat import ST_NLINK
|
||||
import re
|
||||
import mimetools
|
||||
import multifile
|
||||
|
@ -155,8 +154,7 @@ def listsubfolders(self, name):
|
|||
fullname = os.path.join(self.path, name)
|
||||
# Get the link count so we can avoid listing folders
|
||||
# that have no subfolders.
|
||||
st = os.stat(fullname)
|
||||
nlinks = st[ST_NLINK]
|
||||
nlinks = os.stat(fullname).st_nlink
|
||||
if nlinks <= 2:
|
||||
return []
|
||||
subfolders = []
|
||||
|
@ -183,8 +181,7 @@ def listallsubfolders(self, name):
|
|||
fullname = os.path.join(self.path, name)
|
||||
# Get the link count so we can avoid listing folders
|
||||
# that have no subfolders.
|
||||
st = os.stat(fullname)
|
||||
nlinks = st[ST_NLINK]
|
||||
nlinks = os.stat(fullname).st_nlink
|
||||
if nlinks <= 2:
|
||||
return []
|
||||
subfolders = []
|
||||
|
|
|
@ -216,18 +216,15 @@ def commonprefix(m):
|
|||
|
||||
def getsize(filename):
|
||||
"""Return the size of a file, reported by os.stat()"""
|
||||
st = os.stat(filename)
|
||||
return st[stat.ST_SIZE]
|
||||
return os.stat(filename).st_size
|
||||
|
||||
def getmtime(filename):
|
||||
"""Return the last modification time of a file, reported by os.stat()"""
|
||||
st = os.stat(filename)
|
||||
return st[stat.ST_MTIME]
|
||||
return os.stat(filename).st_mtime
|
||||
|
||||
def getatime(filename):
|
||||
"""Return the last access time of a file, reported by os.stat()"""
|
||||
st = os.stat(filename)
|
||||
return st[stat.ST_ATIME]
|
||||
return os.stat(filename).st_atime
|
||||
|
||||
|
||||
# Is a path a symbolic link?
|
||||
|
@ -260,7 +257,7 @@ def isdir(path):
|
|||
st = os.stat(path)
|
||||
except os.error:
|
||||
return False
|
||||
return stat.S_ISDIR(st[stat.ST_MODE])
|
||||
return stat.S_ISDIR(st.st_mode)
|
||||
|
||||
|
||||
# Is a path a regular file?
|
||||
|
@ -273,7 +270,7 @@ def isfile(path):
|
|||
st = os.stat(path)
|
||||
except os.error:
|
||||
return False
|
||||
return stat.S_ISREG(st[stat.ST_MODE])
|
||||
return stat.S_ISREG(st.st_mode)
|
||||
|
||||
|
||||
# Is a path a mount point? Either a root (with or without drive letter)
|
||||
|
|
|
@ -175,18 +175,15 @@ def commonprefix(m):
|
|||
|
||||
def getsize(filename):
|
||||
"""Return the size of a file, reported by os.stat()"""
|
||||
st = os.stat(filename)
|
||||
return st[stat.ST_SIZE]
|
||||
return os.stat(filename).st_size
|
||||
|
||||
def getmtime(filename):
|
||||
"""Return the last modification time of a file, reported by os.stat()"""
|
||||
st = os.stat(filename)
|
||||
return st[stat.ST_MTIME]
|
||||
return os.stat(filename).st_mtime
|
||||
|
||||
def getatime(filename):
|
||||
"""Return the last access time of a file, reported by os.stat()"""
|
||||
st = os.stat(filename)
|
||||
return st[stat.ST_ATIME]
|
||||
return os.stat(filename).st_atime
|
||||
|
||||
|
||||
# Is a path a symbolic link?
|
||||
|
@ -217,7 +214,7 @@ def isdir(path):
|
|||
st = os.stat(path)
|
||||
except os.error:
|
||||
return False
|
||||
return stat.S_ISDIR(st[stat.ST_MODE])
|
||||
return stat.S_ISDIR(st.st_mode)
|
||||
|
||||
|
||||
# Is a path a regular file?
|
||||
|
@ -230,7 +227,7 @@ def isfile(path):
|
|||
st = os.stat(path)
|
||||
except os.error:
|
||||
return False
|
||||
return stat.S_ISREG(st[stat.ST_MODE])
|
||||
return stat.S_ISREG(st.st_mode)
|
||||
|
||||
|
||||
# Is a path a mount point? Either a root (with or without drive letter)
|
||||
|
|
|
@ -136,18 +136,15 @@ def commonprefix(m):
|
|||
|
||||
def getsize(filename):
|
||||
"""Return the size of a file, reported by os.stat()."""
|
||||
st = os.stat(filename)
|
||||
return st[stat.ST_SIZE]
|
||||
return os.stat(filename).st_size
|
||||
|
||||
def getmtime(filename):
|
||||
"""Return the last modification time of a file, reported by os.stat()."""
|
||||
st = os.stat(filename)
|
||||
return st[stat.ST_MTIME]
|
||||
return os.stat(filename).st_mtime
|
||||
|
||||
def getatime(filename):
|
||||
"""Return the last access time of a file, reported by os.stat()."""
|
||||
st = os.stat(filename)
|
||||
return st[stat.ST_ATIME]
|
||||
return os.stat(filename).st_atime
|
||||
|
||||
|
||||
# Is a path a symbolic link?
|
||||
|
@ -159,7 +156,7 @@ def islink(path):
|
|||
st = os.lstat(path)
|
||||
except (os.error, AttributeError):
|
||||
return False
|
||||
return stat.S_ISLNK(st[stat.ST_MODE])
|
||||
return stat.S_ISLNK(st.st_mode)
|
||||
|
||||
|
||||
# Does a path exist?
|
||||
|
@ -184,7 +181,7 @@ def isdir(path):
|
|||
st = os.stat(path)
|
||||
except os.error:
|
||||
return False
|
||||
return stat.S_ISDIR(st[stat.ST_MODE])
|
||||
return stat.S_ISDIR(st.st_mode)
|
||||
|
||||
|
||||
# Is a path a regular file?
|
||||
|
@ -197,7 +194,7 @@ def isfile(path):
|
|||
st = os.stat(path)
|
||||
except os.error:
|
||||
return False
|
||||
return stat.S_ISREG(st[stat.ST_MODE])
|
||||
return stat.S_ISREG(st.st_mode)
|
||||
|
||||
|
||||
# Are two filenames really pointing to the same file?
|
||||
|
@ -224,8 +221,8 @@ def sameopenfile(fp1, fp2):
|
|||
|
||||
def samestat(s1, s2):
|
||||
"""Test whether two stat buffers reference the same file"""
|
||||
return s1[stat.ST_INO] == s2[stat.ST_INO] and \
|
||||
s1[stat.ST_DEV] == s2[stat.ST_DEV]
|
||||
return s1.st_ino == s2.st_ino and \
|
||||
s1.st_dev == s2.st_dev
|
||||
|
||||
|
||||
# Is a path a mount point?
|
||||
|
@ -238,12 +235,12 @@ def ismount(path):
|
|||
s2 = os.stat(join(path, '..'))
|
||||
except os.error:
|
||||
return False # It doesn't exist -- so not a mount point :-)
|
||||
dev1 = s1[stat.ST_DEV]
|
||||
dev2 = s2[stat.ST_DEV]
|
||||
dev1 = s1.st_dev
|
||||
dev2 = s2.st_dev
|
||||
if dev1 != dev2:
|
||||
return True # path/.. on a different device as path
|
||||
ino1 = s1[stat.ST_INO]
|
||||
ino2 = s2[stat.ST_INO]
|
||||
ino1 = s1.st_ino
|
||||
ino2 = s2.st_ino
|
||||
if ino1 == ino2:
|
||||
return True # path/.. is the same i-node as path
|
||||
return False
|
||||
|
|
|
@ -108,7 +108,7 @@ def load_stats(self, arg):
|
|||
f.close()
|
||||
try:
|
||||
file_stats = os.stat(arg)
|
||||
arg = time.ctime(file_stats[8]) + " " + arg
|
||||
arg = time.ctime(file_stats.st_mtime) + " " + arg
|
||||
except: # in case this is not unix
|
||||
pass
|
||||
self.files = [ arg ]
|
||||
|
|
|
@ -46,9 +46,9 @@ def compile(file, cfile=None, dfile=None):
|
|||
import os, marshal, __builtin__
|
||||
f = open(file, 'U')
|
||||
try:
|
||||
timestamp = long(os.fstat(f.fileno())[8])
|
||||
timestamp = long(os.fstat(f.fileno()).st_mtime)
|
||||
except AttributeError:
|
||||
timestamp = long(os.stat(file)[8])
|
||||
timestamp = long(os.stat(file).st_mtime)
|
||||
codestring = f.read()
|
||||
# If parsing from a string, line breaks are \n (see parsetok.c:tok_nextc)
|
||||
# Replace will return original string if pattern is not found, so
|
||||
|
|
|
@ -43,7 +43,7 @@ class or function within a module or module in a package. If the
|
|||
# the current directory is changed with os.chdir(), an incorrect
|
||||
# path will be displayed.
|
||||
|
||||
import sys, imp, os, stat, re, types, inspect
|
||||
import sys, imp, os, re, types, inspect
|
||||
from repr import Repr
|
||||
from string import expandtabs, find, join, lower, split, strip, rfind, rstrip
|
||||
|
||||
|
@ -153,7 +153,7 @@ def ispackage(path):
|
|||
|
||||
def synopsis(filename, cache={}):
|
||||
"""Get the one-line summary out of a module file."""
|
||||
mtime = os.stat(filename)[stat.ST_MTIME]
|
||||
mtime = os.stat(filename).st_mtime
|
||||
lastupdate, result = cache.get(filename, (0, None))
|
||||
if lastupdate < mtime:
|
||||
info = inspect.getmoduleinfo(filename)
|
||||
|
@ -1698,7 +1698,7 @@ class ModuleScanner(Scanner):
|
|||
def __init__(self):
|
||||
roots = map(lambda dir: (dir, ''), pathdirs())
|
||||
Scanner.__init__(self, roots, self.submodules, self.isnewpackage)
|
||||
self.inodes = map(lambda (dir, pkg): os.stat(dir)[1], roots)
|
||||
self.inodes = map(lambda (dir, pkg): os.stat(dir).st_ino, roots)
|
||||
|
||||
def submodules(self, (dir, package)):
|
||||
children = []
|
||||
|
@ -1712,7 +1712,7 @@ def submodules(self, (dir, package)):
|
|||
return children
|
||||
|
||||
def isnewpackage(self, (dir, package)):
|
||||
inode = os.path.exists(dir) and os.stat(dir)[1]
|
||||
inode = os.path.exists(dir) and os.stat(dir).st_ino
|
||||
if not (os.path.islink(dir) and inode in self.inodes):
|
||||
self.inodes.append(inode) # detect circular symbolic links
|
||||
return ispackage(dir)
|
||||
|
|
|
@ -79,4 +79,4 @@ def isdir(path):
|
|||
st = stat(path)
|
||||
except _os.error:
|
||||
return False
|
||||
return S_ISDIR(st[ST_MODE])
|
||||
return S_ISDIR(st.st_mode)
|
||||
|
|
|
@ -52,7 +52,7 @@ def encode(in_file, out_file, name=None, mode=None):
|
|||
name = os.path.basename(in_file)
|
||||
if mode is None:
|
||||
try:
|
||||
mode = os.stat(in_file)[0]
|
||||
mode = os.stat(in_file).st_mode
|
||||
except AttributeError:
|
||||
pass
|
||||
in_file = open(in_file, 'rb')
|
||||
|
|
|
@ -373,7 +373,7 @@ def write(self, filename, arcname=None, compress_type=None):
|
|||
"""Put the bytes from filename into the archive under the name
|
||||
arcname."""
|
||||
st = os.stat(filename)
|
||||
mtime = time.localtime(st[8])
|
||||
mtime = time.localtime(st.st_mtime)
|
||||
date_time = mtime[0:6]
|
||||
# Create ZipInfo instance to store file information
|
||||
if arcname is None:
|
||||
|
@ -572,10 +572,10 @@ def _get_codename(self, pathname, basename):
|
|||
file_pyc = pathname + ".pyc"
|
||||
file_pyo = pathname + ".pyo"
|
||||
if os.path.isfile(file_pyo) and \
|
||||
os.stat(file_pyo)[8] >= os.stat(file_py)[8]:
|
||||
os.stat(file_pyo).st_mtime >= os.stat(file_py).st_mtime:
|
||||
fname = file_pyo # Use .pyo file
|
||||
elif not os.path.isfile(file_pyc) or \
|
||||
os.stat(file_pyc)[8] < os.stat(file_py)[8]:
|
||||
os.stat(file_pyc).st_mtime < os.stat(file_py).st_mtime:
|
||||
import py_compile
|
||||
if self.debug:
|
||||
print "Compiling", file_py
|
||||
|
|
Loading…
Reference in New Issue