Skip to content

Commit d35bf8f

Browse files
Rasmus Lerchedahl PetersenRasmus Lerchedahl Petersen
authored andcommitted
Python: Update comments on PEP 249 module
1 parent 0240670 commit d35bf8f

File tree

1 file changed

+26
-8
lines changed
  • python/ql/src/experimental/semmle/python/frameworks

1 file changed

+26
-8
lines changed

python/ql/src/experimental/semmle/python/frameworks/PEP249.qll

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
/**
2+
* Provides classes modeling PEP 249.
3+
* See https://www.python.org/dev/peps/pep-0249/.
4+
*/
5+
16
private import python
27
private import experimental.dataflow.DataFlow
38
private import experimental.dataflow.RemoteFlowSources
49
private import experimental.semmle.python.Concepts
510

11+
/** A module implementing PEP 249. Extend this class for implementations. */
612
abstract class PEP249Module extends DataFlow::Node { }
713

814
/** Gets a reference to a connect call. */
@@ -19,7 +25,7 @@ DataFlow::Node connect() { result = connect(DataFlow::TypeTracker::end()) }
1925
/**
2026
* Provides models for the `db.Conection` class
2127
*
22-
* See apiref.
28+
* See https://www.python.org/dev/peps/pep-0249/#connection-objects.
2329
*/
2430
module Connection {
2531
/**
@@ -30,6 +36,9 @@ module Connection {
3036
* library.
3137
*
3238
* Use `Conection::instance()` predicate to get references to instances of `db.Conection`.
39+
*
40+
* Extend this class if the module implementing PEP 249 offers more direct ways to obtain
41+
* a connection than going through `connect`.
3342
*/
3443
abstract class InstanceSource extends DataFlow::Node { }
3544

@@ -52,40 +61,49 @@ module Connection {
5261
DataFlow::Node instance() { result = instance(DataFlow::TypeTracker::end()) }
5362
}
5463

55-
/** Provides models for the `django.db.connection.cursor` method. */
64+
/**
65+
* Provides models for the `db.connection.cursor` method.
66+
* See https://www.python.org/dev/peps/pep-0249/#cursor.
67+
*/
5668
module cursor {
57-
/** Gets a reference to the `django.db.connection.cursor` metod. */
69+
/** Gets a reference to the `db.connection.cursor` metod. */
5870
private DataFlow::Node methodRef(DataFlow::TypeTracker t) {
5971
t.startInAttr("cursor") and
6072
result = Connection::instance()
6173
or
6274
exists(DataFlow::TypeTracker t2 | result = methodRef(t2).track(t2, t))
6375
}
6476

65-
/** Gets a reference to the `django.db.connection.cursor` metod. */
77+
/** Gets a reference to the `db.connection.cursor` metod. */
6678
DataFlow::Node methodRef() { result = methodRef(DataFlow::TypeTracker::end()) }
6779

68-
/** Gets a reference to a result of calling `django.db.connection.cursor`. */
80+
/** Gets a reference to a result of calling `db.connection.cursor`. */
6981
private DataFlow::Node methodResult(DataFlow::TypeTracker t) {
7082
t.start() and
7183
result.asCfgNode().(CallNode).getFunction() = methodRef().asCfgNode()
7284
or
7385
exists(DataFlow::TypeTracker t2 | result = methodResult(t2).track(t2, t))
7486
}
7587

76-
/** Gets a reference to a result of calling `django.db.connection.cursor`. */
88+
/** Gets a reference to a result of calling `db.connection.cursor`. */
7789
DataFlow::Node methodResult() { result = methodResult(DataFlow::TypeTracker::end()) }
7890
}
7991

80-
/** Gets a reference to the `django.db.connection.cursor.execute` function. */
92+
/**
93+
* Gets a reference to the `db.connection.cursor.execute` function.
94+
* See https://www.python.org/dev/peps/pep-0249/#id15.
95+
*/
8196
private DataFlow::Node execute(DataFlow::TypeTracker t) {
8297
t.startInAttr("execute") and
8398
result = cursor::methodResult()
8499
or
85100
exists(DataFlow::TypeTracker t2 | result = execute(t2).track(t2, t))
86101
}
87102

88-
/** Gets a reference to the `django.db.connection.cursor.execute` function. */
103+
/**
104+
* Gets a reference to the `db.connection.cursor.execute` function.
105+
* See https://www.python.org/dev/peps/pep-0249/#id15.
106+
*/
89107
DataFlow::Node execute() { result = execute(DataFlow::TypeTracker::end()) }
90108

91109
private class DbConnectionExecute extends SqlExecution::Range, DataFlow::CfgNode {

0 commit comments

Comments
 (0)