@@ -19,31 +19,15 @@ private module Stdlib {
19
19
/** Gets a reference to the `os` module. */
20
20
API:: Node os ( ) { result = API:: moduleImport ( "os" ) }
21
21
22
- /**
23
- * Gets a reference to the attribute `attr_name` of the `os` module.
24
- * WARNING: Only holds for a few predefined attributes.
25
- *
26
- * For example, using `"system"` will get all uses of `os.system`.
27
- */
28
- private API:: Node os_attr ( string attr_name ) { result = os ( ) .getMember ( attr_name ) }
29
-
30
22
/** Provides models for the `os` module. */
31
23
module os {
32
24
/** Gets a reference to the `os.path` module. */
33
- API:: Node path ( ) { result = os_attr ( "path" ) }
25
+ API:: Node path ( ) { result = os ( ) . getMember ( "path" ) }
34
26
35
27
/** Provides models for the `os.path` module */
36
28
module path {
37
- /**
38
- * Gets a reference to the attribute `attr_name` of the `os.path` module.
39
- * WARNING: Only holds for a few predefined attributes.
40
- *
41
- * For example, using `attr_name = "join"` will get all uses of `os.path.join`.
42
- */
43
- API:: Node path_attr ( string attr_name ) { result = path ( ) .getMember ( attr_name ) }
44
-
45
29
/** Gets a reference to the `os.path.join` function. */
46
- API:: Node join ( ) { result = path_attr ( "join" ) }
30
+ API:: Node join ( ) { result = path ( ) . getMember ( "join" ) }
47
31
}
48
32
}
49
33
@@ -52,7 +36,7 @@ private module Stdlib {
52
36
* See https://docs.python.org/3/library/os.path.html#os.path.normpath
53
37
*/
54
38
private class OsPathNormpathCall extends Path:: PathNormalization:: Range , DataFlow:: CallCfgNode {
55
- OsPathNormpathCall ( ) { this = os:: path:: path_attr ( "normpath" ) .getACall ( ) }
39
+ OsPathNormpathCall ( ) { this = os:: path ( ) . getMember ( "normpath" ) .getACall ( ) }
56
40
57
41
DataFlow:: Node getPathArg ( ) {
58
42
result .asCfgNode ( ) in [ node .getArg ( 0 ) , node .getArgByName ( "path" ) ]
@@ -73,10 +57,8 @@ private module Stdlib {
73
57
* A call to `os.path.abspath`.
74
58
* See https://docs.python.org/3/library/os.path.html#os.path.abspath
75
59
*/
76
- private class OsPathAbspathCall extends Path:: PathNormalization:: Range , DataFlow:: CfgNode {
77
- override CallNode node ;
78
-
79
- OsPathAbspathCall ( ) { this = os:: path:: path_attr ( "abspath" ) .getACall ( ) }
60
+ private class OsPathAbspathCall extends Path:: PathNormalization:: Range , DataFlow:: CallCfgNode {
61
+ OsPathAbspathCall ( ) { this = os:: path ( ) .getMember ( "abspath" ) .getACall ( ) }
80
62
81
63
DataFlow:: Node getPathArg ( ) {
82
64
result .asCfgNode ( ) in [ node .getArg ( 0 ) , node .getArgByName ( "path" ) ]
@@ -97,10 +79,8 @@ private module Stdlib {
97
79
* A call to `os.path.realpath`.
98
80
* See https://docs.python.org/3/library/os.path.html#os.path.realpath
99
81
*/
100
- private class OsPathRealpathCall extends Path:: PathNormalization:: Range , DataFlow:: CfgNode {
101
- override CallNode node ;
102
-
103
- OsPathRealpathCall ( ) { this = os:: path:: path_attr ( "realpath" ) .getACall ( ) }
82
+ private class OsPathRealpathCall extends Path:: PathNormalization:: Range , DataFlow:: CallCfgNode {
83
+ OsPathRealpathCall ( ) { this = os:: path ( ) .getMember ( "realpath" ) .getACall ( ) }
104
84
105
85
DataFlow:: Node getPathArg ( ) {
106
86
result .asCfgNode ( ) in [ node .getArg ( 0 ) , node .getArgByName ( "path" ) ]
@@ -121,10 +101,8 @@ private module Stdlib {
121
101
* A call to `os.system`.
122
102
* See https://docs.python.org/3/library/os.html#os.system
123
103
*/
124
- private class OsSystemCall extends SystemCommandExecution:: Range , DataFlow:: CfgNode {
125
- override CallNode node ;
126
-
127
- OsSystemCall ( ) { this = os_attr ( "system" ) .getACall ( ) }
104
+ private class OsSystemCall extends SystemCommandExecution:: Range , DataFlow:: CallCfgNode {
105
+ OsSystemCall ( ) { this = os ( ) .getMember ( "system" ) .getACall ( ) }
128
106
129
107
override DataFlow:: Node getCommand ( ) { result .asCfgNode ( ) = node .getArg ( 0 ) }
130
108
}
@@ -137,13 +115,12 @@ private module Stdlib {
137
115
* Although deprecated since version 2.6, they still work in 2.7.
138
116
* See https://docs.python.org/2.7/library/os.html#os.popen2
139
117
*/
140
- private class OsPopenCall extends SystemCommandExecution:: Range , DataFlow:: CfgNode {
141
- override CallNode node ;
118
+ private class OsPopenCall extends SystemCommandExecution:: Range , DataFlow:: CallCfgNode {
142
119
string name ;
143
120
144
121
OsPopenCall ( ) {
145
122
name in [ "popen" , "popen2" , "popen3" , "popen4" ] and
146
- this = os_attr ( name ) .getACall ( )
123
+ this = os ( ) . getMember ( name ) .getACall ( )
147
124
}
148
125
149
126
override DataFlow:: Node getCommand ( ) {
@@ -158,13 +135,11 @@ private module Stdlib {
158
135
* A call to any of the `os.exec*` functions
159
136
* See https://docs.python.org/3.8/library/os.html#os.execl
160
137
*/
161
- private class OsExecCall extends SystemCommandExecution:: Range , DataFlow:: CfgNode {
162
- override CallNode node ;
163
-
138
+ private class OsExecCall extends SystemCommandExecution:: Range , DataFlow:: CallCfgNode {
164
139
OsExecCall ( ) {
165
140
exists ( string name |
166
141
name in [ "execl" , "execle" , "execlp" , "execlpe" , "execv" , "execve" , "execvp" , "execvpe" ] and
167
- this = os_attr ( name ) .getACall ( )
142
+ this = os ( ) . getMember ( name ) .getACall ( )
168
143
)
169
144
}
170
145
@@ -175,15 +150,13 @@ private module Stdlib {
175
150
* A call to any of the `os.spawn*` functions
176
151
* See https://docs.python.org/3.8/library/os.html#os.spawnl
177
152
*/
178
- private class OsSpawnCall extends SystemCommandExecution:: Range , DataFlow:: CfgNode {
179
- override CallNode node ;
180
-
153
+ private class OsSpawnCall extends SystemCommandExecution:: Range , DataFlow:: CallCfgNode {
181
154
OsSpawnCall ( ) {
182
155
exists ( string name |
183
156
name in [
184
157
"spawnl" , "spawnle" , "spawnlp" , "spawnlpe" , "spawnv" , "spawnve" , "spawnvp" , "spawnvpe"
185
158
] and
186
- this = os_attr ( name ) .getACall ( )
159
+ this = os ( ) . getMember ( name ) .getACall ( )
187
160
)
188
161
}
189
162
@@ -194,10 +167,8 @@ private module Stdlib {
194
167
* A call to any of the `os.posix_spawn*` functions
195
168
* See https://docs.python.org/3.8/library/os.html#os.posix_spawn
196
169
*/
197
- private class OsPosixSpawnCall extends SystemCommandExecution:: Range , DataFlow:: CfgNode {
198
- override CallNode node ;
199
-
200
- OsPosixSpawnCall ( ) { this = os_attr ( [ "posix_spawn" , "posix_spawnp" ] ) .getACall ( ) }
170
+ private class OsPosixSpawnCall extends SystemCommandExecution:: Range , DataFlow:: CallCfgNode {
171
+ OsPosixSpawnCall ( ) { this = os ( ) .getMember ( [ "posix_spawn" , "posix_spawnp" ] ) .getACall ( ) }
201
172
202
173
override DataFlow:: Node getCommand ( ) { result .asCfgNode ( ) = node .getArg ( 0 ) }
203
174
}
@@ -218,29 +189,17 @@ private module Stdlib {
218
189
// subprocess
219
190
// ---------------------------------------------------------------------------
220
191
/** Gets a reference to the `subprocess` module. */
221
- deprecated DataFlow:: Node subprocess ( ) { result = API:: moduleImport ( "subprocess" ) .getAUse ( ) }
222
-
223
- /**
224
- * Gets a reference to the attribute `attr_name` of the `subprocess` module.
225
- * WARNING: Only holds for a few predefined attributes.
226
- *
227
- * For example, using `attr_name = "Popen"` will get all uses of `subprocess.Popen`.
228
- */
229
- private DataFlow:: Node subprocess_attr ( string attr_name ) {
230
- result = API:: moduleImport ( "subprocess" ) .getMember ( attr_name ) .getAUse ( )
231
- }
192
+ API:: Node subprocess ( ) { result = API:: moduleImport ( "subprocess" ) }
232
193
233
194
/**
234
195
* A call to `subprocess.Popen` or helper functions (call, check_call, check_output, run)
235
196
* See https://docs.python.org/3.8/library/subprocess.html#subprocess.Popen
236
197
*/
237
- private class SubprocessPopenCall extends SystemCommandExecution:: Range , DataFlow:: CfgNode {
238
- override CallNode node ;
239
-
198
+ private class SubprocessPopenCall extends SystemCommandExecution:: Range , DataFlow:: CallCfgNode {
240
199
SubprocessPopenCall ( ) {
241
200
exists ( string name |
242
201
name in [ "Popen" , "call" , "check_call" , "check_output" , "run" ] and
243
- node . getFunction ( ) = subprocess_attr ( name ) .asCfgNode ( )
202
+ this = subprocess ( ) . getMember ( name ) .getACall ( )
244
203
)
245
204
}
246
205
@@ -311,17 +270,6 @@ private module Stdlib {
311
270
// ---------------------------------------------------------------------------
312
271
// marshal
313
272
// ---------------------------------------------------------------------------
314
- /** Gets a reference to the `marshal` module. */
315
- deprecated DataFlow:: Node marshal ( ) { result = API:: moduleImport ( "marshal" ) .getAUse ( ) }
316
-
317
- /** Provides models for the `marshal` module. */
318
- module marshal {
319
- /** Gets a reference to the `marshal.loads` function. */
320
- deprecated DataFlow:: Node loads ( ) {
321
- result = API:: moduleImport ( "marshal" ) .getMember ( "loads" ) .getAUse ( )
322
- }
323
- }
324
-
325
273
/**
326
274
* A call to `marshal.loads`
327
275
* See https://docs.python.org/3/library/marshal.html#marshal.loads
@@ -342,9 +290,7 @@ private module Stdlib {
342
290
// pickle
343
291
// ---------------------------------------------------------------------------
344
292
/** Gets a reference to the `pickle` module. */
345
- DataFlow:: Node pickle ( ) {
346
- result = API:: moduleImport ( [ "pickle" , "cPickle" , "_pickle" ] ) .getAUse ( )
347
- }
293
+ DataFlow:: Node pickle ( ) { result = API:: moduleImport ( [ "pickle" , "cPickle" , "_pickle" ] ) .getAUse ( ) }
348
294
349
295
/** Provides models for the `pickle` module. */
350
296
module pickle {
@@ -376,25 +322,15 @@ private module Stdlib {
376
322
/** Gets a reference to the `popen2` module (only available in Python 2). */
377
323
API:: Node popen2 ( ) { result = API:: moduleImport ( "popen2" ) }
378
324
379
- /**
380
- * Gets a reference to the attribute `attr_name` of the `popen2` module.
381
- * WARNING: Only holds for a few predefined attributes.
382
- */
383
- private API:: Node popen2_attr ( string attr_name ) {
384
- result = API:: moduleImport ( "popen2" ) .getMember ( attr_name )
385
- }
386
-
387
325
/**
388
326
* A call to any of the `popen.popen*` functions, or instantiation of a `popen.Popen*` class.
389
327
* See https://docs.python.org/2.7/library/popen2.html
390
328
*/
391
- private class Popen2PopenCall extends SystemCommandExecution:: Range , DataFlow:: CfgNode {
392
- override CallNode node ;
393
-
329
+ private class Popen2PopenCall extends SystemCommandExecution:: Range , DataFlow:: CallCfgNode {
394
330
Popen2PopenCall ( ) {
395
331
exists ( string name |
396
332
name in [ "popen2" , "popen3" , "popen4" , "Popen3" , "Popen4" ] and
397
- this = popen2_attr ( name ) .getACall ( )
333
+ this = popen2 ( ) . getMember ( name ) .getACall ( )
398
334
)
399
335
}
400
336
@@ -409,18 +345,12 @@ private module Stdlib {
409
345
/** Gets a reference to the `platform` module. */
410
346
API:: Node platform ( ) { result = API:: moduleImport ( "platform" ) }
411
347
412
- /**
413
- * Gets a reference to the attribute `attr_name` of the `platform` module.
414
- * WARNING: Only holds for a few predefined attributes.
415
- */
416
- private API:: Node platform_attr ( string attr_name ) { result = platform ( ) .getMember ( attr_name ) }
417
-
418
348
/**
419
349
* A call to the `platform.popen` function.
420
350
* See https://docs.python.org/2.7/library/platform.html#platform.popen
421
351
*/
422
352
private class PlatformPopenCall extends SystemCommandExecution:: Range , DataFlow:: CallCfgNode {
423
- PlatformPopenCall ( ) { this = platform_attr ( "popen" ) .getACall ( ) }
353
+ PlatformPopenCall ( ) { this = platform ( ) . getMember ( "popen" ) .getACall ( ) }
424
354
425
355
override DataFlow:: Node getCommand ( ) {
426
356
result .asCfgNode ( ) in [ node .getArg ( 0 ) , node .getArgByName ( "cmd" ) ]
@@ -500,12 +430,6 @@ private module Stdlib {
500
430
/** Gets a reference to the `base64` module. */
501
431
API:: Node base64 ( ) { result = API:: moduleImport ( "base64" ) }
502
432
503
- /**
504
- * Gets a reference to the attribute `attr_name` of the `base64` module.
505
- * WARNING: Only holds for a few predefined attributes.
506
- */
507
- private API:: Node base64_attr ( string attr_name ) { result = base64 ( ) .getMember ( attr_name ) }
508
-
509
433
/** A call to any of the encode functions in the `base64` module. */
510
434
private class Base64EncodeCall extends Encoding:: Range , DataFlow:: CallCfgNode {
511
435
string name ;
@@ -515,7 +439,7 @@ private module Stdlib {
515
439
"b64encode" , "standard_b64encode" , "urlsafe_b64encode" , "b32encode" , "b16encode" ,
516
440
"encodestring" , "a85encode" , "b85encode" , "encodebytes"
517
441
] and
518
- this = base64_attr ( name ) .getACall ( )
442
+ this = base64 ( ) . getMember ( name ) .getACall ( )
519
443
}
520
444
521
445
override DataFlow:: Node getAnInput ( ) { result .asCfgNode ( ) = node .getArg ( 0 ) }
@@ -547,7 +471,7 @@ private module Stdlib {
547
471
"b64decode" , "standard_b64decode" , "urlsafe_b64decode" , "b32decode" , "b16decode" ,
548
472
"decodestring" , "a85decode" , "b85decode" , "decodebytes"
549
473
] and
550
- this = base64_attr ( name ) .getACall ( )
474
+ this = base64 ( ) . getMember ( name ) .getACall ( )
551
475
}
552
476
553
477
override predicate mayExecuteInput ( ) { none ( ) }
@@ -578,18 +502,12 @@ private module Stdlib {
578
502
/** Gets a reference to the `json` module. */
579
503
API:: Node json ( ) { result = API:: moduleImport ( "json" ) }
580
504
581
- /**
582
- * Gets a reference to the attribute `attr_name` of the `json` module.
583
- * WARNING: Only holds for a few predefined attributes.
584
- */
585
- private API:: Node json_attr ( string attr_name ) { result = json ( ) .getMember ( attr_name ) }
586
-
587
505
/**
588
506
* A call to `json.loads`
589
507
* See https://docs.python.org/3/library/json.html#json.loads
590
508
*/
591
509
private class JsonLoadsCall extends Decoding:: Range , DataFlow:: CallCfgNode {
592
- JsonLoadsCall ( ) { this = json_attr ( "loads" ) .getACall ( ) }
510
+ JsonLoadsCall ( ) { this = json ( ) . getMember ( "loads" ) .getACall ( ) }
593
511
594
512
override predicate mayExecuteInput ( ) { none ( ) }
595
513
@@ -605,7 +523,7 @@ private module Stdlib {
605
523
* See https://docs.python.org/3/library/json.html#json.dumps
606
524
*/
607
525
private class JsonDumpsCall extends Encoding:: Range , DataFlow:: CallCfgNode {
608
- JsonDumpsCall ( ) { this = json_attr ( "dumps" ) .getACall ( ) }
526
+ JsonDumpsCall ( ) { this = json ( ) . getMember ( "dumps" ) .getACall ( ) }
609
527
610
528
override DataFlow:: Node getAnInput ( ) { result .asCfgNode ( ) = node .getArg ( 0 ) }
611
529
@@ -799,36 +717,24 @@ private module Stdlib {
799
717
/** Gets a reference to the `http` module. */
800
718
API:: Node http ( ) { result = API:: moduleImport ( "http" ) }
801
719
802
- /**
803
- * Gets a reference to the attribute `attr_name` of the `http` module.
804
- * WARNING: Only holds for a few predefined attributes.
805
- */
806
- private API:: Node http_attr ( string attr_name ) { result = http ( ) .getMember ( attr_name ) }
807
-
808
720
/** Provides models for the `http` module. */
809
721
module http {
810
722
// -------------------------------------------------------------------------
811
723
// http.server
812
724
// -------------------------------------------------------------------------
813
725
/** Gets a reference to the `http.server` module. */
814
- API:: Node server ( ) { result = http_attr ( "server" ) }
726
+ API:: Node server ( ) { result = http ( ) . getMember ( "server" ) }
815
727
816
728
/** Provides models for the `http.server` module */
817
729
module server {
818
- /**
819
- * Gets a reference to the attribute `attr_name` of the `http.server` module.
820
- * WARNING: Only holds for a few predefined attributes.
821
- */
822
- private API:: Node server_attr ( string attr_name ) { result = server ( ) .getMember ( attr_name ) }
823
-
824
730
/**
825
731
* Provides models for the `http.server.BaseHTTPRequestHandler` class (Python 3 only).
826
732
*
827
733
* See https://docs.python.org/3.9/library/http.server.html#http.server.BaseHTTPRequestHandler.
828
734
*/
829
735
module BaseHTTPRequestHandler {
830
736
/** Gets a reference to the `http.server.BaseHTTPRequestHandler` class. */
831
- API:: Node classRef ( ) { result = server_attr ( "BaseHTTPRequestHandler" ) }
737
+ API:: Node classRef ( ) { result = server ( ) . getMember ( "BaseHTTPRequestHandler" ) }
832
738
}
833
739
834
740
/**
@@ -838,7 +744,7 @@ private module Stdlib {
838
744
*/
839
745
module SimpleHTTPRequestHandler {
840
746
/** Gets a reference to the `http.server.SimpleHTTPRequestHandler` class. */
841
- API:: Node classRef ( ) { result = server_attr ( "SimpleHTTPRequestHandler" ) }
747
+ API:: Node classRef ( ) { result = server ( ) . getMember ( "SimpleHTTPRequestHandler" ) }
842
748
}
843
749
844
750
/**
@@ -848,7 +754,7 @@ private module Stdlib {
848
754
*/
849
755
module CGIHTTPRequestHandler {
850
756
/** Gets a reference to the `http.server.CGIHTTPRequestHandler` class. */
851
- API:: Node classRef ( ) { result = server_attr ( "CGIHTTPRequestHandler" ) }
757
+ API:: Node classRef ( ) { result = server ( ) . getMember ( "CGIHTTPRequestHandler" ) }
852
758
}
853
759
}
854
760
}
0 commit comments