-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathFileSystemAccess.py
More file actions
277 lines (192 loc) · 11.1 KB
/
FileSystemAccess.py
File metadata and controls
277 lines (192 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
import builtins
import io
import os
import stat
import tempfile
import shutil
open("file") # $ getAPathArgument="file"
open(file="file") # $ getAPathArgument="file"
o = open
o("file") # $ getAPathArgument="file"
o(file="file") # $ getAPathArgument="file"
builtins.open("file") # $ getAPathArgument="file"
builtins.open(file="file") # $ getAPathArgument="file"
io.open("file") # $ getAPathArgument="file"
io.open(file="file") # $ getAPathArgument="file"
io.open_code("file") # $ getAPathArgument="file"
io.FileIO("file") # $ getAPathArgument="file"
f = open("path") # $ getAPathArgument="path"
f.write("foo") # $ getAPathArgument="path" fileWriteData="foo"
lines = ["foo"]
f.writelines(lines) # $ getAPathArgument="path" fileWriteData=lines
def through_function(open_file):
open_file.write("foo") # $ fileWriteData="foo" getAPathArgument="path"
through_function(f)
# os.path
os.path.exists("path") # $ getAPathArgument="path"
os.path.exists(path="path") # $ getAPathArgument="path"
os.path.isfile("path") # $ getAPathArgument="path"
os.path.isfile(path="path") # $ getAPathArgument="path"
os.path.isdir("s") # $ getAPathArgument="s"
os.path.isdir(s="s") # $ getAPathArgument="s"
os.path.islink("path") # $ getAPathArgument="path"
os.path.islink(path="path") # $ getAPathArgument="path"
os.path.ismount("path") # $ getAPathArgument="path"
os.path.ismount(path="path") # $ getAPathArgument="path"
os.path.samefile("f1", "f2") # $ getAPathArgument="f1" getAPathArgument="f2"
os.path.samefile(f1="f1", f2="f2") # $ getAPathArgument="f1" getAPathArgument="f2"
# actual os.path implementations
import posixpath
import ntpath
import genericpath
posixpath.exists("path") # $ getAPathArgument="path"
posixpath.exists(path="path") # $ getAPathArgument="path"
ntpath.exists("path") # $ getAPathArgument="path"
ntpath.exists(path="path") # $ getAPathArgument="path"
genericpath.exists("path") # $ getAPathArgument="path"
genericpath.exists(path="path") # $ getAPathArgument="path"
# os
def test_fsencode_fsdecode():
# notice that this does not make a file system access, but performs encoding/decoding.
os.fsencode("filename") # $ encodeInput="filename" encodeOutput=os.fsencode(..) encodeFormat=filesystem
os.fsencode(filename="filename") # $ encodeInput="filename" encodeOutput=os.fsencode(..) encodeFormat=filesystem
os.fsdecode("filename") # $ decodeInput="filename" decodeOutput=os.fsdecode(..) decodeFormat=filesystem
os.fsdecode(filename="filename") # $ decodeInput="filename" decodeOutput=os.fsdecode(..) decodeFormat=filesystem
def test_fspath():
# notice that this does not make a file system access, but returns the path
# representation of a path-like object.
ensure_tainted(
TAINTED_STRING, # $ tainted
os.fspath(TAINTED_STRING), # $ tainted
os.fspath(path=TAINTED_STRING), # $ tainted
)
os.open("path", os.O_RDONLY) # $ getAPathArgument="path"
os.open(path="path", flags=os.O_RDONLY) # $ getAPathArgument="path"
os.access("path", os.R_OK) # $ getAPathArgument="path"
os.access(path="path", mode=os.R_OK) # $ getAPathArgument="path"
os.chdir("path") # $ getAPathArgument="path"
os.chdir(path="path") # $ getAPathArgument="path"
os.chflags("path", stat.UF_NODUMP) # $ getAPathArgument="path"
os.chflags(path="path", flags=stat.UF_NODUMP) # $ getAPathArgument="path"
os.chmod("path", 0o700) # $ getAPathArgument="path"
os.chmod(path="path", mode=0o700) # $ getAPathArgument="path"
os.chown("path", -1, -1) # $ getAPathArgument="path"
os.chown(path="path", uid=-1, gid=-1) # $ getAPathArgument="path"
# unix only
os.chroot("path") # $ getAPathArgument="path"
os.chroot(path="path") # $ getAPathArgument="path"
# unix only
os.lchflags("path", stat.UF_NODUMP) # $ getAPathArgument="path"
os.lchflags(path="path", flags=stat.UF_NODUMP) # $ getAPathArgument="path"
# unix only
os.lchmod("path", 0o700) # $ getAPathArgument="path"
os.lchmod(path="path", mode=0o700) # $ getAPathArgument="path"
# unix only
os.lchown("path", -1, -1) # $ getAPathArgument="path"
os.lchown(path="path", uid=-1, gid=-1) # $ getAPathArgument="path"
os.link("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
os.link(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
os.listdir("path") # $ getAPathArgument="path"
os.listdir(path="path") # $ getAPathArgument="path"
os.lstat("path") # $ getAPathArgument="path"
os.lstat(path="path") # $ getAPathArgument="path"
os.mkdir("path") # $ getAPathArgument="path"
os.mkdir(path="path") # $ getAPathArgument="path"
os.makedirs("name") # $ getAPathArgument="name"
os.makedirs(name="name") # $ getAPathArgument="name"
os.mkfifo("path") # $ getAPathArgument="path"
os.mkfifo(path="path") # $ getAPathArgument="path"
os.mknod("path") # $ getAPathArgument="path"
os.mknod(path="path") # $ getAPathArgument="path"
os.pathconf("path", "name") # $ getAPathArgument="path"
os.pathconf(path="path", name="name") # $ getAPathArgument="path"
os.readlink("path") # $ getAPathArgument="path"
os.readlink(path="path") # $ getAPathArgument="path"
os.remove("path") # $ getAPathArgument="path"
os.remove(path="path") # $ getAPathArgument="path"
os.removedirs("name") # $ getAPathArgument="name"
os.removedirs(name="name") # $ getAPathArgument="name"
os.rename("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
os.rename(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
os.renames("old", "new") # $ getAPathArgument="old" getAPathArgument="new"
os.renames(old="old", new="new") # $ getAPathArgument="old" getAPathArgument="new"
os.replace("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
os.replace(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
os.rmdir("path") # $ getAPathArgument="path"
os.rmdir(path="path") # $ getAPathArgument="path"
os.scandir("path") # $ getAPathArgument="path"
os.scandir(path="path") # $ getAPathArgument="path"
os.stat("path") # $ getAPathArgument="path"
os.stat(path="path") # $ getAPathArgument="path"
os.statvfs("path") # $ getAPathArgument="path"
os.statvfs(path="path") # $ getAPathArgument="path"
os.symlink("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
os.symlink(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
os.truncate("path", 42) # $ getAPathArgument="path"
os.truncate(path="path", length=42) # $ getAPathArgument="path"
os.unlink("path") # $ getAPathArgument="path"
os.unlink(path="path") # $ getAPathArgument="path"
os.utime("path") # $ getAPathArgument="path"
os.utime(path="path") # $ getAPathArgument="path"
os.walk("top") # $ getAPathArgument="top"
os.walk(top="top") # $ getAPathArgument="top"
os.fwalk("top") # $ getAPathArgument="top"
os.fwalk(top="top") # $ getAPathArgument="top"
# Linux only
os.getxattr("path", "attribute") # $ getAPathArgument="path"
os.getxattr(path="path", attribute="attribute") # $ getAPathArgument="path"
# Linux only
os.listxattr("path") # $ getAPathArgument="path"
os.listxattr(path="path") # $ getAPathArgument="path"
# Linux only
os.removexattr("path", "attribute") # $ getAPathArgument="path"
os.removexattr(path="path", attribute="attribute") # $ getAPathArgument="path"
# Linux only
os.setxattr("path", "attribute", "value") # $ getAPathArgument="path"
os.setxattr(path="path", attribute="attribute", value="value") # $ getAPathArgument="path"
# Windows only
os.add_dll_directory("path") # $ getAPathArgument="path"
os.add_dll_directory(path="path") # $ getAPathArgument="path"
# for `os.exec*`, `os.spawn*`, and `os.posix_spawn*` functions, see the
# `SystemCommandExecution.py` file.
# Windows only
os.startfile("path") # $ getAPathArgument="path"
os.startfile(path="path") # $ getAPathArgument="path"
# ------------------------------------------------------------------------------
# tempfile
# ------------------------------------------------------------------------------
# _mkstemp_inner does `_os.path.join(dir, pre + name + suf)`
tempfile.mkstemp("suffix", "prefix", "dir") # $ getAPathArgument="suffix" getAPathArgument="prefix" getAPathArgument="dir"
tempfile.mkstemp(suffix="suffix", prefix="prefix", dir="dir") # $ getAPathArgument="suffix" getAPathArgument="prefix" getAPathArgument="dir"
tempfile.NamedTemporaryFile('w+b', -1, None, None, "suffix", "prefix", "dir") # $ getAPathArgument="suffix" getAPathArgument="prefix" getAPathArgument="dir"
tempfile.NamedTemporaryFile(suffix="suffix", prefix="prefix", dir="dir") # $ getAPathArgument="suffix" getAPathArgument="prefix" getAPathArgument="dir"
tempfile.TemporaryFile('w+b', -1, None, None, "suffix", "prefix", "dir") # $ getAPathArgument="suffix" getAPathArgument="prefix" getAPathArgument="dir"
tempfile.TemporaryFile(suffix="suffix", prefix="prefix", dir="dir") # $ getAPathArgument="suffix" getAPathArgument="prefix" getAPathArgument="dir"
tempfile.SpooledTemporaryFile(0, 'w+b', -1, None, None, "suffix", "prefix", "dir") # $ getAPathArgument="suffix" getAPathArgument="prefix" getAPathArgument="dir"
tempfile.SpooledTemporaryFile(suffix="suffix", prefix="prefix", dir="dir") # $ getAPathArgument="suffix" getAPathArgument="prefix" getAPathArgument="dir"
# mkdtemp does `_os.path.join(dir, prefix + name + suffix)`
tempfile.mkdtemp("suffix", "prefix", "dir") # $ getAPathArgument="suffix" getAPathArgument="prefix" getAPathArgument="dir"
tempfile.mkdtemp(suffix="suffix", prefix="prefix", dir="dir") # $ getAPathArgument="suffix" getAPathArgument="prefix" getAPathArgument="dir"
tempfile.TemporaryDirectory("suffix", "prefix", "dir") # $ getAPathArgument="suffix" getAPathArgument="prefix" getAPathArgument="dir"
tempfile.TemporaryDirectory(suffix="suffix", prefix="prefix", dir="dir") # $ getAPathArgument="suffix" getAPathArgument="prefix" getAPathArgument="dir"
# ------------------------------------------------------------------------------
# shutil
# ------------------------------------------------------------------------------
shutil.rmtree("path") # $ getAPathArgument="path"
shutil.rmtree(path="path") # $ getAPathArgument="path"
shutil.copyfile("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
shutil.copyfile(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
shutil.copy("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
shutil.copy(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
shutil.copy2("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
shutil.copy2(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
shutil.copytree("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
shutil.copytree(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
shutil.move("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
shutil.move(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
shutil.copymode("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
shutil.copymode(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
shutil.copystat("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
shutil.copystat(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
shutil.disk_usage("path") # $ getAPathArgument="path"
shutil.disk_usage(path="path") # $ getAPathArgument="path"