Replaced obsolete stat module constants with equivalent attributes · python/cpython@32200ae · GitHub
Skip to content

Commit 32200ae

Browse files
committed
Replaced obsolete stat module constants with equivalent attributes
1 parent 16e3c42 commit 32200ae

18 files changed

Lines changed: 59 additions & 79 deletions

Lib/CGIHTTPServer.py

Lines changed: 1 addition & 1 deletion

Lib/compileall.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"""
1414

1515
import os
16-
import stat
1716
import sys
1817
import py_compile
1918

@@ -56,8 +55,8 @@ def compile_dir(dir, maxlevels=10, ddir=None,
5655
head, tail = name[:-3], name[-3:]
5756
if tail == '.py':
5857
cfile = fullname + (__debug__ and 'c' or 'o')
59-
ftime = os.stat(fullname)[stat.ST_MTIME]
60-
try: ctime = os.stat(cfile)[stat.ST_MTIME]
58+
ftime = os.stat(fullname).st_mtime
59+
try: ctime = os.stat(cfile).st_mtime
6160
except os.error: ctime = 0
6261
if (ctime > ftime) and not force: continue
6362
if not quiet:

Lib/dircache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def listdir(path):
2323
except KeyError:
2424
cached_mtime, list = -1, []
2525
try:
26-
mtime = os.stat(path)[8]
26+
mtime = os.stat(path).st_mtime
2727
except os.error:
2828
return []
2929
if mtime != cached_mtime:

Lib/dospath.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,16 @@ def commonprefix(m):
123123

124124
def getsize(filename):
125125
"""Return the size of a file, reported by os.stat()."""
126-
st = os.stat(filename)
127-
return st[stat.ST_SIZE]
126+
return os.stat(filename).st_size
128127

129128
def getmtime(filename):
130129
"""Return the last modification time of a file, reported by os.stat()."""
131-
st = os.stat(filename)
132-
return st[stat.ST_MTIME]
130+
return os.stat(filename).st_mtime
133131

134132
def getatime(filename):
135133
"""Return the last access time of a file, reported by os.stat()."""
136-
st = os.stat(filename)
137-
return st[stat.ST_ATIME]
138134

135+
return os.stat(filename).st_atime
139136

140137
def islink(path):
141138
"""Is a path a symbolic link?
@@ -162,7 +159,7 @@ def isdir(path):
162159
st = os.stat(path)
163160
except os.error:
164161
return False
165-
return stat.S_ISDIR(st[stat.ST_MODE])
162+
return stat.S_ISDIR(st.st_mode)
166163

167164

168165
def isfile(path):
@@ -172,7 +169,7 @@ def isfile(path):
172169
st = os.stat(path)
173170
except os.error:
174171
return False
175-
return stat.S_ISREG(st[stat.ST_MODE])
172+
return stat.S_ISREG(st.st_mode)
176173

177174

178175
def ismount(path):

Lib/filecmp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def cmp(f1, f2, shallow=1, use_statcache=0):
6464
return outcome
6565

6666
def _sig(st):
67-
return (stat.S_IFMT(st[stat.ST_MODE]),
68-
st[stat.ST_SIZE],
69-
st[stat.ST_MTIME])
67+
return (stat.S_IFMT(st.st_mode),
68+
st.st_size,
69+
st.st_mtime)
7070

7171
def _do_cmp(f1, f2):
7272
bufsize = BUFSIZE
@@ -199,8 +199,8 @@ def phase2(self): # Distinguish files, directories, funnies
199199
ok = 0
200200

201201
if ok:
202-
a_type = stat.S_IFMT(a_stat[stat.ST_MODE])
203-
b_type = stat.S_IFMT(b_stat[stat.ST_MODE])
202+
a_type = stat.S_IFMT(a_stat.st_mode)
203+
b_type = stat.S_IFMT(b_stat.st_mode)
204204
if a_type != b_type:
205205
self.common_funny.append(x)
206206
elif stat.S_ISDIR(a_type):

Lib/imputil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,15 @@ def _os_path_isdir(pathname):
484484
s = _os_stat(pathname)
485485
except OSError:
486486
return None
487-
return (s[0] & 0170000) == 0040000
487+
return (s.st_mode & 0170000) == 0040000
488488

489489
def _timestamp(pathname):
490490
"Return the file modification time as a Long."
491491
try:
492492
s = _os_stat(pathname)
493493
except OSError:
494494
return None
495-
return long(s[8])
495+
return long(s.st_mtime)
496496

497497

498498
######################################################################

Lib/linecache.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import sys
99
import os
10-
from stat import *
1110

1211
__all__ = ["getline","clearcache","checkcache"]
1312

@@ -52,7 +51,7 @@ def checkcache():
5251
except os.error:
5352
del cache[filename]
5453
continue
55-
if size != stat[ST_SIZE] or mtime != stat[ST_MTIME]:
54+
if size != stat.st_size or mtime != stat.st_mtime:
5655
del cache[filename]
5756

5857

@@ -96,6 +95,6 @@ def updatecache(filename):
9695
except IOError, msg:
9796
## print '*** Cannot open', fullname, ':', msg
9897
return []
99-
size, mtime = stat[ST_SIZE], stat[ST_MTIME]
98+
size, mtime = stat.st_size, stat.st_mtime
10099
cache[filename] = size, mtime, lines, fullname
101100
return lines

Lib/macpath.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,22 @@ def isdir(s):
100100
st = os.stat(s)
101101
except os.error:
102102
return 0
103-
return S_ISDIR(st[ST_MODE])
103+
return S_ISDIR(st.st_mode)
104104

105105

106106
# Get size, mtime, atime of files.
107107

108108
def getsize(filename):
109109
"""Return the size of a file, reported by os.stat()."""
110-
st = os.stat(filename)
111-
return st[ST_SIZE]
110+
return os.stat(filename).st_size
112111

113112
def getmtime(filename):
114113
"""Return the last modification time of a file, reported by os.stat()."""
115-
st = os.stat(filename)
116-
return st[ST_MTIME]
114+
return os.stat(filename).st_mtime
117115

118116
def getatime(filename):
119117
"""Return the last access time of a file, reported by os.stat()."""
120-
st = os.stat(filename)
121-
return st[ST_ATIME]
118+
return os.stat(filename).st_atime
122119

123120

124121
def islink(s):
@@ -138,7 +135,7 @@ def isfile(s):
138135
st = os.stat(s)
139136
except os.error:
140137
return False
141-
return S_ISREG(st[ST_MODE])
138+
return S_ISREG(st.st_mode)
142139

143140

144141
def exists(s):

Lib/mhlib.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474

7575
import os
7676
import sys
77-
from stat import ST_NLINK
7877
import re
7978
import mimetools
8079
import multifile
@@ -155,8 +154,7 @@ def listsubfolders(self, name):
155154
fullname = os.path.join(self.path, name)
156155
# Get the link count so we can avoid listing folders
157156
# that have no subfolders.
158-
st = os.stat(fullname)
159-
nlinks = st[ST_NLINK]
157+
nlinks = os.stat(fullname).st_nlink
160158
if nlinks <= 2:
161159
return []
162160
subfolders = []
@@ -183,8 +181,7 @@ def listallsubfolders(self, name):
183181
fullname = os.path.join(self.path, name)
184182
# Get the link count so we can avoid listing folders
185183
# that have no subfolders.
186-
st = os.stat(fullname)
187-
nlinks = st[ST_NLINK]
184+
nlinks = os.stat(fullname).st_nlink
188185
if nlinks <= 2:
189186
return []
190187
subfolders = []

Lib/ntpath.py

Lines changed: 5 additions & 8 deletions

0 commit comments

Comments
 (0)