mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Python: Add utility predicate for finding ModuleObject by name.
This commit is contained in:
@@ -84,11 +84,7 @@ predicate in_notebook(Expr e) {
|
||||
}
|
||||
|
||||
FunctionObject assertRaises() {
|
||||
exists(ModuleObject unittest, ClassObject testcase |
|
||||
unittest.getName() = "unittest" and
|
||||
testcase = unittest.getAttribute("TestCase") and
|
||||
result = testcase.lookupAttribute("assertRaises")
|
||||
)
|
||||
result = ModuleObject::named("unittest").getAttribute("TestCase").(ClassObject).lookupAttribute("assertRaises")
|
||||
}
|
||||
|
||||
/** Holds if expression `e` is in a `with` block that tests for exceptions being raised. */
|
||||
|
||||
@@ -7,9 +7,8 @@ class ZopeInterfaceMethod extends PyFunctionObject {
|
||||
|
||||
/** Holds if this method belongs to a class that sub-classes `zope.interface.Interface` */
|
||||
ZopeInterfaceMethod() {
|
||||
exists(ModuleObject zope, Object interface, ClassObject owner |
|
||||
zope.getAttribute("Interface") = interface and
|
||||
zope.getName() = "zope.interface" and
|
||||
exists(Object interface, ClassObject owner |
|
||||
ModuleObject::named("zope.interface").getAttribute("Interface") = interface and
|
||||
owner.declaredAttribute(_) = this and
|
||||
owner.getAnImproperSuperType().getABaseType() = interface
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ string mode_from_mode_object(Object obj) {
|
||||
result = "MULTILINE" or result = "DOTALL" or result = "UNICODE" or
|
||||
result = "VERBOSE"
|
||||
) and
|
||||
exists(ModuleObject re | re.getName() = "re" and re.getAttribute(result) = obj)
|
||||
ModuleObject::named("re").getAttribute(result) = obj
|
||||
or
|
||||
exists(BinaryExpr be, Object sub | obj.getOrigin() = be |
|
||||
be.getOp() instanceof BitOr and
|
||||
|
||||
@@ -33,10 +33,7 @@ private class ExpatParser extends TaintKind {
|
||||
}
|
||||
|
||||
private FunctionObject expatCreateParseFunction() {
|
||||
exists(ModuleObject expat |
|
||||
expat.getName() = "xml.parsers.expat" and
|
||||
result = expat.getAttribute("ParserCreate")
|
||||
)
|
||||
result = ModuleObject::named("xml.parsers.expat").getAttribute("ParserCreate")
|
||||
}
|
||||
|
||||
private class ExpatCreateParser extends TaintSource {
|
||||
|
||||
@@ -257,3 +257,12 @@ class PackageObject extends ModuleObject {
|
||||
|
||||
}
|
||||
|
||||
/** Utility module for predicates relevant to the `ModuleObject` class. */
|
||||
module ModuleObject {
|
||||
|
||||
/** Gets a `ModuleObject` who's name is `name` */
|
||||
ModuleObject named(string name) {
|
||||
result.getName() = name
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user