Skip to content

Commit 6356fdb

Browse files
committed
Tidy up stat
1 parent cb095d6 commit 6356fdb

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

qiling/os/posix/stat.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,30 @@
66
import os
77

88
class StatBase:
9-
def __init__(self):
10-
self._stat_buf = None
9+
def __init__(self, stat: os.stat_result):
10+
self._stat_buf = stat
1111

1212
# Never iterate this object!
1313
def __getitem__(self, key):
1414
if type(key) is not str:
1515
raise TypeError
16-
if not key.startswith("__") and key in dir(self._stat_buf):
16+
17+
if not key.startswith("__") and hasattr(self._stat_buf, key):
1718
return self._stat_buf.__getattribute__(key)
19+
1820
return 0
19-
21+
2022
def __getattr__(self, key):
2123
return self.__getitem__(key)
24+
2225
class Stat(StatBase):
2326
def __init__(self, path):
24-
super(Stat, self).__init__()
25-
self._stat_buf = os.stat(path)
27+
super().__init__(os.stat(path))
2628

2729
class Fstat(StatBase):
28-
def __init__(self, fd):
29-
super(Fstat, self).__init__()
30-
self._stat_buf = os.fstat(fd)
30+
def __init__(self, fd: int):
31+
super().__init__(os.fstat(fd))
3132

3233
class Lstat(StatBase):
3334
def __init__(self, path):
34-
super(Lstat, self).__init__()
35-
self._stat_buf = os.lstat(path)
36-
37-
35+
super().__init__(os.lstat(path))

0 commit comments

Comments
 (0)