Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6093bb9

Browse files
tausbnRasmusWL
authored andcommitted
Python: add some stdlib models
1 parent 4879a93 commit 6093bb9

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,10 @@ module Stdlib {
182182
*/
183183
module SplitResult {
184184
/** Gets a reference to the `urllib.parse.SplitResult` class. */
185-
private API::Node classRef() {
185+
API::Node classRef() {
186186
result = API::moduleImport("urllib").getMember("parse").getMember("SplitResult")
187+
or
188+
result = ModelOutput::getATypeNode("urllib.parse.SplitResult~Subclass").getASubclass*()
187189
}
188190

189191
/**
@@ -2306,7 +2308,7 @@ module StdlibPrivate {
23062308
*/
23072309
module HttpConnection {
23082310
/** Gets a reference to the `http.client.HttpConnection` class. */
2309-
private API::Node classRef() {
2311+
API::Node classRef() {
23102312
exists(string className | className in ["HTTPConnection", "HTTPSConnection"] |
23112313
// Python 3
23122314
result = API::moduleImport("http").getMember("client").getMember(className)
@@ -2317,6 +2319,8 @@ module StdlibPrivate {
23172319
result =
23182320
API::moduleImport("six").getMember("moves").getMember("http_client").getMember(className)
23192321
)
2322+
or
2323+
result = ModelOutput::getATypeNode("http.client.HTTPConnection~Subclass").getASubclass*()
23202324
}
23212325

23222326
/**
@@ -3550,8 +3554,10 @@ module StdlibPrivate {
35503554
*/
35513555
module StringIO {
35523556
/** Gets a reference to the `io.StringIO` class. */
3553-
private API::Node classRef() {
3557+
API::Node classRef() {
35543558
result = API::moduleImport("io").getMember(["StringIO", "BytesIO"])
3559+
or
3560+
result = ModelOutput::getATypeNode("io.StringIO~Subclass").getASubclass*()
35553561
}
35563562

35573563
/**

python/ql/src/meta/ClassHierarchy/Find.ql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,24 @@ class SqlAlchemySession extends FindSubclassesSpec {
362362
override API::Node getAlreadyModeledClass() { result = SqlAlchemy::Session::classRef() }
363363
}
364364

365+
class UrlLibParseSplitResult extends FindSubclassesSpec {
366+
UrlLibParseSplitResult() { this = "urllib.parse.SplitResult~Subclass" }
367+
368+
override API::Node getAlreadyModeledClass() { result = Stdlib::SplitResult::classRef() }
369+
}
370+
371+
class StdlibHttpConnection extends FindSubclassesSpec {
372+
StdlibHttpConnection() { this = "http.client.HTTPConnection~Subclass" }
373+
374+
override API::Node getAlreadyModeledClass() { result = StdlibPrivate::HttpConnection::classRef() }
375+
}
376+
377+
class StringIO extends FindSubclassesSpec {
378+
StringIO() { this = "io.StringIO~Subclass" }
379+
380+
override API::Node getAlreadyModeledClass() { result = StdlibPrivate::StringIO::classRef() }
381+
}
382+
365383
bindingset[fullyQualified]
366384
predicate fullyQualifiedToYamlFormat(string fullyQualified, string type2, string path) {
367385
exists(int firstDot | firstDot = fullyQualified.indexOf(".", 0, 0) |

0 commit comments

Comments
 (0)