@@ -20,83 +20,85 @@ private import semmle.python.Concepts
2020private import semmle.python.ApiGraphs
2121
2222/**
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/.
2425 */
2526module PEP249 {
2627 /**
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.
2929 */
3030 abstract class PEP249ModuleApiNode extends API:: Node {
3131 /** Gets a string representation of this element. */
3232 override string toString ( ) { result = this .( API:: Node ) .toString ( ) }
3333 }
3434
35- /** Gets a reference to a connect call . */
35+ /** Gets a reference to the ` connect` function of a module that implements PEP 249 . */
3636 DataFlow:: Node connect ( ) { result = any ( PEP249ModuleApiNode a ) .getMember ( "connect" ) .getAUse ( ) }
3737
3838 /**
39- * Provides models for the `db.Connection` class
39+ * Provides models for database connections (following PEP 249).
4040 *
4141 * See https://www.python.org/dev/peps/pep-0249/#connection-objects.
4242 */
4343 module Connection {
4444 /**
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.
4646 *
4747 * This can include instantiations of the class, return values from function
4848 * calls, or a special parameter that will be set when functions are called by external
4949 * libraries.
5050 *
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) .
5252 *
5353 * Extend this class if the module implementing PEP 249 offers more direct ways to obtain
5454 * a connection than going through `connect`.
5555 */
5656 abstract class InstanceSource extends DataFlow:: Node { }
5757
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 ( ) }
6161 }
6262
63- /** Gets a reference to an instance of `db.Connection` . */
63+ /** Gets a reference to a database connection (following PEP 249) . */
6464 private DataFlow:: LocalSourceNode instance ( DataFlow:: TypeTracker t ) {
6565 t .start ( ) and
6666 result instanceof InstanceSource
6767 or
6868 exists ( DataFlow:: TypeTracker t2 | result = instance ( t2 ) .track ( t2 , t ) )
6969 }
7070
71- /** Gets a reference to an instance of `db.Connection` . */
71+ /** Gets a reference to a database connection (following PEP 249) . */
7272 DataFlow:: Node instance ( ) { instance ( DataFlow:: TypeTracker:: end ( ) ) .flowsTo ( result ) }
7373 }
7474
7575 /**
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.
7779 * See https://www.python.org/dev/peps/pep-0249/#cursor.
7880 */
7981 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. */
8183 private DataFlow:: LocalSourceNode methodRef ( DataFlow:: TypeTracker t ) {
8284 t .startInAttr ( "cursor" ) and
8385 result = Connection:: instance ( )
8486 or
8587 exists ( DataFlow:: TypeTracker t2 | result = methodRef ( t2 ) .track ( t2 , t ) )
8688 }
8789
88- /** Gets a reference to the `cursor` method on a connection. */
90+ /** Gets a reference to the `cursor` method on a database connection. */
8991 DataFlow:: Node methodRef ( ) { methodRef ( DataFlow:: TypeTracker:: end ( ) ) .flowsTo ( result ) }
9092
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. */
9294 private DataFlow:: LocalSourceNode methodResult ( DataFlow:: TypeTracker t ) {
9395 t .start ( ) and
9496 result .asCfgNode ( ) .( CallNode ) .getFunction ( ) = methodRef ( ) .asCfgNode ( )
9597 or
9698 exists ( DataFlow:: TypeTracker t2 | result = methodResult ( t2 ) .track ( t2 , t ) )
9799 }
98100
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. */
100102 DataFlow:: Node methodResult ( ) { methodResult ( DataFlow:: TypeTracker:: end ( ) ) .flowsTo ( result ) }
101103 }
102104
0 commit comments