Skip to content

Commit 9acc71a

Browse files
authored
Python: Get rid of all _attr methods in Django.qll
1 parent f3661c3 commit 9acc71a

File tree

1 file changed

+38
-78
lines changed

1 file changed

+38
-78
lines changed

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

Lines changed: 38 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -300,19 +300,13 @@ private module PrivateDjango {
300300
/** Gets a reference to the `django` module. */
301301
API::Node django() { result = API::moduleImport("django") }
302302

303-
/**
304-
* Gets a reference to the attribute `attr_name` of the `django` module.
305-
* WARNING: Only holds for a few predefined attributes.
306-
*/
307-
private API::Node django_attr(string attr_name) { result = django().getMember(attr_name) }
308-
309303
/** Provides models for the `django` module. */
310304
module django {
311305
// -------------------------------------------------------------------------
312306
// django.db
313307
// -------------------------------------------------------------------------
314308
/** Gets a reference to the `django.db` module. */
315-
API::Node db() { result = django_attr("db") }
309+
API::Node db() { result = django().getMember("db") }
316310

317311
/**
318312
* `django.db` implements PEP249, providing ways to execute SQL statements against a database.
@@ -473,34 +467,28 @@ private module PrivateDjango {
473467
// django.urls
474468
// -------------------------------------------------------------------------
475469
/** Gets a reference to the `django.urls` module. */
476-
API::Node urls() { result = django_attr("urls") }
470+
API::Node urls() { result = django().getMember("urls") }
477471

478472
/** Provides models for the `django.urls` module */
479473
module urls {
480-
/**
481-
* Gets a reference to the attribute `attr_name` of the `urls` module.
482-
* WARNING: Only holds for a few predefined attributes.
483-
*/
484-
private API::Node urls_attr(string attr_name) { result = urls().getMember(attr_name) }
485-
486474
/**
487475
* Gets a reference to the `django.urls.path` function.
488476
* See https://docs.djangoproject.com/en/3.0/ref/urls/#path
489477
*/
490-
API::Node path() { result = urls_attr("path") }
478+
API::Node path() { result = urls().getMember("path") }
491479

492480
/**
493481
* Gets a reference to the `django.urls.re_path` function.
494482
* See https://docs.djangoproject.com/en/3.0/ref/urls/#re_path
495483
*/
496-
API::Node re_path() { result = urls_attr("re_path") }
484+
API::Node re_path() { result = urls().getMember("re_path") }
497485
}
498486

499487
// -------------------------------------------------------------------------
500488
// django.conf
501489
// -------------------------------------------------------------------------
502490
/** Gets a reference to the `django.conf` module. */
503-
API::Node conf() { result = django_attr("conf") }
491+
API::Node conf() { result = django().getMember("conf") }
504492

505493
/** Provides models for the `django.conf` module */
506494
module conf {
@@ -525,30 +513,18 @@ private module PrivateDjango {
525513
// django.http
526514
// -------------------------------------------------------------------------
527515
/** Gets a reference to the `django.http` module. */
528-
API::Node http() { result = django_attr("http") }
516+
API::Node http() { result = django().getMember("http") }
529517

530518
/** Provides models for the `django.http` module */
531519
module http {
532-
/**
533-
* Gets a reference to the attribute `attr_name` of the `django.http` module.
534-
* WARNING: Only holds for a few predefined attributes.
535-
*/
536-
private API::Node http_attr(string attr_name) { result = http().getMember(attr_name) }
537-
538520
// ---------------------------------------------------------------------------
539521
// django.http.request
540522
// ---------------------------------------------------------------------------
541523
/** Gets a reference to the `django.http.request` module. */
542-
API::Node request() { result = http_attr("request") }
524+
API::Node request() { result = http().getMember("request") }
543525

544526
/** Provides models for the `django.http.request` module. */
545527
module request {
546-
/**
547-
* Gets a reference to the attribute `attr_name` of the `django.http.request` module.
548-
* WARNING: Only holds for a few predefined attributes.
549-
*/
550-
private API::Node request_attr(string attr_name) { result = request().getMember(attr_name) }
551-
552528
/**
553529
* Provides models for the `django.http.request.HttpRequest` class
554530
*
@@ -557,10 +533,10 @@ private module PrivateDjango {
557533
module HttpRequest {
558534
/** Gets a reference to the `django.http.request.HttpRequest` class. */
559535
API::Node classRef() {
560-
result = request_attr("HttpRequest")
536+
result = request().getMember("HttpRequest")
561537
or
562538
// handle django.http.HttpRequest alias
563-
result = http_attr("HttpRequest")
539+
result = http().getMember("HttpRequest")
564540
}
565541

566542
/**
@@ -592,29 +568,21 @@ private module PrivateDjango {
592568
// django.http.response
593569
// -------------------------------------------------------------------------
594570
/** Gets a reference to the `django.http.response` module. */
595-
API::Node response() { result = http_attr("response") }
571+
API::Node response() { result = http().getMember("response") }
596572

597573
/** Provides models for the `django.http.response` module */
598574
module response {
599-
/**
600-
* Gets a reference to the attribute `attr_name` of the `django.http.response` module.
601-
* WARNING: Only holds for a few predefined attributes.
602-
*/
603-
private API::Node response_attr(string attr_name) {
604-
result = response().getMember(attr_name)
605-
}
606-
607575
/**
608576
* Provides models for the `django.http.response.HttpResponse` class
609577
*
610578
* See https://docs.djangoproject.com/en/3.1/ref/request-response/#django.http.HttpResponse.
611579
*/
612580
module HttpResponse {
613581
API::Node baseClassRef() {
614-
result = response_attr("HttpResponse")
582+
result = response().getMember("HttpResponse")
615583
or
616584
// Handle `django.http.HttpResponse` alias
617-
result = http_attr("HttpResponse")
585+
result = http().getMember("HttpResponse")
618586
}
619587

620588
/** Gets a reference to the `django.http.response.HttpResponse` class. */
@@ -672,10 +640,10 @@ private module PrivateDjango {
672640
module HttpResponseRedirect {
673641
/** Gets a reference to the `django.http.response.HttpResponseRedirect` class. */
674642
API::Node baseClassRef() {
675-
result = response_attr("HttpResponseRedirect")
643+
result = response().getMember("HttpResponseRedirect")
676644
or
677645
// Handle `django.http.HttpResponseRedirect` alias
678-
result = http_attr("HttpResponseRedirect")
646+
result = http().getMember("HttpResponseRedirect")
679647
}
680648

681649
/** Gets a reference a subclass of the `django.http.response.HttpResponseRedirect` class. */
@@ -734,10 +702,10 @@ private module PrivateDjango {
734702
module HttpResponsePermanentRedirect {
735703
/** Gets a reference to the `django.http.response.HttpResponsePermanentRedirect` class. */
736704
API::Node baseClassRef() {
737-
result = response_attr("HttpResponsePermanentRedirect")
705+
result = response().getMember("HttpResponsePermanentRedirect")
738706
or
739707
// Handle `django.http.HttpResponsePermanentRedirect` alias
740-
result = http_attr("HttpResponsePermanentRedirect")
708+
result = http().getMember("HttpResponsePermanentRedirect")
741709
}
742710

743711
/** Gets a reference to the `django.http.response.HttpResponsePermanentRedirect` class. */
@@ -796,11 +764,11 @@ private module PrivateDjango {
796764
module HttpResponseNotModified {
797765
/** Gets a reference to the `django.http.response.HttpResponseNotModified` class. */
798766
API::Node baseClassRef() {
799-
result = response_attr("HttpResponseNotModified")
767+
result = response().getMember("HttpResponseNotModified")
800768
or
801769
// TODO: remove/expand this part of the template as needed
802770
// Handle `django.http.HttpResponseNotModified` alias
803-
result = http_attr("HttpResponseNotModified")
771+
result = http().getMember("HttpResponseNotModified")
804772
}
805773

806774
/** Gets a reference to the `django.http.response.HttpResponseNotModified` class. */
@@ -849,10 +817,10 @@ private module PrivateDjango {
849817
module HttpResponseBadRequest {
850818
/** Gets a reference to the `django.http.response.HttpResponseBadRequest` class. */
851819
API::Node baseClassRef() {
852-
result = response_attr("HttpResponseBadRequest")
820+
result = response().getMember("HttpResponseBadRequest")
853821
or
854822
// Handle `django.http.HttpResponseBadRequest` alias
855-
result = http_attr("HttpResponseBadRequest")
823+
result = http().getMember("HttpResponseBadRequest")
856824
}
857825

858826
/** Gets a reference to the `django.http.response.HttpResponseBadRequest` class. */
@@ -903,10 +871,10 @@ private module PrivateDjango {
903871
module HttpResponseNotFound {
904872
/** Gets a reference to the `django.http.response.HttpResponseNotFound` class. */
905873
API::Node baseClassRef() {
906-
result = response_attr("HttpResponseNotFound")
874+
result = response().getMember("HttpResponseNotFound")
907875
or
908876
// Handle `django.http.HttpResponseNotFound` alias
909-
result = http_attr("HttpResponseNotFound")
877+
result = http().getMember("HttpResponseNotFound")
910878
}
911879

912880
/** Gets a reference to the `django.http.response.HttpResponseNotFound` class. */
@@ -957,10 +925,10 @@ private module PrivateDjango {
957925
module HttpResponseForbidden {
958926
/** Gets a reference to the `django.http.response.HttpResponseForbidden` class. */
959927
API::Node baseClassRef() {
960-
result = response_attr("HttpResponseForbidden")
928+
result = response().getMember("HttpResponseForbidden")
961929
or
962930
// Handle `django.http.HttpResponseForbidden` alias
963-
result = http_attr("HttpResponseForbidden")
931+
result = http().getMember("HttpResponseForbidden")
964932
}
965933

966934
/** Gets a reference to the `django.http.response.HttpResponseForbidden` class. */
@@ -1011,10 +979,10 @@ private module PrivateDjango {
1011979
module HttpResponseNotAllowed {
1012980
/** Gets a reference to the `django.http.response.HttpResponseNotAllowed` class. */
1013981
API::Node baseClassRef() {
1014-
result = response_attr("HttpResponseNotAllowed")
982+
result = response().getMember("HttpResponseNotAllowed")
1015983
or
1016984
// Handle `django.http.HttpResponseNotAllowed` alias
1017-
result = http_attr("HttpResponseNotAllowed")
985+
result = http().getMember("HttpResponseNotAllowed")
1018986
}
1019987

1020988
/** Gets a reference to the `django.http.response.HttpResponseNotAllowed` class. */
@@ -1066,10 +1034,10 @@ private module PrivateDjango {
10661034
module HttpResponseGone {
10671035
/** Gets a reference to the `django.http.response.HttpResponseGone` class. */
10681036
API::Node baseClassRef() {
1069-
result = response_attr("HttpResponseGone")
1037+
result = response().getMember("HttpResponseGone")
10701038
or
10711039
// Handle `django.http.HttpResponseGone` alias
1072-
result = http_attr("HttpResponseGone")
1040+
result = http().getMember("HttpResponseGone")
10731041
}
10741042

10751043
/** Gets a reference to the `django.http.response.HttpResponseGone` class. */
@@ -1120,10 +1088,10 @@ private module PrivateDjango {
11201088
module HttpResponseServerError {
11211089
/** Gets a reference to the `django.http.response.HttpResponseServerError` class. */
11221090
API::Node baseClassRef() {
1123-
result = response_attr("HttpResponseServerError")
1091+
result = response().getMember("HttpResponseServerError")
11241092
or
11251093
// Handle `django.http.HttpResponseServerError` alias
1126-
result = http_attr("HttpResponseServerError")
1094+
result = http().getMember("HttpResponseServerError")
11271095
}
11281096

11291097
/** Gets a reference to the `django.http.response.HttpResponseServerError` class. */
@@ -1174,10 +1142,10 @@ private module PrivateDjango {
11741142
module JsonResponse {
11751143
/** Gets a reference to the `django.http.response.JsonResponse` class. */
11761144
API::Node baseClassRef() {
1177-
result = response_attr("JsonResponse")
1145+
result = response().getMember("JsonResponse")
11781146
or
11791147
// Handle `django.http.JsonResponse` alias
1180-
result = http_attr("JsonResponse")
1148+
result = http().getMember("JsonResponse")
11811149
}
11821150

11831151
/** Gets a reference to the `django.http.response.JsonResponse` class. */
@@ -1231,10 +1199,10 @@ private module PrivateDjango {
12311199
module StreamingHttpResponse {
12321200
/** Gets a reference to the `django.http.response.StreamingHttpResponse` class. */
12331201
API::Node baseClassRef() {
1234-
result = response_attr("StreamingHttpResponse")
1202+
result = response().getMember("StreamingHttpResponse")
12351203
or
12361204
// Handle `django.http.StreamingHttpResponse` alias
1237-
result = http_attr("StreamingHttpResponse")
1205+
result = http().getMember("StreamingHttpResponse")
12381206
}
12391207

12401208
/** Gets a reference to the `django.http.response.StreamingHttpResponse` class. */
@@ -1285,10 +1253,10 @@ private module PrivateDjango {
12851253
module FileResponse {
12861254
/** Gets a reference to the `django.http.response.FileResponse` class. */
12871255
API::Node baseClassRef() {
1288-
result = response_attr("FileResponse")
1256+
result = response().getMember("FileResponse")
12891257
or
12901258
// Handle `django.http.FileResponse` alias
1291-
result = http_attr("FileResponse")
1259+
result = http().getMember("FileResponse")
12921260
}
12931261

12941262
/** Gets a reference to the `django.http.response.FileResponse` class. */
@@ -1378,24 +1346,16 @@ private module PrivateDjango {
13781346
// django.shortcuts
13791347
// -------------------------------------------------------------------------
13801348
/** Gets a reference to the `django.shortcuts` module. */
1381-
API::Node shortcuts() { result = django_attr("shortcuts") }
1349+
API::Node shortcuts() { result = django().getMember("shortcuts") }
13821350

13831351
/** Provides models for the `django.shortcuts` module */
13841352
module shortcuts {
1385-
/**
1386-
* Gets a reference to the attribute `attr_name` of the `django.shortcuts` module.
1387-
* WARNING: Only holds for a few predefined attributes.
1388-
*/
1389-
private API::Node shortcuts_attr(string attr_name) {
1390-
result = shortcuts().getMember(attr_name)
1391-
}
1392-
13931353
/**
13941354
* Gets a reference to the `django.shortcuts.redirect` function
13951355
*
13961356
* See https://docs.djangoproject.com/en/3.1/topics/http/shortcuts/#redirect
13971357
*/
1398-
API::Node redirect() { result = shortcuts_attr("redirect") }
1358+
API::Node redirect() { result = shortcuts().getMember("redirect") }
13991359
}
14001360
}
14011361

0 commit comments

Comments
 (0)