Skip to content

Commit 181a53b

Browse files
committed
Python: Rename getAnImmediateUse -> asSource
1 parent 60fde3c commit 181a53b

File tree

22 files changed

+48
-56
lines changed

22 files changed

+48
-56
lines changed

python/ql/lib/semmle/python/ApiGraphs.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ module API {
147147
* to the `escape` member of `re`, neither `x` nor any node that `x` flows to is a reference to
148148
* this API component.
149149
*/
150-
DataFlow::LocalSourceNode getAnImmediateUse() { Impl::use(this, result) }
150+
DataFlow::LocalSourceNode asSource() { Impl::use(this, result) }
151151

152152
/**
153153
* Gets a call to the function represented by this API component.
154154
*/
155-
CallNode getACall() { result = this.getReturn().getAnImmediateUse() }
155+
CallNode getACall() { result = this.getReturn().asSource() }
156156

157157
/**
158158
* Gets a node representing member `m` of this API component.
@@ -377,7 +377,7 @@ module API {
377377
class CallNode extends DataFlow::CallCfgNode {
378378
API::Node callee;
379379

380-
CallNode() { this = callee.getReturn().getAnImmediateUse() }
380+
CallNode() { this = callee.getReturn().asSource() }
381381

382382
/** Gets the API node for the `i`th parameter of this invocation. */
383383
pragma[nomagic]
@@ -423,7 +423,7 @@ module API {
423423
/** Gets the API node for the return value of this call. */
424424
Node getReturn() {
425425
result = callee.getReturn() and
426-
result.getAnImmediateUse() = this
426+
result.asSource() = this
427427
}
428428

429429
/**

python/ql/lib/semmle/python/filters/Tests.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class UnitTestClass extends TestScope, Class {
99
testCaseString.matches("%TestCase") and
1010
testCaseClass = any(API::Node mod).getMember(testCaseString)
1111
|
12-
this.getParent() = testCaseClass.getASubclass*().getAnImmediateUse().asExpr()
12+
this.getParent() = testCaseClass.getASubclass*().asSource().asExpr()
1313
)
1414
}
1515
}

python/ql/lib/semmle/python/frameworks/Aiohttp.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,7 @@ module AiohttpWebModel {
243243

244244
/** A class that has a super-type which is an aiohttp.web View class. */
245245
class AiohttpViewClassFromSuperClass extends AiohttpViewClass {
246-
AiohttpViewClassFromSuperClass() {
247-
this.getParent() = View::subclassRef().getAnImmediateUse().asExpr()
248-
}
246+
AiohttpViewClassFromSuperClass() { this.getParent() = View::subclassRef().asSource().asExpr() }
249247
}
250248

251249
/** A class that is used in a route-setup, therefore being considered an aiohttp.web View class. */

python/ql/lib/semmle/python/frameworks/Aiomysql.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private module Aiomysql {
6363
class AwaitedCursorExecuteCall extends SqlExecution::Range {
6464
CursorExecuteCall executeCall;
6565

66-
AwaitedCursorExecuteCall() { this = executeCall.getReturn().getAwaited().getAnImmediateUse() }
66+
AwaitedCursorExecuteCall() { this = executeCall.getReturn().getAwaited().asSource() }
6767

6868
override DataFlow::Node getSql() { result = executeCall.getSql() }
6969
}
@@ -104,7 +104,7 @@ private module Aiomysql {
104104
class AwaitedSAConnectionExecuteCall extends SqlExecution::Range {
105105
SAConnectionExecuteCall execute;
106106

107-
AwaitedSAConnectionExecuteCall() { this = execute.getReturn().getAwaited().getAnImmediateUse() }
107+
AwaitedSAConnectionExecuteCall() { this = execute.getReturn().getAwaited().asSource() }
108108

109109
override DataFlow::Node getSql() { result = execute.getSql() }
110110
}

python/ql/lib/semmle/python/frameworks/Aiopg.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private module Aiopg {
6363
class AwaitedCursorExecuteCall extends SqlExecution::Range {
6464
CursorExecuteCall execute;
6565

66-
AwaitedCursorExecuteCall() { this = execute.getReturn().getAwaited().getAnImmediateUse() }
66+
AwaitedCursorExecuteCall() { this = execute.getReturn().getAwaited().asSource() }
6767

6868
override DataFlow::Node getSql() { result = execute.getSql() }
6969
}
@@ -100,7 +100,7 @@ private module Aiopg {
100100
class AwaitedSAConnectionExecuteCall extends SqlExecution::Range {
101101
SAConnectionExecuteCall excute;
102102

103-
AwaitedSAConnectionExecuteCall() { this = excute.getReturn().getAwaited().getAnImmediateUse() }
103+
AwaitedSAConnectionExecuteCall() { this = excute.getReturn().getAwaited().asSource() }
104104

105105
override DataFlow::Node getSql() { result = excute.getSql() }
106106
}

python/ql/lib/semmle/python/frameworks/Asyncpg.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private module Asyncpg {
7171
CursorCreation() {
7272
exists(CursorConstruction c |
7373
sql = c.getSql() and
74-
this = c.getReturn().getAwaited().getAnImmediateUse()
74+
this = c.getReturn().getAwaited().asSource()
7575
)
7676
or
7777
exists(API::CallNode prepareCall |
@@ -86,7 +86,7 @@ private module Asyncpg {
8686
.getMember("cursor")
8787
.getReturn()
8888
.getAwaited()
89-
.getAnImmediateUse()
89+
.asSource()
9090
)
9191
}
9292

python/ql/lib/semmle/python/frameworks/Cryptography.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ private module CryptographyModel {
144144
DataFlow::Node getCurveArg() { result in [this.getArg(0), this.getArgByName("curve")] }
145145

146146
override int getKeySizeWithOrigin(DataFlow::Node origin) {
147-
exists(API::Node n |
148-
n = Ecc::predefinedCurveClass(result) and origin = n.getAnImmediateUse()
149-
|
147+
exists(API::Node n | n = Ecc::predefinedCurveClass(result) and origin = n.asSource() |
150148
this.getCurveArg() = n.getAUse()
151149
or
152150
this.getCurveArg() = n.getReturn().getAUse()

python/ql/lib/semmle/python/frameworks/Django.qll

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ module PrivateDjango {
562562

563563
/** A `django.db.connection` is a PEP249 compliant DB connection. */
564564
class DjangoDbConnection extends PEP249::Connection::InstanceSource {
565-
DjangoDbConnection() { this = connection().getAnImmediateUse() }
565+
DjangoDbConnection() { this = connection().asSource() }
566566
}
567567

568568
// -------------------------------------------------------------------------
@@ -869,7 +869,7 @@ module PrivateDjango {
869869

870870
/** Gets the (AST) class of the Django model class `modelClass`. */
871871
Class getModelClassClass(API::Node modelClass) {
872-
result.getParent() = modelClass.getAnImmediateUse().asExpr() and
872+
result.getParent() = modelClass.asSource().asExpr() and
873873
modelClass = Model::subclassRef()
874874
}
875875

@@ -2202,9 +2202,7 @@ module PrivateDjango {
22022202
* thereby handling user input.
22032203
*/
22042204
class DjangoFormClass extends Class, SelfRefMixin {
2205-
DjangoFormClass() {
2206-
this.getParent() = Django::Forms::Form::subclassRef().getAnImmediateUse().asExpr()
2207-
}
2205+
DjangoFormClass() { this.getParent() = Django::Forms::Form::subclassRef().asSource().asExpr() }
22082206
}
22092207

22102208
/**
@@ -2237,7 +2235,7 @@ module PrivateDjango {
22372235
*/
22382236
class DjangoFormFieldClass extends Class {
22392237
DjangoFormFieldClass() {
2240-
this.getParent() = Django::Forms::Field::subclassRef().getAnImmediateUse().asExpr()
2238+
this.getParent() = Django::Forms::Field::subclassRef().asSource().asExpr()
22412239
}
22422240
}
22432241

@@ -2340,7 +2338,7 @@ module PrivateDjango {
23402338
*/
23412339
class DjangoViewClassFromSuperClass extends DjangoViewClass {
23422340
DjangoViewClassFromSuperClass() {
2343-
this.getParent() = Django::Views::View::subclassRef().getAnImmediateUse().asExpr()
2341+
this.getParent() = Django::Views::View::subclassRef().asSource().asExpr()
23442342
}
23452343
}
23462344

@@ -2743,7 +2741,7 @@ module PrivateDjango {
27432741
.getMember("utils")
27442742
.getMember("log")
27452743
.getMember("request_logger")
2746-
.getAnImmediateUse()
2744+
.asSource()
27472745
}
27482746
}
27492747

python/ql/lib/semmle/python/frameworks/FastApi.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private module FastApi {
166166
exists(Class cls, API::Node base |
167167
base = getModeledResponseClass(_).getASubclass*() and
168168
cls.getABase() = base.getAUse().asExpr() and
169-
responseClass.getAnImmediateUse().asExpr() = cls.getParent()
169+
responseClass.asSource().asExpr() = cls.getParent()
170170
|
171171
exists(Assign assign | assign = cls.getAStmt() |
172172
assign.getATarget().(Name).getId() = "media_type" and

python/ql/lib/semmle/python/frameworks/Flask.qll

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ module Flask {
195195

196196
FlaskViewClass() {
197197
api_node = Views::View::subclassRef() and
198-
this.getParent() = api_node.getAnImmediateUse().asExpr()
198+
this.getParent() = api_node.asSource().asExpr()
199199
}
200200

201201
/** Gets a function that could handle incoming requests, if any. */
@@ -220,7 +220,7 @@ module Flask {
220220
class FlaskMethodViewClass extends FlaskViewClass {
221221
FlaskMethodViewClass() {
222222
api_node = Views::MethodView::subclassRef() and
223-
this.getParent() = api_node.getAnImmediateUse().asExpr()
223+
this.getParent() = api_node.asSource().asExpr()
224224
}
225225

226226
override Function getARequestHandler() {
@@ -404,7 +404,7 @@ module Flask {
404404

405405
private class RequestAttrMultiDict extends Werkzeug::MultiDict::InstanceSource {
406406
RequestAttrMultiDict() {
407-
this = request().getMember(["args", "values", "form", "files"]).getAnImmediateUse()
407+
this = request().getMember(["args", "values", "form", "files"]).asSource()
408408
}
409409
}
410410

@@ -427,14 +427,12 @@ module Flask {
427427

428428
/** An `Headers` instance that originates from a flask request. */
429429
private class FlaskRequestHeadersInstances extends Werkzeug::Headers::InstanceSource {
430-
FlaskRequestHeadersInstances() { this = request().getMember("headers").getAnImmediateUse() }
430+
FlaskRequestHeadersInstances() { this = request().getMember("headers").asSource() }
431431
}
432432

433433
/** An `Authorization` instance that originates from a flask request. */
434434
private class FlaskRequestAuthorizationInstances extends Werkzeug::Authorization::InstanceSource {
435-
FlaskRequestAuthorizationInstances() {
436-
this = request().getMember("authorization").getAnImmediateUse()
437-
}
435+
FlaskRequestAuthorizationInstances() { this = request().getMember("authorization").asSource() }
438436
}
439437

440438
// ---------------------------------------------------------------------------
@@ -574,6 +572,6 @@ module Flask {
574572
* - https://flask.palletsprojects.com/en/2.0.x/logging/
575573
*/
576574
private class FlaskLogger extends Stdlib::Logger::InstanceSource {
577-
FlaskLogger() { this = FlaskApp::instance().getMember("logger").getAnImmediateUse() }
575+
FlaskLogger() { this = FlaskApp::instance().getMember("logger").asSource() }
578576
}
579577
}

0 commit comments

Comments
 (0)