Skip to content

Commit 46f7a2b

Browse files
RasmusWLyoff
andauthored
Python: Apply suggestions from code review
Co-authored-by: yoff <[email protected]>
1 parent afd35f2 commit 46f7a2b

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ module AiohttpWebModel {
2727
* See https://docs.aiohttp.org/en/stable/web_reference.html#view.
2828
*/
2929
module View {
30-
/** Gets a reference to the `flask.views.View` class or any subclass. */
30+
/** Gets a reference to the `aiohttp.web.View` class or any subclass. */
3131
API::Node subclassRef() {
3232
result = API::moduleImport("aiohttp").getMember("web").getMember("View").getASubclass*()
3333
}
3434
}
3535

3636
// -- route modeling --
37-
/** Gets a reference to a `aiohttp.web.Application` instance. */
37+
/** Gets a reference to an `aiohttp.web.Application` instance. */
3838
API::Node applicationInstance() {
3939
// Not sure whether you're allowed to add routes _after_ starting the app, for
4040
// example in the middle of handling a http request... but I'm guessing that for 99%
@@ -43,7 +43,7 @@ module AiohttpWebModel {
4343
result = API::moduleImport("aiohttp").getMember("web").getMember("Application").getReturn()
4444
}
4545

46-
/** Gets a reference to a `aiohttp.web.UrlDispatcher` instance. */
46+
/** Gets a reference to an `aiohttp.web.UrlDispatcher` instance. */
4747
API::Node urlDispathcerInstance() {
4848
result = API::moduleImport("aiohttp").getMember("web").getMember("UrlDispatcher").getReturn()
4949
or
@@ -106,9 +106,7 @@ module AiohttpWebModel {
106106
Function getARequestHandler() {
107107
this.getHandlerArg() = poorMansFunctionTracker(result)
108108
or
109-
exists(AiohttpViewClass cls |
110-
cls = this.getViewClass() and
111-
result = cls.getARequestHandler()
109+
result = this.getViewClass().(AiohttpViewClass).getARequestHandler()
112110
)
113111
}
114112
}
@@ -142,7 +140,7 @@ module AiohttpWebModel {
142140
}
143141
}
144142

145-
/** An aiohttp route setup that uses coroutines (async function) as request handler. */
143+
/** An aiohttp route setup that uses coroutines (async function) as request handlers. */
146144
class AiohttpCoroutineRouteSetup extends AiohttpRouteSetup {
147145
AiohttpCoroutineRouteSetup() { this.getHandlerArg() = poorMansFunctionTracker(_) }
148146
}
@@ -187,7 +185,7 @@ module AiohttpWebModel {
187185
}
188186
}
189187

190-
/** A route-setup using a decorator, such as `route`, `view`, `get`, `post`, etc. on a `aiohttp.web.RouteTableDef`. */
188+
/** A route-setup using a decorator, such as `route`, `view`, `get`, `post`, etc. on an `aiohttp.web.RouteTableDef`. */
191189
class AiohttpDecoratorRouteSetup extends AiohttpRouteSetup::Range, DataFlow::CallCfgNode {
192190
/** At what index route arguments starts, so we can handle "route" version together with get/post/... */
193191
int routeArgsStart;
@@ -232,7 +230,7 @@ module AiohttpWebModel {
232230
}
233231
}
234232

235-
/** A class that we consider a aiohttp.web View class. */
233+
/** A class that we consider an aiohttp.web View class. */
236234
abstract class AiohttpViewClass extends Class, SelfRefMixin {
237235
/** Gets a function that could handle incoming requests, if any. */
238236
Function getARequestHandler() {
@@ -243,12 +241,12 @@ module AiohttpWebModel {
243241
}
244242
}
245243

246-
/** A class that has a super-type which is a aiohttp.web View class. */
244+
/** A class that has a super-type which is an aiohttp.web View class. */
247245
class AiohttpViewClassFromSuperClass extends AiohttpViewClass {
248246
AiohttpViewClassFromSuperClass() { this.getABase() = View::subclassRef().getAUse().asExpr() }
249247
}
250248

251-
/** A class that is used in a route-setup, therefore being considered a aiohttp.web View class. */
249+
/** A class that is used in a route-setup, therefore being considered an aiohttp.web View class. */
252250
class AiohttpViewClassFromRouteSetup extends AiohttpViewClass {
253251
AiohttpViewClassFromRouteSetup() { this = any(AiohttpRouteSetup rs).getViewClass() }
254252
}
@@ -299,7 +297,7 @@ module AiohttpWebModel {
299297
}
300298

301299
/**
302-
* A parameter that will receive a `aiohttp.web.Request` instance when a request
300+
* A parameter that will receive an `aiohttp.web.Request` instance when a request
303301
* handler is invoked.
304302
*/
305303
class AiohttpRequestHandlerRequestParam extends Request::InstanceSource, RemoteFlowSource::Range,
@@ -329,7 +327,7 @@ module AiohttpWebModel {
329327
}
330328

331329
/**
332-
* A read of the `request` attribute on an instance of a aiohttp.web View class,
330+
* A read of the `request` attribute on an instance of an aiohttp.web View class,
333331
* which is the request being processed currently.
334332
*/
335333
class AiohttpViewClassRequestAttributeRead extends Request::InstanceSource,
@@ -382,15 +380,15 @@ module AiohttpWebModel {
382380
}
383381
}
384382

385-
/** An attribute read on a `aiohttp.web.Request` that is a `MultiDictProxy` instance. */
383+
/** An attribute read on an `aiohttp.web.Request` that is a `MultiDictProxy` instance. */
386384
class AiohttpRequestMultiDictProxyInstances extends Multidict::MultiDictProxy::InstanceSource {
387385
AiohttpRequestMultiDictProxyInstances() {
388386
this.(DataFlow::AttrRead).getObject() = Request::instance() and
389387
this.(DataFlow::AttrRead).getAttributeName() in ["query", "headers"]
390388
}
391389
}
392390

393-
/** An attribute read on a `aiohttp.web.Request` that is a `yarl.URL` instance. */
391+
/** An attribute read on an `aiohttp.web.Request` that is a `yarl.URL` instance. */
394392
class AiohttpRequestYarlUrlInstances extends Yarl::Url::InstanceSource {
395393
AiohttpRequestYarlUrlInstances() {
396394
this.(DataFlow::AttrRead).getObject() = Request::instance() and

0 commit comments

Comments
 (0)