@@ -20,83 +20,85 @@ private import semmle.python.Concepts
20
20
private import semmle.python.ApiGraphs
21
21
22
22
/**
23
- * Provides classes modeling PEP 249.
23
+ * Provides classes modeling database interfaces following PEP 249.
24
+ * See https://www.python.org/dev/peps/pep-0249/.
24
25
*/
25
26
module PEP249 {
26
27
/**
27
- * An abstract class encompassing API graph nodes that implement PEP 249.
28
- * Extend this class for implementations.
28
+ * An API graph node representing a module that implements PEP 249.
29
29
*/
30
30
abstract class PEP249ModuleApiNode extends API:: Node {
31
31
/** Gets a string representation of this element. */
32
32
override string toString ( ) { result = this .( API:: Node ) .toString ( ) }
33
33
}
34
34
35
- /** Gets a reference to a connect call . */
35
+ /** Gets a reference to the ` connect` function of a module that implements PEP 249 . */
36
36
DataFlow:: Node connect ( ) { result = any ( PEP249ModuleApiNode a ) .getMember ( "connect" ) .getAUse ( ) }
37
37
38
38
/**
39
- * Provides models for the `db.Connection` class
39
+ * Provides models for database connections (following PEP 249).
40
40
*
41
41
* See https://www.python.org/dev/peps/pep-0249/#connection-objects.
42
42
*/
43
43
module Connection {
44
44
/**
45
- * A source of instances of `db.Connection` , extend this class to model new instances.
45
+ * A source of database connections (following PEP 249) , extend this class to model new instances.
46
46
*
47
47
* This can include instantiations of the class, return values from function
48
48
* calls, or a special parameter that will be set when functions are called by external
49
49
* libraries.
50
50
*
51
- * Use the predicate `Connection::instance()` to get references to instances of `db.Connection` .
51
+ * Use the predicate `Connection::instance()` to get references database connections (following PEP 249) .
52
52
*
53
53
* Extend this class if the module implementing PEP 249 offers more direct ways to obtain
54
54
* a connection than going through `connect`.
55
55
*/
56
56
abstract class InstanceSource extends DataFlow:: Node { }
57
57
58
- /** A direct instantiation of `db.Connection` . */
59
- private class ClassInstantiation extends InstanceSource , DataFlow:: CallCfgNode {
60
- ClassInstantiation ( ) { this .getFunction ( ) = connect ( ) }
58
+ /** A call to the `connect` function of a module that implements PEP 249 . */
59
+ private class ConnectCall extends InstanceSource , DataFlow:: CallCfgNode {
60
+ ConnectCall ( ) { this .getFunction ( ) = connect ( ) }
61
61
}
62
62
63
- /** Gets a reference to an instance of `db.Connection` . */
63
+ /** Gets a reference to a database connection (following PEP 249) . */
64
64
private DataFlow:: LocalSourceNode instance ( DataFlow:: TypeTracker t ) {
65
65
t .start ( ) and
66
66
result instanceof InstanceSource
67
67
or
68
68
exists ( DataFlow:: TypeTracker t2 | result = instance ( t2 ) .track ( t2 , t ) )
69
69
}
70
70
71
- /** Gets a reference to an instance of `db.Connection` . */
71
+ /** Gets a reference to a database connection (following PEP 249) . */
72
72
DataFlow:: Node instance ( ) { instance ( DataFlow:: TypeTracker:: end ( ) ) .flowsTo ( result ) }
73
73
}
74
74
75
75
/**
76
- * Provides models for the `cursor` method on a connection.
76
+ * Provides models for database cursors (following PEP 249).
77
+ *
78
+ * These are are returned by the `cursor` method on a database connection.
77
79
* See https://www.python.org/dev/peps/pep-0249/#cursor.
78
80
*/
79
81
module cursor {
80
- /** Gets a reference to the `cursor` method on a connection. */
82
+ /** Gets a reference to the `cursor` method on a database connection. */
81
83
private DataFlow:: LocalSourceNode methodRef ( DataFlow:: TypeTracker t ) {
82
84
t .startInAttr ( "cursor" ) and
83
85
result = Connection:: instance ( )
84
86
or
85
87
exists ( DataFlow:: TypeTracker t2 | result = methodRef ( t2 ) .track ( t2 , t ) )
86
88
}
87
89
88
- /** Gets a reference to the `cursor` method on a connection. */
90
+ /** Gets a reference to the `cursor` method on a database connection. */
89
91
DataFlow:: Node methodRef ( ) { methodRef ( DataFlow:: TypeTracker:: end ( ) ) .flowsTo ( result ) }
90
92
91
- /** Gets a reference to a result of calling the `cursor` method on a connection. */
93
+ /** Gets a reference to a result of calling the `cursor` method on a database connection. */
92
94
private DataFlow:: LocalSourceNode methodResult ( DataFlow:: TypeTracker t ) {
93
95
t .start ( ) and
94
96
result .asCfgNode ( ) .( CallNode ) .getFunction ( ) = methodRef ( ) .asCfgNode ( )
95
97
or
96
98
exists ( DataFlow:: TypeTracker t2 | result = methodResult ( t2 ) .track ( t2 , t ) )
97
99
}
98
100
99
- /** Gets a reference to a result of calling the `cursor` method on a connection. */
101
+ /** Gets a reference to a result of calling the `cursor` method on a database connection. */
100
102
DataFlow:: Node methodResult ( ) { methodResult ( DataFlow:: TypeTracker:: end ( ) ) .flowsTo ( result ) }
101
103
}
102
104
0 commit comments