|
| 1 | +import python |
| 2 | +import semmle.python.dataflow.new.DataFlow |
| 3 | +private import semmle.python.ApiGraphs |
| 4 | +import semmle.python.frameworks.internal.SubclassFinder::NotExposed |
| 5 | +private import semmle.python.frameworks.Flask |
| 6 | +private import semmle.python.frameworks.FastApi |
| 7 | +private import semmle.python.frameworks.Django |
| 8 | +import semmle.python.frameworks.data.internal.ApiGraphModelsExtensions as Extensions |
| 9 | + |
| 10 | +class FlaskViewClasses extends FindSubclassesSpec { |
| 11 | + FlaskViewClasses() { this = "flask.View~Subclass" } |
| 12 | + |
| 13 | + override API::Node getAlreadyModeledClass() { result = Flask::Views::View::subclassRef() } |
| 14 | +} |
| 15 | + |
| 16 | +class FlaskMethodViewClasses extends FindSubclassesSpec { |
| 17 | + FlaskMethodViewClasses() { this = "flask.MethodView~Subclass" } |
| 18 | + |
| 19 | + override API::Node getAlreadyModeledClass() { result = Flask::Views::MethodView::subclassRef() } |
| 20 | + |
| 21 | + override FlaskViewClasses getSuperClass() { any() } |
| 22 | +} |
| 23 | + |
| 24 | +bindingset[fullyQualified] |
| 25 | +predicate fullyQualifiedToYamlFormat(string fullyQualified, string type2, string path) { |
| 26 | + exists(int firstDot | firstDot = fullyQualified.indexOf(".", 0, 0) | |
| 27 | + type2 = fullyQualified.prefix(firstDot) and |
| 28 | + path = |
| 29 | + ("Member[" + fullyQualified.suffix(firstDot + 1).replaceAll(".", "].Member[") + "]") |
| 30 | + .replaceAll(".Member[__init__].", "") |
| 31 | + .replaceAll("Member[__init__].", "") |
| 32 | + ) |
| 33 | +} |
| 34 | + |
| 35 | +from FindSubclassesSpec spec, string newModelFullyQualified, string type2, string path, Module mod |
| 36 | +where |
| 37 | + newModel(spec, newModelFullyQualified, _, mod, _) and |
| 38 | + not exists(FindSubclassesSpec subclass | subclass.getSuperClass() = spec | |
| 39 | + newModel(subclass, newModelFullyQualified, _, mod, _) |
| 40 | + ) and |
| 41 | + not exists(mod.getLocation().getFile().getRelativePath()) and |
| 42 | + fullyQualifiedToYamlFormat(newModelFullyQualified, type2, path) and |
| 43 | + not Extensions::typeModel(spec, type2, path) |
| 44 | +select spec.(string), type2, path |
0 commit comments