mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Python: Add copy of internal Python 3 tests
Again, mostly extractor tests, and a single library test.
This commit is contained in:
1
python/ql/test/3/extractor-tests/Kannada/Test.expected
Normal file
1
python/ql/test/3/extractor-tests/Kannada/Test.expected
Normal file
@@ -0,0 +1 @@
|
||||
| Script \u0ca8\u0ca8\u0ccd\u0ca8_\u0cb8\u0ccd\u0c95\u0ccd\u0cb0\u0cbf\u0caa\u0ccd\u0c9f\u0ccd.py |
|
||||
3
python/ql/test/3/extractor-tests/Kannada/Test.ql
Normal file
3
python/ql/test/3/extractor-tests/Kannada/Test.ql
Normal file
@@ -0,0 +1,3 @@
|
||||
import python
|
||||
from Module m
|
||||
select m.toString()
|
||||
@@ -0,0 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys
|
||||
from dbgimporter import import_and_enable_debugger
|
||||
import_and_enable_debugger()
|
||||
def ಏನಾದರೂ_ಮಾಡು():
|
||||
print('ಏನೋ ಮಾಡಿದೆ'.encode(sys.stdout.encoding, errors='replace'))
|
||||
|
||||
|
||||
ಏನಾದರೂ_ಮಾಡು()
|
||||
@@ -0,0 +1,8 @@
|
||||
| 1 | AnnAssign | x | int | IntegerLiteral |
|
||||
| 2 | AnnAssign | y | Thing | something() |
|
||||
| 3 | AnnAssign | z | Any | ---- |
|
||||
| 4 | AnnAssign | Attribute | complex | ---- |
|
||||
| 5 | AnnAssign | Attribute | not_simple | None |
|
||||
| 8 | AnnAssign | a | int | IntegerLiteral |
|
||||
| 9 | AnnAssign | b | Thing | something() |
|
||||
| 10 | AnnAssign | c | Any | ---- |
|
||||
8
python/ql/test/3/extractor-tests/annotations/Assign.ql
Normal file
8
python/ql/test/3/extractor-tests/annotations/Assign.ql
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
import python
|
||||
|
||||
from AnnAssign a, string value
|
||||
where
|
||||
value = a.getValue().toString() or not exists(a.getValue()) and value = "----"
|
||||
select a.getLocation().getStartLine(), a.toString(), a.getTarget().toString(), a.getAnnotation().toString(), value
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
| 0 | 0 | 0 | 0 | Module test |
|
||||
| 1 | 1 | 1 | 1 | x |
|
||||
| 1 | 1 | 1 | 10 | AnnAssign |
|
||||
| 1 | 4 | 1 | 6 | int |
|
||||
| 1 | 10 | 1 | 10 | IntegerLiteral |
|
||||
| 2 | 1 | 2 | 1 | y |
|
||||
| 2 | 1 | 2 | 22 | AnnAssign |
|
||||
| 2 | 4 | 2 | 8 | Thing |
|
||||
| 2 | 12 | 2 | 20 | something |
|
||||
| 2 | 12 | 2 | 22 | something() |
|
||||
| 3 | 1 | 3 | 1 | z |
|
||||
| 3 | 1 | 3 | 6 | AnnAssign |
|
||||
| 3 | 4 | 3 | 6 | Any |
|
||||
| 4 | 1 | 4 | 1 | a |
|
||||
| 4 | 1 | 4 | 3 | Attribute |
|
||||
| 4 | 1 | 4 | 13 | AnnAssign |
|
||||
| 4 | 7 | 4 | 13 | complex |
|
||||
| 5 | 1 | 5 | 1 | c |
|
||||
| 5 | 1 | 5 | 3 | Attribute |
|
||||
| 5 | 1 | 5 | 23 | AnnAssign |
|
||||
| 5 | 7 | 5 | 16 | not_simple |
|
||||
| 5 | 20 | 5 | 23 | None |
|
||||
| 7 | 1 | 7 | 8 | Function f |
|
||||
| 7 | 1 | 7 | 8 | FunctionDef |
|
||||
| 7 | 1 | 7 | 8 | FunctionExpr |
|
||||
| 7 | 5 | 7 | 5 | f |
|
||||
| 8 | 5 | 8 | 5 | a |
|
||||
| 8 | 5 | 8 | 14 | AnnAssign |
|
||||
| 8 | 8 | 8 | 10 | int |
|
||||
| 8 | 14 | 8 | 14 | IntegerLiteral |
|
||||
| 9 | 5 | 9 | 5 | b |
|
||||
| 9 | 5 | 9 | 26 | AnnAssign |
|
||||
| 9 | 8 | 9 | 12 | Thing |
|
||||
| 9 | 16 | 9 | 24 | something |
|
||||
| 9 | 16 | 9 | 26 | something() |
|
||||
| 10 | 5 | 10 | 5 | c |
|
||||
| 10 | 5 | 10 | 10 | AnnAssign |
|
||||
| 10 | 8 | 10 | 10 | Any |
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
import python
|
||||
|
||||
from AstNode a, Location l
|
||||
where l = a.getLocation()
|
||||
select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn(), a.toString()
|
||||
@@ -0,0 +1,34 @@
|
||||
| 0 | Module test | 1 | IntegerLiteral |
|
||||
| 1 | AnnAssign | 2 | something |
|
||||
| 1 | IntegerLiteral | 1 | x |
|
||||
| 1 | int | 1 | AnnAssign |
|
||||
| 1 | x | 1 | int |
|
||||
| 2 | AnnAssign | 3 | z |
|
||||
| 2 | Thing | 2 | AnnAssign |
|
||||
| 2 | something | 2 | something() |
|
||||
| 2 | something() | 2 | y |
|
||||
| 2 | y | 2 | Thing |
|
||||
| 3 | AnnAssign | 4 | a |
|
||||
| 3 | Any | 3 | AnnAssign |
|
||||
| 3 | z | 3 | Any |
|
||||
| 4 | AnnAssign | 5 | None |
|
||||
| 4 | Attribute | 4 | complex |
|
||||
| 4 | a | 4 | Attribute |
|
||||
| 4 | complex | 4 | AnnAssign |
|
||||
| 5 | AnnAssign | 7 | FunctionExpr |
|
||||
| 5 | Attribute | 5 | not_simple |
|
||||
| 5 | None | 5 | c |
|
||||
| 5 | c | 5 | Attribute |
|
||||
| 5 | not_simple | 5 | AnnAssign |
|
||||
| 7 | Function f | 8 | IntegerLiteral |
|
||||
| 7 | FunctionExpr | 7 | f |
|
||||
| 7 | f | 0 | Module test |
|
||||
| 8 | AnnAssign | 9 | something |
|
||||
| 8 | IntegerLiteral | 8 | a |
|
||||
| 8 | a | 8 | AnnAssign |
|
||||
| 9 | AnnAssign | 10 | c |
|
||||
| 9 | b | 9 | AnnAssign |
|
||||
| 9 | something | 9 | something() |
|
||||
| 9 | something() | 9 | b |
|
||||
| 10 | AnnAssign | 7 | Function f |
|
||||
| 10 | c | 10 | AnnAssign |
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
import python
|
||||
|
||||
from ControlFlowNode p, ControlFlowNode s
|
||||
where p.getASuccessor() = s
|
||||
select p.getLocation().getStartLine(), p.getNode().toString(), s.getLocation().getStartLine(), s.getNode().toString()
|
||||
10
python/ql/test/3/extractor-tests/annotations/test.py
Normal file
10
python/ql/test/3/extractor-tests/annotations/test.py
Normal file
@@ -0,0 +1,10 @@
|
||||
x: int = 0
|
||||
y: Thing = something()
|
||||
z: Any
|
||||
a.x : complex
|
||||
c.y : not_simple = None
|
||||
|
||||
def f():
|
||||
a: int = 0
|
||||
b: Thing = something()
|
||||
c: Any
|
||||
@@ -0,0 +1 @@
|
||||
| 3 | For |
|
||||
4
python/ql/test/3/extractor-tests/async3.5/AsyncFor.ql
Normal file
4
python/ql/test/3/extractor-tests/async3.5/AsyncFor.ql
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
import python
|
||||
from AsyncFor a
|
||||
select a.getLocation().getStartLine(), a.toString()
|
||||
@@ -0,0 +1 @@
|
||||
| 4 | With |
|
||||
5
python/ql/test/3/extractor-tests/async3.5/AsyncWith.ql
Normal file
5
python/ql/test/3/extractor-tests/async3.5/AsyncWith.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
import python
|
||||
from AsyncWith aw
|
||||
select aw.getLocation().getStartLine(), aw.toString()
|
||||
|
||||
1
python/ql/test/3/extractor-tests/async3.5/Await.expected
Normal file
1
python/ql/test/3/extractor-tests/async3.5/Await.expected
Normal file
@@ -0,0 +1 @@
|
||||
| 6 | Await |
|
||||
4
python/ql/test/3/extractor-tests/async3.5/Await.ql
Normal file
4
python/ql/test/3/extractor-tests/async3.5/Await.ql
Normal file
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from Await a
|
||||
select a.getLocation().getStartLine(), a.toString()
|
||||
8
python/ql/test/3/extractor-tests/async3.5/test.py
Normal file
8
python/ql/test/3/extractor-tests/async3.5/test.py
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
async def foo():
|
||||
async for x in y:
|
||||
async with a as b:
|
||||
pass
|
||||
await z
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
| 7 | For | normal |
|
||||
| 14 | For | async |
|
||||
| 15 | For | normal |
|
||||
| 16 | For | async |
|
||||
| 17 | For | normal |
|
||||
| 22 | For | normal |
|
||||
| 23 | For | normal |
|
||||
| 24 | For | normal |
|
||||
| 25 | For | normal |
|
||||
7
python/ql/test/3/extractor-tests/async3.6/AsyncFor.ql
Normal file
7
python/ql/test/3/extractor-tests/async3.6/AsyncFor.ql
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
import python
|
||||
from For f, string kind
|
||||
where
|
||||
f instanceof AsyncFor and kind = "async" or
|
||||
not f instanceof AsyncFor and kind = "normal"
|
||||
select f.getLocation().getStartLine(), f.toString(), kind
|
||||
3
python/ql/test/3/extractor-tests/async3.6/Await.expected
Normal file
3
python/ql/test/3/extractor-tests/async3.6/Await.expected
Normal file
@@ -0,0 +1,3 @@
|
||||
| 9 | Await |
|
||||
| 15 | Await |
|
||||
| 17 | Await |
|
||||
4
python/ql/test/3/extractor-tests/async3.6/Await.ql
Normal file
4
python/ql/test/3/extractor-tests/async3.6/Await.ql
Normal file
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from Await a
|
||||
select a.getLocation().getStartLine(), a.toString()
|
||||
159
python/ql/test/3/extractor-tests/async3.6/Locations.expected
Normal file
159
python/ql/test/3/extractor-tests/async3.6/Locations.expected
Normal file
@@ -0,0 +1,159 @@
|
||||
| 0 | 0 | 0 | 0 | Module test |
|
||||
| 5 | 7 | 5 | 28 | Function ticker |
|
||||
| 5 | 7 | 5 | 28 | FunctionDef |
|
||||
| 5 | 7 | 5 | 28 | FunctionExpr |
|
||||
| 5 | 11 | 5 | 16 | ticker |
|
||||
| 5 | 18 | 5 | 22 | delay |
|
||||
| 5 | 25 | 5 | 26 | to |
|
||||
| 6 | 5 | 6 | 61 | ExprStmt |
|
||||
| 6 | 5 | 6 | 61 | Str |
|
||||
| 7 | 5 | 7 | 23 | For |
|
||||
| 7 | 9 | 7 | 9 | i |
|
||||
| 7 | 14 | 7 | 18 | range |
|
||||
| 7 | 14 | 7 | 22 | range() |
|
||||
| 7 | 20 | 7 | 21 | to |
|
||||
| 8 | 9 | 8 | 15 | ExprStmt |
|
||||
| 8 | 9 | 8 | 15 | Yield |
|
||||
| 8 | 15 | 8 | 15 | i |
|
||||
| 9 | 9 | 9 | 34 | Await |
|
||||
| 9 | 9 | 9 | 34 | ExprStmt |
|
||||
| 9 | 15 | 9 | 21 | asyncio |
|
||||
| 9 | 15 | 9 | 27 | Attribute |
|
||||
| 9 | 15 | 9 | 34 | Attribute() |
|
||||
| 9 | 29 | 9 | 33 | delay |
|
||||
| 13 | 7 | 13 | 14 | Function f |
|
||||
| 13 | 7 | 13 | 14 | FunctionDef |
|
||||
| 13 | 7 | 13 | 14 | FunctionExpr |
|
||||
| 13 | 11 | 13 | 11 | f |
|
||||
| 14 | 5 | 14 | 5 | a |
|
||||
| 14 | 5 | 14 | 43 | AssignStmt |
|
||||
| 14 | 9 | 14 | 43 | .0 |
|
||||
| 14 | 9 | 14 | 43 | For |
|
||||
| 14 | 9 | 14 | 43 | Function listcomp |
|
||||
| 14 | 9 | 14 | 43 | ListComp |
|
||||
| 14 | 10 | 14 | 10 | ExprStmt |
|
||||
| 14 | 10 | 14 | 10 | Yield |
|
||||
| 14 | 10 | 14 | 10 | i |
|
||||
| 14 | 22 | 14 | 22 | i |
|
||||
| 14 | 27 | 14 | 31 | aiter |
|
||||
| 14 | 27 | 14 | 33 | aiter() |
|
||||
| 14 | 38 | 14 | 38 | i |
|
||||
| 14 | 38 | 14 | 42 | BinaryExpr |
|
||||
| 14 | 38 | 14 | 42 | If |
|
||||
| 14 | 42 | 14 | 42 | IntegerLiteral |
|
||||
| 15 | 5 | 15 | 5 | b |
|
||||
| 15 | 5 | 15 | 59 | AssignStmt |
|
||||
| 15 | 9 | 15 | 59 | .0 |
|
||||
| 15 | 9 | 15 | 59 | For |
|
||||
| 15 | 9 | 15 | 59 | Function listcomp |
|
||||
| 15 | 9 | 15 | 59 | ListComp |
|
||||
| 15 | 10 | 15 | 20 | Await |
|
||||
| 15 | 10 | 15 | 20 | ExprStmt |
|
||||
| 15 | 10 | 15 | 20 | Yield |
|
||||
| 15 | 16 | 15 | 18 | fun |
|
||||
| 15 | 16 | 15 | 20 | fun() |
|
||||
| 15 | 26 | 15 | 28 | fun |
|
||||
| 15 | 33 | 15 | 37 | funcs |
|
||||
| 15 | 42 | 15 | 58 | Await |
|
||||
| 15 | 42 | 15 | 58 | If |
|
||||
| 15 | 48 | 15 | 56 | condition |
|
||||
| 15 | 48 | 15 | 58 | condition() |
|
||||
| 16 | 5 | 16 | 5 | c |
|
||||
| 16 | 5 | 16 | 43 | AssignStmt |
|
||||
| 16 | 9 | 16 | 43 | .0 |
|
||||
| 16 | 9 | 16 | 43 | For |
|
||||
| 16 | 9 | 16 | 43 | Function setcomp |
|
||||
| 16 | 9 | 16 | 43 | SetComp |
|
||||
| 16 | 10 | 16 | 10 | ExprStmt |
|
||||
| 16 | 10 | 16 | 10 | Yield |
|
||||
| 16 | 10 | 16 | 10 | i |
|
||||
| 16 | 22 | 16 | 22 | i |
|
||||
| 16 | 27 | 16 | 31 | aiter |
|
||||
| 16 | 27 | 16 | 33 | aiter() |
|
||||
| 16 | 38 | 16 | 38 | i |
|
||||
| 16 | 38 | 16 | 42 | BinaryExpr |
|
||||
| 16 | 38 | 16 | 42 | If |
|
||||
| 16 | 42 | 16 | 42 | IntegerLiteral |
|
||||
| 17 | 5 | 17 | 5 | d |
|
||||
| 17 | 5 | 17 | 59 | AssignStmt |
|
||||
| 17 | 9 | 17 | 59 | .0 |
|
||||
| 17 | 9 | 17 | 59 | For |
|
||||
| 17 | 9 | 17 | 59 | Function setcomp |
|
||||
| 17 | 9 | 17 | 59 | SetComp |
|
||||
| 17 | 10 | 17 | 20 | Await |
|
||||
| 17 | 10 | 17 | 20 | ExprStmt |
|
||||
| 17 | 10 | 17 | 20 | Yield |
|
||||
| 17 | 16 | 17 | 18 | fun |
|
||||
| 17 | 16 | 17 | 20 | fun() |
|
||||
| 17 | 26 | 17 | 28 | fun |
|
||||
| 17 | 33 | 17 | 37 | funcs |
|
||||
| 17 | 42 | 17 | 58 | Await |
|
||||
| 17 | 42 | 17 | 58 | If |
|
||||
| 17 | 48 | 17 | 56 | condition |
|
||||
| 17 | 48 | 17 | 58 | condition() |
|
||||
| 21 | 1 | 21 | 8 | Function g |
|
||||
| 21 | 1 | 21 | 8 | FunctionDef |
|
||||
| 21 | 1 | 21 | 8 | FunctionExpr |
|
||||
| 21 | 5 | 21 | 5 | g |
|
||||
| 22 | 5 | 22 | 5 | a |
|
||||
| 22 | 5 | 22 | 36 | AssignStmt |
|
||||
| 22 | 9 | 22 | 36 | .0 |
|
||||
| 22 | 9 | 22 | 36 | For |
|
||||
| 22 | 9 | 22 | 36 | Function listcomp |
|
||||
| 22 | 9 | 22 | 36 | ListComp |
|
||||
| 22 | 10 | 22 | 10 | ExprStmt |
|
||||
| 22 | 10 | 22 | 10 | Yield |
|
||||
| 22 | 10 | 22 | 10 | i |
|
||||
| 22 | 16 | 22 | 16 | i |
|
||||
| 22 | 21 | 22 | 24 | iter |
|
||||
| 22 | 21 | 22 | 26 | iter() |
|
||||
| 22 | 31 | 22 | 31 | i |
|
||||
| 22 | 31 | 22 | 35 | BinaryExpr |
|
||||
| 22 | 31 | 22 | 35 | If |
|
||||
| 22 | 35 | 22 | 35 | IntegerLiteral |
|
||||
| 23 | 5 | 23 | 5 | b |
|
||||
| 23 | 5 | 23 | 47 | AssignStmt |
|
||||
| 23 | 9 | 23 | 47 | .0 |
|
||||
| 23 | 9 | 23 | 47 | For |
|
||||
| 23 | 9 | 23 | 47 | Function listcomp |
|
||||
| 23 | 9 | 23 | 47 | ListComp |
|
||||
| 23 | 10 | 23 | 12 | fun |
|
||||
| 23 | 10 | 23 | 14 | ExprStmt |
|
||||
| 23 | 10 | 23 | 14 | Yield |
|
||||
| 23 | 10 | 23 | 14 | fun() |
|
||||
| 23 | 20 | 23 | 22 | fun |
|
||||
| 23 | 27 | 23 | 31 | funcs |
|
||||
| 23 | 36 | 23 | 44 | condition |
|
||||
| 23 | 36 | 23 | 46 | If |
|
||||
| 23 | 36 | 23 | 46 | condition() |
|
||||
| 24 | 5 | 24 | 5 | c |
|
||||
| 24 | 5 | 24 | 36 | AssignStmt |
|
||||
| 24 | 9 | 24 | 36 | .0 |
|
||||
| 24 | 9 | 24 | 36 | For |
|
||||
| 24 | 9 | 24 | 36 | Function setcomp |
|
||||
| 24 | 9 | 24 | 36 | SetComp |
|
||||
| 24 | 10 | 24 | 10 | ExprStmt |
|
||||
| 24 | 10 | 24 | 10 | Yield |
|
||||
| 24 | 10 | 24 | 10 | i |
|
||||
| 24 | 16 | 24 | 16 | i |
|
||||
| 24 | 21 | 24 | 24 | iter |
|
||||
| 24 | 21 | 24 | 26 | iter() |
|
||||
| 24 | 31 | 24 | 31 | i |
|
||||
| 24 | 31 | 24 | 35 | BinaryExpr |
|
||||
| 24 | 31 | 24 | 35 | If |
|
||||
| 24 | 35 | 24 | 35 | IntegerLiteral |
|
||||
| 25 | 5 | 25 | 5 | d |
|
||||
| 25 | 5 | 25 | 47 | AssignStmt |
|
||||
| 25 | 9 | 25 | 47 | .0 |
|
||||
| 25 | 9 | 25 | 47 | For |
|
||||
| 25 | 9 | 25 | 47 | Function setcomp |
|
||||
| 25 | 9 | 25 | 47 | SetComp |
|
||||
| 25 | 10 | 25 | 12 | fun |
|
||||
| 25 | 10 | 25 | 14 | ExprStmt |
|
||||
| 25 | 10 | 25 | 14 | Yield |
|
||||
| 25 | 10 | 25 | 14 | fun() |
|
||||
| 25 | 20 | 25 | 22 | fun |
|
||||
| 25 | 27 | 25 | 31 | funcs |
|
||||
| 25 | 36 | 25 | 44 | condition |
|
||||
| 25 | 36 | 25 | 46 | If |
|
||||
| 25 | 36 | 25 | 46 | condition() |
|
||||
6
python/ql/test/3/extractor-tests/async3.6/Locations.ql
Normal file
6
python/ql/test/3/extractor-tests/async3.6/Locations.ql
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
import python
|
||||
|
||||
from AstNode a, Location l
|
||||
where l = a.getLocation()
|
||||
select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn(), a.toString()
|
||||
@@ -0,0 +1,32 @@
|
||||
| 5 | Function ticker | 5 | delay |
|
||||
| 5 | delay | 5 | to |
|
||||
| 5 | to | 6 | Str |
|
||||
| 6 | Str | 7 | range |
|
||||
| 7 | For | 5 | Function ticker |
|
||||
| 7 | For | 7 | i |
|
||||
| 7 | i | 8 | i |
|
||||
| 7 | range | 7 | to |
|
||||
| 7 | range() | 7 | For |
|
||||
| 7 | to | 7 | range() |
|
||||
| 8 | Yield | 9 | asyncio |
|
||||
| 8 | i | 8 | Yield |
|
||||
| 9 | Attribute | 9 | delay |
|
||||
| 9 | Attribute() | 9 | Await |
|
||||
| 9 | Await | 7 | For |
|
||||
| 9 | asyncio | 9 | Attribute |
|
||||
| 9 | delay | 9 | Attribute() |
|
||||
| 13 | Function f | 14 | aiter |
|
||||
| 14 | ListComp | 14 | a |
|
||||
| 14 | a | 15 | funcs |
|
||||
| 14 | aiter | 14 | aiter() |
|
||||
| 14 | aiter() | 14 | ListComp |
|
||||
| 15 | ListComp | 15 | b |
|
||||
| 15 | b | 16 | aiter |
|
||||
| 15 | funcs | 15 | ListComp |
|
||||
| 16 | SetComp | 16 | c |
|
||||
| 16 | aiter | 16 | aiter() |
|
||||
| 16 | aiter() | 16 | SetComp |
|
||||
| 16 | c | 17 | funcs |
|
||||
| 17 | SetComp | 17 | d |
|
||||
| 17 | d | 13 | Function f |
|
||||
| 17 | funcs | 17 | SetComp |
|
||||
6
python/ql/test/3/extractor-tests/async3.6/Successors.ql
Normal file
6
python/ql/test/3/extractor-tests/async3.6/Successors.ql
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
import python
|
||||
|
||||
from ControlFlowNode p, ControlFlowNode s
|
||||
where p.getASuccessor() = s and p.getScope().(Function).isAsync()
|
||||
select p.getLocation().getStartLine(), p.getNode().toString(), s.getLocation().getStartLine(), s.getNode().toString()
|
||||
26
python/ql/test/3/extractor-tests/async3.6/test.py
Normal file
26
python/ql/test/3/extractor-tests/async3.6/test.py
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
|
||||
#PEP 525
|
||||
|
||||
async def ticker(delay, to):
|
||||
"""Yield numbers from 0 to *to* every *delay* seconds."""
|
||||
for i in range(to):
|
||||
yield i
|
||||
await asyncio.sleep(delay)
|
||||
|
||||
#PEP 530
|
||||
|
||||
async def f():
|
||||
a = [i async for i in aiter() if i % 2]
|
||||
b = [await fun() for fun in funcs if await condition()]
|
||||
c = {i async for i in aiter() if i % 2}
|
||||
d = {await fun() for fun in funcs if await condition()}
|
||||
|
||||
# Not async versions
|
||||
|
||||
def g():
|
||||
a = [i for i in iter() if i % 2]
|
||||
b = [fun() for fun in funcs if condition()]
|
||||
c = {i for i in iter() if i % 2}
|
||||
d = {fun() for fun in funcs if condition()}
|
||||
|
||||
3
python/ql/test/3/extractor-tests/decorators/test.py
Normal file
3
python/ql/test/3/extractor-tests/decorators/test.py
Normal file
@@ -0,0 +1,3 @@
|
||||
@foo[0].bar
|
||||
def baz():
|
||||
pass
|
||||
3
python/ql/test/3/extractor-tests/decorators/test.ql
Normal file
3
python/ql/test/3/extractor-tests/decorators/test.ql
Normal file
@@ -0,0 +1,3 @@
|
||||
import python
|
||||
|
||||
select any(SyntaxError s)
|
||||
@@ -0,0 +1,75 @@
|
||||
| 2 | Fstring | 0 | Str |
|
||||
| 2 | Fstring | 1 | world |
|
||||
| 2 | Fstring | 2 | Str |
|
||||
| 3 | Fstring | 0 | Str |
|
||||
| 3 | Fstring | 1 | one |
|
||||
| 3 | Fstring | 2 | Str |
|
||||
| 3 | Fstring | 3 | two |
|
||||
| 3 | Fstring | 4 | Str |
|
||||
| 3 | Fstring | 5 | three |
|
||||
| 3 | Fstring | 6 | Str |
|
||||
| 4 | Fstring | 0 | Str |
|
||||
| 4 | Fstring | 1 | cruel |
|
||||
| 4 | Fstring | 2 | Str |
|
||||
| 5 | Fstring | 0 | Str |
|
||||
| 5 | Fstring | 1 | thing |
|
||||
| 5 | Fstring | 2 | Str |
|
||||
| 6 | Fstring | 0 | Str |
|
||||
| 6 | Fstring | 1 | x |
|
||||
| 6 | Fstring | 2 | Str |
|
||||
| 8 | Fstring | 0 | Str |
|
||||
| 8 | Fstring | 1 | name |
|
||||
| 8 | Fstring | 2 | Str |
|
||||
| 8 | Fstring | 3 | BinaryExpr |
|
||||
| 8 | Fstring | 4 | Str |
|
||||
| 8 | Fstring | 5 | anniversary |
|
||||
| 8 | Fstring | 6 | Str |
|
||||
| 13 | Fstring | 0 | Str |
|
||||
| 13 | Fstring | 1 | world |
|
||||
| 13 | Fstring | 2 | Str |
|
||||
| 16 | Fstring | 0 | Str |
|
||||
| 16 | Fstring | 1 | Tuple |
|
||||
| 16 | Fstring | 2 | Str |
|
||||
| 16 | Fstring | 3 | Tuple |
|
||||
| 16 | Fstring | 4 | Str |
|
||||
| 19 | Fstring | 0 | Str |
|
||||
| 19 | Fstring | 1 | Tuple |
|
||||
| 19 | Fstring | 2 | Str |
|
||||
| 19 | Fstring | 3 | Tuple |
|
||||
| 19 | Fstring | 4 | Str |
|
||||
| 32 | Fstring | 0 | Str |
|
||||
| 32 | Fstring | 1 | IntegerLiteral |
|
||||
| 32 | Fstring | 2 | Str |
|
||||
| 34 | Fstring | 0 | Str |
|
||||
| 34 | Fstring | 1 | IntegerLiteral |
|
||||
| 34 | Fstring | 2 | Str |
|
||||
| 36 | Fstring | 0 | Str |
|
||||
| 36 | Fstring | 1 | IntegerLiteral |
|
||||
| 36 | Fstring | 2 | Str |
|
||||
| 38 | Fstring | 0 | Str |
|
||||
| 38 | Fstring | 1 | IntegerLiteral |
|
||||
| 38 | Fstring | 2 | Str |
|
||||
| 53 | Fstring | 0 | Str |
|
||||
| 53 | Fstring | 1 | degrees |
|
||||
| 53 | Fstring | 2 | Str |
|
||||
| 56 | Fstring | 0 | Str |
|
||||
| 56 | Fstring | 1 | IntegerLiteral |
|
||||
| 56 | Fstring | 2 | Str |
|
||||
| 59 | Fstring | 0 | Str |
|
||||
| 59 | Fstring | 1 | IntegerLiteral |
|
||||
| 59 | Fstring | 2 | Str |
|
||||
| 62 | Fstring | 0 | Str |
|
||||
| 62 | Fstring | 1 | IntegerLiteral |
|
||||
| 62 | Fstring | 2 | Str |
|
||||
| 67 | Fstring | 0 | Str |
|
||||
| 67 | Fstring | 1 | IntegerLiteral |
|
||||
| 67 | Fstring | 2 | Str |
|
||||
| 70 | Fstring | 0 | Str |
|
||||
| 70 | Fstring | 1 | IntegerLiteral |
|
||||
| 70 | Fstring | 2 | Str |
|
||||
| 75 | Fstring | 0 | Str |
|
||||
| 75 | Fstring | 1 | IntegerLiteral |
|
||||
| 75 | Fstring | 2 | Str |
|
||||
| 78 | Fstring | 0 | Str |
|
||||
| 78 | Fstring | 1 | IntegerLiteral |
|
||||
| 78 | Fstring | 2 | Str |
|
||||
8
python/ql/test/3/extractor-tests/fstrings3.6/FString.ql
Normal file
8
python/ql/test/3/extractor-tests/fstrings3.6/FString.ql
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
import python
|
||||
|
||||
from Fstring str, int n, Expr e
|
||||
where e = str.getValue(n) and
|
||||
not exists(FormattedValue v | v.getFormatSpec() = str)
|
||||
select str.getLocation().getStartLine(), str.toString(), n, e.toString()
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
| 2 | FormattedValue | | world | s |
|
||||
| 3 | FormattedValue | #06x | one | |
|
||||
| 3 | FormattedValue | ++++ | three | s |
|
||||
| 3 | FormattedValue | format | two | |
|
||||
| 4 | FormattedValue | | cruel | |
|
||||
| 5 | FormattedValue | | thing | a |
|
||||
| 6 | FormattedValue | | x | r |
|
||||
| 8 | FormattedValue | | BinaryExpr | |
|
||||
| 8 | FormattedValue | | name | |
|
||||
| 8 | FormattedValue | %A, %B %d, %Y | anniversary | |
|
||||
| 13 | FormattedValue | | world | s |
|
||||
10
python/ql/test/3/extractor-tests/fstrings3.6/Formatted.ql
Normal file
10
python/ql/test/3/extractor-tests/fstrings3.6/Formatted.ql
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
import python
|
||||
|
||||
from FormattedValue val, string format, string typeconv
|
||||
where
|
||||
|
||||
(typeconv = val.getConversion() or not exists(val.getConversion()) and typeconv = " ")
|
||||
and
|
||||
(format = val.getFormatSpec().getValue(0).(StrConst).getText() or not exists(val.getFormatSpec()) and format = "")
|
||||
select val.getLocation().getStartLine(), val, format, val.getValue(), typeconv
|
||||
116
python/ql/test/3/extractor-tests/fstrings3.6/Locations.expected
Normal file
116
python/ql/test/3/extractor-tests/fstrings3.6/Locations.expected
Normal file
@@ -0,0 +1,116 @@
|
||||
| 2 | 1 | 2 | 9 | Str |
|
||||
| 2 | 1 | 2 | 18 | Fstring |
|
||||
| 2 | 10 | 2 | 14 | world |
|
||||
| 2 | 17 | 2 | 18 | Str |
|
||||
| 3 | 1 | 3 | 4 | Str |
|
||||
| 3 | 1 | 3 | 42 | Fstring |
|
||||
| 3 | 5 | 3 | 7 | one |
|
||||
| 3 | 13 | 3 | 15 | Str |
|
||||
| 3 | 16 | 3 | 18 | two |
|
||||
| 3 | 26 | 3 | 28 | Str |
|
||||
| 3 | 29 | 3 | 33 | three |
|
||||
| 3 | 41 | 3 | 42 | Str |
|
||||
| 4 | 1 | 4 | 11 | Str |
|
||||
| 4 | 1 | 4 | 24 | Fstring |
|
||||
| 4 | 12 | 4 | 16 | cruel |
|
||||
| 4 | 17 | 4 | 24 | Str |
|
||||
| 5 | 1 | 5 | 8 | Str |
|
||||
| 5 | 1 | 5 | 17 | Fstring |
|
||||
| 5 | 9 | 5 | 13 | thing |
|
||||
| 5 | 16 | 5 | 17 | Str |
|
||||
| 6 | 1 | 6 | 3 | Str |
|
||||
| 6 | 1 | 6 | 8 | Fstring |
|
||||
| 6 | 4 | 6 | 4 | x |
|
||||
| 6 | 7 | 6 | 8 | Str |
|
||||
| 8 | 1 | 8 | 16 | Str |
|
||||
| 8 | 1 | 10 | 31 | Fstring |
|
||||
| 8 | 17 | 8 | 20 | name |
|
||||
| 8 | 21 | 9 | 1 | Str |
|
||||
| 9 | 2 | 9 | 4 | age |
|
||||
| 9 | 2 | 9 | 6 | BinaryExpr |
|
||||
| 9 | 6 | 9 | 6 | IntegerLiteral |
|
||||
| 9 | 7 | 10 | 1 | Str |
|
||||
| 10 | 2 | 10 | 12 | anniversary |
|
||||
| 10 | 27 | 10 | 31 | Str |
|
||||
| 13 | 1 | 13 | 12 | Str |
|
||||
| 13 | 1 | 13 | 21 | Fstring |
|
||||
| 13 | 13 | 13 | 17 | world |
|
||||
| 13 | 20 | 13 | 21 | Str |
|
||||
| 16 | 1 | 16 | 3 | Str |
|
||||
| 16 | 1 | 16 | 13 | Fstring |
|
||||
| 16 | 4 | 16 | 4 | IntegerLiteral |
|
||||
| 16 | 4 | 16 | 6 | Tuple |
|
||||
| 16 | 6 | 16 | 6 | IntegerLiteral |
|
||||
| 16 | 7 | 16 | 8 | Str |
|
||||
| 16 | 9 | 16 | 9 | IntegerLiteral |
|
||||
| 16 | 9 | 16 | 11 | Tuple |
|
||||
| 16 | 11 | 16 | 11 | IntegerLiteral |
|
||||
| 16 | 12 | 16 | 13 | Str |
|
||||
| 19 | 1 | 19 | 3 | Str |
|
||||
| 19 | 1 | 19 | 11 | Fstring |
|
||||
| 19 | 4 | 19 | 4 | IntegerLiteral |
|
||||
| 19 | 4 | 19 | 5 | Tuple |
|
||||
| 19 | 6 | 19 | 7 | Str |
|
||||
| 19 | 8 | 19 | 8 | IntegerLiteral |
|
||||
| 19 | 8 | 19 | 9 | Tuple |
|
||||
| 19 | 10 | 19 | 11 | Str |
|
||||
| 24 | 2 | 24 | 9 | Str |
|
||||
| 26 | 2 | 26 | 5 | Str |
|
||||
| 28 | 2 | 28 | 9 | Str |
|
||||
| 30 | 2 | 30 | 5 | Str |
|
||||
| 32 | 2 | 32 | 6 | Str |
|
||||
| 32 | 2 | 32 | 11 | Fstring |
|
||||
| 32 | 7 | 32 | 7 | IntegerLiteral |
|
||||
| 32 | 8 | 32 | 11 | Str |
|
||||
| 34 | 2 | 34 | 4 | Str |
|
||||
| 34 | 2 | 34 | 7 | Fstring |
|
||||
| 34 | 5 | 34 | 5 | IntegerLiteral |
|
||||
| 34 | 6 | 34 | 7 | Str |
|
||||
| 36 | 2 | 36 | 6 | Str |
|
||||
| 36 | 2 | 36 | 11 | Fstring |
|
||||
| 36 | 7 | 36 | 7 | IntegerLiteral |
|
||||
| 36 | 8 | 36 | 11 | Str |
|
||||
| 38 | 2 | 38 | 4 | Str |
|
||||
| 38 | 2 | 38 | 7 | Fstring |
|
||||
| 38 | 5 | 38 | 5 | IntegerLiteral |
|
||||
| 38 | 6 | 38 | 7 | Str |
|
||||
| 40 | 2 | 40 | 8 | Str |
|
||||
| 42 | 2 | 42 | 4 | Str |
|
||||
| 44 | 2 | 44 | 8 | Str |
|
||||
| 46 | 2 | 46 | 4 | Str |
|
||||
| 53 | 1 | 53 | 18 | Str |
|
||||
| 53 | 1 | 53 | 27 | Fstring |
|
||||
| 53 | 19 | 53 | 25 | degrees |
|
||||
| 53 | 26 | 53 | 27 | Str |
|
||||
| 56 | 1 | 56 | 3 | Str |
|
||||
| 56 | 1 | 56 | 21 | Fstring |
|
||||
| 56 | 4 | 56 | 4 | IntegerLiteral |
|
||||
| 56 | 5 | 56 | 21 | Str |
|
||||
| 59 | 1 | 59 | 7 | Str |
|
||||
| 59 | 1 | 59 | 11 | Fstring |
|
||||
| 59 | 8 | 59 | 8 | IntegerLiteral |
|
||||
| 59 | 9 | 59 | 11 | Str |
|
||||
| 62 | 1 | 62 | 4 | Str |
|
||||
| 62 | 1 | 62 | 10 | Fstring |
|
||||
| 62 | 5 | 62 | 5 | IntegerLiteral |
|
||||
| 62 | 6 | 62 | 10 | Str |
|
||||
| 67 | 1 | 67 | 6 | Str |
|
||||
| 67 | 1 | 67 | 43 | Fstring |
|
||||
| 67 | 7 | 67 | 7 | IntegerLiteral |
|
||||
| 67 | 38 | 67 | 43 | Str |
|
||||
| 70 | 1 | 70 | 6 | Str |
|
||||
| 70 | 1 | 70 | 39 | Fstring |
|
||||
| 70 | 7 | 70 | 7 | IntegerLiteral |
|
||||
| 70 | 34 | 70 | 39 | Str |
|
||||
| 75 | 1 | 75 | 7 | Str |
|
||||
| 75 | 1 | 75 | 11 | Fstring |
|
||||
| 75 | 8 | 75 | 8 | IntegerLiteral |
|
||||
| 75 | 9 | 75 | 11 | Str |
|
||||
| 78 | 1 | 78 | 4 | Str |
|
||||
| 78 | 1 | 78 | 10 | Fstring |
|
||||
| 78 | 5 | 78 | 5 | IntegerLiteral |
|
||||
| 78 | 6 | 78 | 10 | Str |
|
||||
| 81 | 1 | 81 | 3 | Str |
|
||||
| 82 | 1 | 82 | 3 | Str |
|
||||
| 83 | 1 | 83 | 7 | Str |
|
||||
| 84 | 1 | 84 | 7 | Str |
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
import python
|
||||
|
||||
from Expr e, Location l
|
||||
where l = e.getLocation()
|
||||
select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn(), e.toString()
|
||||
117
python/ql/test/3/extractor-tests/fstrings3.6/Successors.expected
Normal file
117
python/ql/test/3/extractor-tests/fstrings3.6/Successors.expected
Normal file
@@ -0,0 +1,117 @@
|
||||
| 0 | 0 | Module test |
|
||||
| 1 | 2 | "hello " |
|
||||
| 2 | 2 | world |
|
||||
| 3 | 2 | "" |
|
||||
| 4 | 2 | Fstring |
|
||||
| 5 | 3 | "1" |
|
||||
| 6 | 3 | one |
|
||||
| 7 | 3 | "2" |
|
||||
| 8 | 3 | two |
|
||||
| 9 | 3 | "3" |
|
||||
| 10 | 3 | three |
|
||||
| 11 | 3 | "" |
|
||||
| 12 | 3 | Fstring |
|
||||
| 13 | 4 | "goodbye " |
|
||||
| 14 | 4 | cruel |
|
||||
| 15 | 4 | " world" |
|
||||
| 16 | 4 | Fstring |
|
||||
| 17 | 5 | "ascii" |
|
||||
| 18 | 5 | thing |
|
||||
| 19 | 5 | "" |
|
||||
| 20 | 5 | Fstring |
|
||||
| 21 | 6 | "" |
|
||||
| 22 | 6 | x |
|
||||
| 23 | 6 | "" |
|
||||
| 24 | 6 | Fstring |
|
||||
| 25 | 8 | "My name is " |
|
||||
| 26 | 8 | name |
|
||||
| 27 | 8 | ", my age next year is \n" |
|
||||
| 28 | 9 | age |
|
||||
| 29 | 9 | IntegerLiteral |
|
||||
| 30 | 9 | BinaryExpr |
|
||||
| 31 | 9 | ", my anniversary is \n" |
|
||||
| 32 | 10 | anniversary |
|
||||
| 33 | 10 | "." |
|
||||
| 34 | 8 | Fstring |
|
||||
| 35 | 13 | "hello " |
|
||||
| 36 | 13 | world |
|
||||
| 37 | 13 | "" |
|
||||
| 38 | 13 | Fstring |
|
||||
| 39 | 16 | "" |
|
||||
| 40 | 16 | IntegerLiteral |
|
||||
| 41 | 16 | IntegerLiteral |
|
||||
| 42 | 16 | Tuple |
|
||||
| 43 | 16 | "" |
|
||||
| 44 | 16 | IntegerLiteral |
|
||||
| 45 | 16 | IntegerLiteral |
|
||||
| 46 | 16 | Tuple |
|
||||
| 47 | 16 | "" |
|
||||
| 48 | 16 | Fstring |
|
||||
| 49 | 19 | "" |
|
||||
| 50 | 19 | IntegerLiteral |
|
||||
| 51 | 19 | Tuple |
|
||||
| 52 | 19 | "" |
|
||||
| 53 | 19 | IntegerLiteral |
|
||||
| 54 | 19 | Tuple |
|
||||
| 55 | 19 | "" |
|
||||
| 56 | 19 | Fstring |
|
||||
| 57 | 24 | "0" |
|
||||
| 58 | 26 | "0" |
|
||||
| 59 | 28 | "0" |
|
||||
| 60 | 30 | "0" |
|
||||
| 61 | 32 | "" |
|
||||
| 62 | 32 | IntegerLiteral |
|
||||
| 63 | 32 | "" |
|
||||
| 64 | 32 | Fstring |
|
||||
| 65 | 34 | "" |
|
||||
| 66 | 34 | IntegerLiteral |
|
||||
| 67 | 34 | "" |
|
||||
| 68 | 34 | Fstring |
|
||||
| 69 | 36 | "" |
|
||||
| 70 | 36 | IntegerLiteral |
|
||||
| 71 | 36 | "" |
|
||||
| 72 | 36 | Fstring |
|
||||
| 73 | 38 | "" |
|
||||
| 74 | 38 | IntegerLiteral |
|
||||
| 75 | 38 | "" |
|
||||
| 76 | 38 | Fstring |
|
||||
| 77 | 40 | "0" |
|
||||
| 78 | 42 | "0" |
|
||||
| 79 | 44 | "0" |
|
||||
| 80 | 46 | "0" |
|
||||
| 81 | 53 | "\u00b0" |
|
||||
| 82 | 53 | degrees |
|
||||
| 83 | 53 | "" |
|
||||
| 84 | 53 | Fstring |
|
||||
| 85 | 56 | "" |
|
||||
| 86 | 56 | IntegerLiteral |
|
||||
| 87 | 56 | "\u00b0" |
|
||||
| 88 | 56 | Fstring |
|
||||
| 89 | 59 | "{{ a" |
|
||||
| 90 | 59 | IntegerLiteral |
|
||||
| 91 | 59 | "c" |
|
||||
| 92 | 59 | Fstring |
|
||||
| 93 | 62 | "a" |
|
||||
| 94 | 62 | IntegerLiteral |
|
||||
| 95 | 62 | "{{c" |
|
||||
| 96 | 62 | Fstring |
|
||||
| 97 | 67 | "pre" |
|
||||
| 98 | 67 | IntegerLiteral |
|
||||
| 99 | 67 | "post" |
|
||||
| 100 | 67 | Fstring |
|
||||
| 101 | 70 | "pre" |
|
||||
| 102 | 70 | IntegerLiteral |
|
||||
| 103 | 70 | "post" |
|
||||
| 104 | 70 | Fstring |
|
||||
| 105 | 75 | "}} a" |
|
||||
| 106 | 75 | IntegerLiteral |
|
||||
| 107 | 75 | "c" |
|
||||
| 108 | 75 | Fstring |
|
||||
| 109 | 78 | "a" |
|
||||
| 110 | 78 | IntegerLiteral |
|
||||
| 111 | 78 | "}}c" |
|
||||
| 112 | 78 | Fstring |
|
||||
| 113 | 81 | "" |
|
||||
| 114 | 82 | "" |
|
||||
| 115 | 83 | "" |
|
||||
| 116 | 84 | "" |
|
||||
12
python/ql/test/3/extractor-tests/fstrings3.6/Successors.ql
Normal file
12
python/ql/test/3/extractor-tests/fstrings3.6/Successors.ql
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
import python
|
||||
|
||||
string repr(AstNode a) {
|
||||
not a instanceof StrConst and result = a.toString()
|
||||
or
|
||||
result = "\"" + a.(StrConst).getText() + "\""
|
||||
}
|
||||
|
||||
from ControlFlowNode p, ControlFlowNode s, BasicBlock b, int n
|
||||
where p.getASuccessor() = s and p = b.getNode(n)
|
||||
select n, p.getLocation().getStartLine(), repr(p.getNode())
|
||||
84
python/ql/test/3/extractor-tests/fstrings3.6/test.py
Normal file
84
python/ql/test/3/extractor-tests/fstrings3.6/test.py
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
f'hello {world!s}'
|
||||
f'1{one:#06x}2{two:format}3{three!s:++++}'
|
||||
f'goodbye {cruel} world'
|
||||
f'ascii{thing!a}'
|
||||
f'{x!r}'
|
||||
|
||||
f'''My name is {name}, my age next year is
|
||||
{age+1}, my anniversary is
|
||||
{anniversary:%A, %B %d, %Y}.'''
|
||||
|
||||
#Implicit concatenation
|
||||
"hello" f' {world!s}'
|
||||
|
||||
# Simplified version of FP reported in issue #1990
|
||||
f"{1,1}{1,1}"
|
||||
|
||||
# Trailing comma for 1-element tuple:
|
||||
f"{1,}{1,}"
|
||||
|
||||
# Parenthesized with newline after string.
|
||||
# Simplified version of FP reported in issue #2453
|
||||
|
||||
(f"""0"""
|
||||
)
|
||||
(f"0"
|
||||
)
|
||||
(f'''0'''
|
||||
)
|
||||
(f'0'
|
||||
)
|
||||
(f"""{0}"""
|
||||
)
|
||||
(f"{0}"
|
||||
)
|
||||
(f'''{0}'''
|
||||
)
|
||||
(f'{0}'
|
||||
)
|
||||
("""0"""
|
||||
)
|
||||
("0"
|
||||
)
|
||||
('''0'''
|
||||
)
|
||||
('0'
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
# Unicode literals inside fstrings in initial position
|
||||
f'\N{DEGREE SIGN}{degrees}'
|
||||
|
||||
# Unicode literals inside fstrings in non-initial position
|
||||
f'{1}\N{DEGREE SIGN}'
|
||||
|
||||
# {{ in initial position
|
||||
f'{{ a{1}c'
|
||||
|
||||
# {{ in non-initial position
|
||||
f'a{1}{{c'
|
||||
|
||||
|
||||
|
||||
# Unicode literals inside fspecs in initial position
|
||||
f'pre{1:\N{LATIN SMALL LETTER B}>0.0f}post'
|
||||
|
||||
# Unicode literals inside fspecs in initial position
|
||||
f'pre{1:0\N{LATIN SMALL LETTER B}}post'
|
||||
|
||||
|
||||
|
||||
# }} in initial position
|
||||
f'}} a{1}c'
|
||||
|
||||
# }} in non-initial position
|
||||
f'a{1}}}c'
|
||||
|
||||
# Empty f-strings
|
||||
f''
|
||||
f""
|
||||
f''''''
|
||||
f""""""
|
||||
@@ -0,0 +1,17 @@
|
||||
| 4 | Fstring | 0 | Str |
|
||||
| 4 | Fstring | 1 | foo |
|
||||
| 4 | Fstring | 2 | Str |
|
||||
| 5 | Fstring | 0 | Str |
|
||||
| 5 | Fstring | 1 | foo |
|
||||
| 5 | Fstring | 2 | Str |
|
||||
| 6 | Fstring | 0 | Str |
|
||||
| 6 | Fstring | 1 | Attribute() |
|
||||
| 6 | Fstring | 2 | Str |
|
||||
| 7 | Fstring | 0 | Str |
|
||||
| 7 | Fstring | 1 | foo |
|
||||
| 7 | Fstring | 2 | Str |
|
||||
| 8 | Fstring | 0 | Str |
|
||||
| 8 | Fstring | 1 | foo |
|
||||
| 8 | Fstring | 2 | Str |
|
||||
| 8 | Fstring | 3 | Attribute() |
|
||||
| 8 | Fstring | 4 | Str |
|
||||
8
python/ql/test/3/extractor-tests/fstrings3.8/FString.ql
Normal file
8
python/ql/test/3/extractor-tests/fstrings3.8/FString.ql
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
import python
|
||||
|
||||
from Fstring str, int n, Expr e
|
||||
where e = str.getValue(n) and
|
||||
not exists(FormattedValue v | v.getFormatSpec() = str)
|
||||
select str.getLocation().getStartLine(), str.toString(), n, e.toString()
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
| 1 | 1 | 1 | 3 | foo |
|
||||
| 1 | 7 | 1 | 7 | IntegerLiteral |
|
||||
| 3 | 1 | 3 | 3 | bar |
|
||||
| 3 | 7 | 3 | 11 | Str |
|
||||
| 4 | 1 | 4 | 5 | print |
|
||||
| 4 | 1 | 4 | 16 | print() |
|
||||
| 4 | 7 | 4 | 9 | Str |
|
||||
| 4 | 7 | 4 | 15 | Fstring |
|
||||
| 4 | 10 | 4 | 12 | foo |
|
||||
| 4 | 14 | 4 | 15 | Str |
|
||||
| 5 | 1 | 5 | 5 | print |
|
||||
| 5 | 1 | 5 | 18 | print() |
|
||||
| 5 | 7 | 5 | 9 | Str |
|
||||
| 5 | 7 | 5 | 17 | Fstring |
|
||||
| 5 | 10 | 5 | 12 | foo |
|
||||
| 5 | 16 | 5 | 17 | Str |
|
||||
| 6 | 1 | 6 | 5 | print |
|
||||
| 6 | 1 | 6 | 24 | print() |
|
||||
| 6 | 7 | 6 | 9 | Str |
|
||||
| 6 | 7 | 6 | 23 | Fstring |
|
||||
| 6 | 10 | 6 | 12 | bar |
|
||||
| 6 | 10 | 6 | 18 | Attribute |
|
||||
| 6 | 10 | 6 | 20 | Attribute() |
|
||||
| 6 | 22 | 6 | 23 | Str |
|
||||
| 7 | 1 | 7 | 5 | print |
|
||||
| 7 | 1 | 7 | 23 | print() |
|
||||
| 7 | 7 | 7 | 10 | Str |
|
||||
| 7 | 7 | 7 | 22 | Fstring |
|
||||
| 7 | 11 | 7 | 13 | foo |
|
||||
| 7 | 20 | 7 | 22 | Str |
|
||||
| 8 | 1 | 8 | 5 | print |
|
||||
| 8 | 1 | 8 | 37 | print() |
|
||||
| 8 | 7 | 8 | 10 | Str |
|
||||
| 8 | 7 | 8 | 36 | Fstring |
|
||||
| 8 | 11 | 8 | 13 | foo |
|
||||
| 8 | 20 | 8 | 21 | Str |
|
||||
| 8 | 22 | 8 | 24 | bar |
|
||||
| 8 | 22 | 8 | 30 | Attribute |
|
||||
| 8 | 22 | 8 | 32 | Attribute() |
|
||||
| 8 | 34 | 8 | 36 | Str |
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
import python
|
||||
|
||||
from Expr e, Location l
|
||||
where l = e.getLocation()
|
||||
select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn(), e.toString()
|
||||
@@ -0,0 +1,41 @@
|
||||
| 0 | 0 | Module test |
|
||||
| 1 | 1 | IntegerLiteral |
|
||||
| 2 | 1 | foo |
|
||||
| 3 | 3 | "bar" |
|
||||
| 4 | 3 | bar |
|
||||
| 5 | 4 | print |
|
||||
| 6 | 4 | "" |
|
||||
| 7 | 4 | foo |
|
||||
| 8 | 4 | "" |
|
||||
| 9 | 4 | Fstring |
|
||||
| 10 | 4 | print() |
|
||||
| 11 | 5 | print |
|
||||
| 12 | 5 | "" |
|
||||
| 13 | 5 | foo |
|
||||
| 14 | 5 | "" |
|
||||
| 15 | 5 | Fstring |
|
||||
| 16 | 5 | print() |
|
||||
| 17 | 6 | print |
|
||||
| 18 | 6 | "" |
|
||||
| 19 | 6 | bar |
|
||||
| 20 | 6 | Attribute |
|
||||
| 21 | 6 | Attribute() |
|
||||
| 22 | 6 | "" |
|
||||
| 23 | 6 | Fstring |
|
||||
| 24 | 6 | print() |
|
||||
| 25 | 7 | print |
|
||||
| 26 | 7 | "*" |
|
||||
| 27 | 7 | foo |
|
||||
| 28 | 7 | "*" |
|
||||
| 29 | 7 | Fstring |
|
||||
| 30 | 7 | print() |
|
||||
| 31 | 8 | print |
|
||||
| 32 | 8 | "*" |
|
||||
| 33 | 8 | foo |
|
||||
| 34 | 8 | "" |
|
||||
| 35 | 8 | bar |
|
||||
| 36 | 8 | Attribute |
|
||||
| 37 | 8 | Attribute() |
|
||||
| 38 | 8 | "*" |
|
||||
| 39 | 8 | Fstring |
|
||||
| 40 | 8 | print() |
|
||||
12
python/ql/test/3/extractor-tests/fstrings3.8/Successors.ql
Normal file
12
python/ql/test/3/extractor-tests/fstrings3.8/Successors.ql
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
import python
|
||||
|
||||
string repr(AstNode a) {
|
||||
not a instanceof StrConst and result = a.toString()
|
||||
or
|
||||
result = "\"" + a.(StrConst).getText() + "\""
|
||||
}
|
||||
|
||||
from ControlFlowNode p, ControlFlowNode s, BasicBlock b, int n
|
||||
where p.getASuccessor() = s and p = b.getNode(n)
|
||||
select n, p.getLocation().getStartLine(), repr(p.getNode())
|
||||
8
python/ql/test/3/extractor-tests/fstrings3.8/test.py
Normal file
8
python/ql/test/3/extractor-tests/fstrings3.8/test.py
Normal file
@@ -0,0 +1,8 @@
|
||||
foo = 5
|
||||
|
||||
bar = "bar"
|
||||
print(f'{foo=}')
|
||||
print(f'{foo = }')
|
||||
print(f'{bar.upper()=}')
|
||||
print(f'*{foo=:+<20}*')
|
||||
print(f'*{foo=:+<20}{bar.upper()=}*')
|
||||
1
python/ql/test/3/extractor-tests/import_depth/options
Normal file
1
python/ql/test/3/extractor-tests/import_depth/options
Normal file
@@ -0,0 +1 @@
|
||||
semmle-extractor-options: --lang=3 --max-import-depth=1
|
||||
@@ -0,0 +1,5 @@
|
||||
| Module package |
|
||||
| Module package.__init__ |
|
||||
| Module sys |
|
||||
| Module sys.monitoring |
|
||||
| Module test |
|
||||
1
python/ql/test/3/extractor-tests/import_depth/test.py
Normal file
1
python/ql/test/3/extractor-tests/import_depth/test.py
Normal file
@@ -0,0 +1 @@
|
||||
import package
|
||||
6
python/ql/test/3/extractor-tests/import_depth/test.ql
Normal file
6
python/ql/test/3/extractor-tests/import_depth/test.ql
Normal file
@@ -0,0 +1,6 @@
|
||||
import python
|
||||
|
||||
from ModuleObject m
|
||||
/* Exclude the builtins module as it has a different name under 2 and 3. */
|
||||
where not m = theBuiltinModuleObject()
|
||||
select m.toString()
|
||||
1
python/ql/test/3/extractor-tests/matmult/Test.expected
Normal file
1
python/ql/test/3/extractor-tests/matmult/Test.expected
Normal file
@@ -0,0 +1 @@
|
||||
| 3 | BinaryExpr |
|
||||
7
python/ql/test/3/extractor-tests/matmult/Test.ql
Normal file
7
python/ql/test/3/extractor-tests/matmult/Test.ql
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
import python
|
||||
|
||||
from BinaryExpr b
|
||||
where b.getOp() instanceof MatMult
|
||||
select b.getLocation().getStartLine(), b.toString()
|
||||
|
||||
3
python/ql/test/3/extractor-tests/matmult/matmul.py
Normal file
3
python/ql/test/3/extractor-tests/matmult/matmul.py
Normal file
@@ -0,0 +1,3 @@
|
||||
def matmul(a,b):
|
||||
a * b
|
||||
return a @ b
|
||||
3
python/ql/test/3/extractor-tests/multibyte/Test.expected
Normal file
3
python/ql/test/3/extractor-tests/multibyte/Test.expected
Normal file
@@ -0,0 +1,3 @@
|
||||
| test.py:4:1:4:11 | Str | \u0111\u0142e\u00b6\u014b\u00b6\u0142\u014b |
|
||||
| test.py:4:15:4:19 | Str | hi |
|
||||
| test.py:4:23:4:27 | Str | \n |
|
||||
4
python/ql/test/3/extractor-tests/multibyte/Test.ql
Normal file
4
python/ql/test/3/extractor-tests/multibyte/Test.ql
Normal file
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from StrConst s
|
||||
select s, s.getText()
|
||||
1
python/ql/test/3/extractor-tests/multibyte/options
Normal file
1
python/ql/test/3/extractor-tests/multibyte/options
Normal file
@@ -0,0 +1 @@
|
||||
automatic_locations: true
|
||||
4
python/ql/test/3/extractor-tests/multibyte/test.py
Normal file
4
python/ql/test/3/extractor-tests/multibyte/test.py
Normal file
@@ -0,0 +1,4 @@
|
||||
#coding=utf8
|
||||
|
||||
|
||||
u"đłe¶ŋ¶łŋ" + u"hi" + u"\n"
|
||||
@@ -0,0 +1,6 @@
|
||||
| 2 | IntegerLiteral | 1000000000000000 | 1_000_000_000_000_000 |
|
||||
| 3 | IntegerLiteral | 4294967295 | 0x_FF_FF_FF_FF |
|
||||
| 4 | IntegerLiteral | 3218 | 0b_1100_1001_0010 |
|
||||
| 5 | IntegerLiteral | 12345678 | 1_2_3_4_5_6_7_8 |
|
||||
| 6 | IntegerLiteral | 12 | 1_2 |
|
||||
| 7 | FloatLiteral | 1.234e+57 | 1_2.3_4E+5_6 |
|
||||
6
python/ql/test/3/extractor-tests/numbers/Literal.ql
Normal file
6
python/ql/test/3/extractor-tests/numbers/Literal.ql
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
import python
|
||||
|
||||
from Num n
|
||||
select n.getLocation().getStartLine(), n.toString(), n.getN(), n.getText()
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
| 2 | 1 | 2 | 21 | IntegerLiteral |
|
||||
| 3 | 1 | 3 | 14 | IntegerLiteral |
|
||||
| 4 | 1 | 4 | 17 | IntegerLiteral |
|
||||
| 5 | 1 | 5 | 15 | IntegerLiteral |
|
||||
| 6 | 1 | 6 | 3 | IntegerLiteral |
|
||||
| 7 | 1 | 7 | 12 | FloatLiteral |
|
||||
6
python/ql/test/3/extractor-tests/numbers/Locations.ql
Normal file
6
python/ql/test/3/extractor-tests/numbers/Locations.ql
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
import python
|
||||
|
||||
from Expr e, Location l
|
||||
where l = e.getLocation()
|
||||
select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn(), e.toString()
|
||||
7
python/ql/test/3/extractor-tests/numbers/test.py
Normal file
7
python/ql/test/3/extractor-tests/numbers/test.py
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
1_000_000_000_000_000
|
||||
0x_FF_FF_FF_FF
|
||||
0b_1100_1001_0010
|
||||
1_2_3_4_5_6_7_8
|
||||
1_2
|
||||
1_2.3_4E+5_6
|
||||
1
python/ql/test/3/extractor-tests/options
Normal file
1
python/ql/test/3/extractor-tests/options
Normal file
@@ -0,0 +1 @@
|
||||
automatic_locations: true
|
||||
@@ -0,0 +1,9 @@
|
||||
| test.py:5:1:5:30 | Function positional_only_arg |
|
||||
| test.py:9:1:9:40 | Function all_markers |
|
||||
| test.py:13:1:23:2 | Function all_markers_with_args_and_kwargs |
|
||||
| test.py:27:1:27:64 | Function all_markers_with_defaults |
|
||||
| test.py:31:1:38:2 | Function long_one_with_long_parameter_names |
|
||||
| test.py:42:1:42:14 | Function lambda |
|
||||
| test.py:44:1:44:32 | Function lambda |
|
||||
| test.py:46:1:46:49 | Function lambda |
|
||||
| test.py:48:1:48:42 | Function lambda |
|
||||
4
python/ql/test/3/extractor-tests/positional_only/Test.ql
Normal file
4
python/ql/test/3/extractor-tests/positional_only/Test.ql
Normal file
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from Function f
|
||||
select f
|
||||
70
python/ql/test/3/extractor-tests/positional_only/test.py
Normal file
70
python/ql/test/3/extractor-tests/positional_only/test.py
Normal file
@@ -0,0 +1,70 @@
|
||||
# Taken from https://github.com/psf/black/blob/2848e2e1d6527d6031ea020cd991fd73e52c4a0b/tests/data/pep_570.py
|
||||
|
||||
# See license at end of file.
|
||||
|
||||
def positional_only_arg(a, /):
|
||||
pass
|
||||
|
||||
|
||||
def all_markers(a, b, /, c, d, *, e, f):
|
||||
pass
|
||||
|
||||
|
||||
def all_markers_with_args_and_kwargs(
|
||||
a_long_one,
|
||||
b_long_one,
|
||||
/,
|
||||
c_long_one,
|
||||
d_long_one,
|
||||
*args,
|
||||
e_long_one,
|
||||
f_long_one,
|
||||
**kwargs,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def all_markers_with_defaults(a, b=1, /, c=2, d=3, *, e=4, f=5):
|
||||
pass
|
||||
|
||||
|
||||
def long_one_with_long_parameter_names(
|
||||
but_all_of_them,
|
||||
are_positional_only,
|
||||
arguments_mmmmkay,
|
||||
so_this_is_only_valid_after,
|
||||
three_point_eight,
|
||||
/,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
lambda a, /: a
|
||||
|
||||
lambda a, b, /, c, d, *, e, f: a
|
||||
|
||||
lambda a, b, /, c, d, *args, e, f, **kwargs: args
|
||||
|
||||
lambda a, b=1, /, c=2, d=3, *, e=4, f=5: 1
|
||||
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2018 Łukasz Langa
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
@@ -0,0 +1,5 @@
|
||||
| test.py:2:12:2:17 | Tuple |
|
||||
| test.py:6:15:6:20 | Tuple |
|
||||
| test.py:8:15:8:19 | Tuple |
|
||||
| test.py:10:21:10:23 | Tuple |
|
||||
| test.py:10:27:10:29 | Tuple |
|
||||
11
python/ql/test/3/extractor-tests/tuple_unpacking/test.py
Normal file
11
python/ql/test/3/extractor-tests/tuple_unpacking/test.py
Normal file
@@ -0,0 +1,11 @@
|
||||
def cons(x, ys):
|
||||
return x, *ys
|
||||
|
||||
def cons_each(xs, ys):
|
||||
for x in xs:
|
||||
yield x, *ys
|
||||
|
||||
print(cons(1,(2,3,4)))
|
||||
|
||||
for l in cons_each((1,2),(3,4)):
|
||||
print(l)
|
||||
3
python/ql/test/3/extractor-tests/tuple_unpacking/test.ql
Normal file
3
python/ql/test/3/extractor-tests/tuple_unpacking/test.ql
Normal file
@@ -0,0 +1,3 @@
|
||||
import python
|
||||
|
||||
select any(Tuple t)
|
||||
94
python/ql/test/3/extractor-tests/unpacking/AST.expected
Normal file
94
python/ql/test/3/extractor-tests/unpacking/AST.expected
Normal file
@@ -0,0 +1,94 @@
|
||||
| 0 | 0 | 0 | 0 | Module test |
|
||||
| 2 | 1 | 2 | 5 | print |
|
||||
| 2 | 1 | 2 | 29 | ExprStmt |
|
||||
| 2 | 1 | 2 | 29 | print() |
|
||||
| 2 | 7 | 2 | 10 | Starred |
|
||||
| 2 | 8 | 2 | 10 | List |
|
||||
| 2 | 9 | 2 | 9 | IntegerLiteral |
|
||||
| 2 | 13 | 2 | 16 | Starred |
|
||||
| 2 | 14 | 2 | 16 | List |
|
||||
| 2 | 15 | 2 | 15 | IntegerLiteral |
|
||||
| 2 | 19 | 2 | 19 | IntegerLiteral |
|
||||
| 2 | 22 | 2 | 28 | Starred |
|
||||
| 2 | 23 | 2 | 28 | List |
|
||||
| 2 | 24 | 2 | 24 | IntegerLiteral |
|
||||
| 2 | 27 | 2 | 27 | IntegerLiteral |
|
||||
| 3 | 1 | 3 | 2 | fn |
|
||||
| 3 | 1 | 3 | 42 | ExprStmt |
|
||||
| 3 | 1 | 3 | 42 | fn() |
|
||||
| 3 | 4 | 3 | 21 | DictUnpacking |
|
||||
| 3 | 6 | 3 | 21 | Dict |
|
||||
| 3 | 7 | 3 | 9 | Str |
|
||||
| 3 | 7 | 3 | 12 | KeyValuePair |
|
||||
| 3 | 12 | 3 | 12 | IntegerLiteral |
|
||||
| 3 | 15 | 3 | 17 | Str |
|
||||
| 3 | 15 | 3 | 20 | KeyValuePair |
|
||||
| 3 | 20 | 3 | 20 | IntegerLiteral |
|
||||
| 3 | 24 | 3 | 41 | DictUnpacking |
|
||||
| 3 | 26 | 3 | 41 | Dict |
|
||||
| 3 | 27 | 3 | 29 | Str |
|
||||
| 3 | 27 | 3 | 32 | KeyValuePair |
|
||||
| 3 | 32 | 3 | 32 | IntegerLiteral |
|
||||
| 3 | 35 | 3 | 37 | Str |
|
||||
| 3 | 35 | 3 | 40 | KeyValuePair |
|
||||
| 3 | 40 | 3 | 40 | IntegerLiteral |
|
||||
| 4 | 1 | 4 | 1 | g |
|
||||
| 4 | 1 | 4 | 30 | ExprStmt |
|
||||
| 4 | 1 | 4 | 30 | g() |
|
||||
| 4 | 3 | 4 | 3 | IntegerLiteral |
|
||||
| 4 | 6 | 4 | 7 | Starred |
|
||||
| 4 | 7 | 4 | 7 | x |
|
||||
| 4 | 10 | 4 | 10 | IntegerLiteral |
|
||||
| 4 | 13 | 4 | 15 | Keyword |
|
||||
| 4 | 15 | 4 | 15 | y |
|
||||
| 4 | 18 | 4 | 19 | Starred |
|
||||
| 4 | 19 | 4 | 19 | z |
|
||||
| 4 | 22 | 4 | 24 | Keyword |
|
||||
| 4 | 24 | 4 | 24 | IntegerLiteral |
|
||||
| 4 | 27 | 4 | 29 | DictUnpacking |
|
||||
| 4 | 29 | 4 | 29 | p |
|
||||
| 5 | 1 | 5 | 1 | h |
|
||||
| 5 | 1 | 5 | 14 | ExprStmt |
|
||||
| 5 | 1 | 5 | 14 | h() |
|
||||
| 5 | 3 | 5 | 5 | DictUnpacking |
|
||||
| 5 | 5 | 5 | 5 | x |
|
||||
| 5 | 7 | 5 | 9 | Keyword |
|
||||
| 5 | 9 | 5 | 9 | IntegerLiteral |
|
||||
| 5 | 11 | 5 | 13 | DictUnpacking |
|
||||
| 5 | 13 | 5 | 13 | y |
|
||||
| 7 | 1 | 7 | 9 | Starred |
|
||||
| 7 | 1 | 7 | 12 | ExprStmt |
|
||||
| 7 | 1 | 7 | 12 | Tuple |
|
||||
| 7 | 2 | 7 | 6 | range |
|
||||
| 7 | 2 | 7 | 9 | range() |
|
||||
| 7 | 8 | 7 | 8 | IntegerLiteral |
|
||||
| 7 | 12 | 7 | 12 | IntegerLiteral |
|
||||
| 10 | 1 | 10 | 14 | ExprStmt |
|
||||
| 10 | 1 | 10 | 14 | List |
|
||||
| 10 | 2 | 10 | 10 | Starred |
|
||||
| 10 | 3 | 10 | 7 | range |
|
||||
| 10 | 3 | 10 | 10 | range() |
|
||||
| 10 | 9 | 10 | 9 | IntegerLiteral |
|
||||
| 10 | 13 | 10 | 13 | IntegerLiteral |
|
||||
| 13 | 1 | 13 | 26 | ExprStmt |
|
||||
| 13 | 1 | 13 | 26 | Set |
|
||||
| 13 | 2 | 13 | 10 | Starred |
|
||||
| 13 | 3 | 13 | 7 | range |
|
||||
| 13 | 3 | 13 | 10 | range() |
|
||||
| 13 | 9 | 13 | 9 | IntegerLiteral |
|
||||
| 13 | 13 | 13 | 13 | IntegerLiteral |
|
||||
| 13 | 16 | 13 | 25 | Starred |
|
||||
| 13 | 18 | 13 | 18 | IntegerLiteral |
|
||||
| 13 | 18 | 13 | 24 | Tuple |
|
||||
| 13 | 21 | 13 | 21 | IntegerLiteral |
|
||||
| 13 | 24 | 13 | 24 | IntegerLiteral |
|
||||
| 16 | 1 | 16 | 20 | Dict |
|
||||
| 16 | 1 | 16 | 20 | ExprStmt |
|
||||
| 16 | 2 | 16 | 4 | Str |
|
||||
| 16 | 2 | 16 | 7 | KeyValuePair |
|
||||
| 16 | 7 | 16 | 7 | IntegerLiteral |
|
||||
| 16 | 10 | 16 | 19 | DictUnpacking |
|
||||
| 16 | 12 | 16 | 19 | Dict |
|
||||
| 16 | 13 | 16 | 15 | Str |
|
||||
| 16 | 13 | 16 | 18 | KeyValuePair |
|
||||
| 16 | 18 | 16 | 18 | IntegerLiteral |
|
||||
7
python/ql/test/3/extractor-tests/unpacking/AST.ql
Normal file
7
python/ql/test/3/extractor-tests/unpacking/AST.ql
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
import python
|
||||
|
||||
from AstNode a, int bl, int bc, int el, int ec
|
||||
where a.getLocation().hasLocationInfo(_, bl, bc, el, ec)
|
||||
select bl, bc, el, ec, a.toString()
|
||||
|
||||
17
python/ql/test/3/extractor-tests/unpacking/test.py
Normal file
17
python/ql/test/3/extractor-tests/unpacking/test.py
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
print(*[1], *[2], 3, *[4, 5])
|
||||
fn(**{'a': 1, 'c': 3}, **{'b': 2, 'd': 4})
|
||||
g(1, *x, 2, a=y, *z, b=3, **p)
|
||||
h(**x,a=1,**y)
|
||||
|
||||
*range(4), 4
|
||||
#(0, 1, 2, 3, 4)
|
||||
|
||||
[*range(4), 4]
|
||||
#[0, 1, 2, 3, 4]
|
||||
|
||||
{*range(4), 4, *(5, 6, 7)}
|
||||
#{0, 1, 2, 3, 4, 5, 6, 7}
|
||||
|
||||
{'x': 1, **{'y': 2}}
|
||||
#{'x': 1, 'y': 2}
|
||||
@@ -0,0 +1,32 @@
|
||||
| test.py:5:2:5:7 | AssignExpr | a | IntegerLiteral |
|
||||
| test.py:6:2:6:7 | AssignExpr | a | a |
|
||||
| test.py:7:5:7:33 | AssignExpr | match | Attribute() |
|
||||
| test.py:9:2:9:10 | AssignExpr | y | f() |
|
||||
| test.py:10:38:10:46 | AssignExpr | y | f() |
|
||||
| test.py:11:2:11:10 | AssignExpr | y | f() |
|
||||
| test.py:12:7:12:16 | AssignExpr | y1 | f() |
|
||||
| test.py:13:8:13:16 | AssignExpr | y | f() |
|
||||
| test.py:16:17:16:23 | AssignExpr | p | IntegerLiteral |
|
||||
| test.py:20:18:20:24 | AssignExpr | p | IntegerLiteral |
|
||||
| test.py:24:10:24:15 | AssignExpr | x | IntegerLiteral |
|
||||
| test.py:25:2:25:15 | AssignExpr | x | Lambda |
|
||||
| test.py:26:2:26:22 | AssignExpr | x | Lambda |
|
||||
| test.py:26:16:26:21 | AssignExpr | y | IntegerLiteral |
|
||||
| test.py:27:15:27:42 | AssignExpr | m | Attribute() |
|
||||
| test.py:28:6:28:11 | AssignExpr | y | IntegerLiteral |
|
||||
| test.py:29:2:29:21 | AssignExpr | z | AssignExpr |
|
||||
| test.py:29:8:29:20 | AssignExpr | y | AssignExpr |
|
||||
| test.py:29:14:29:19 | AssignExpr | x | IntegerLiteral |
|
||||
| test.py:30:2:30:29 | AssignExpr | info | Tuple |
|
||||
| test.py:31:2:31:7 | AssignExpr | x | IntegerLiteral |
|
||||
| test.py:32:2:32:21 | AssignExpr | total | BinaryExpr |
|
||||
| test.py:33:5:33:26 | AssignExpr | lines | Attribute() |
|
||||
| test.py:34:5:34:10 | AssignExpr | x | IntegerLiteral |
|
||||
| test.py:35:10:35:29 | AssignExpr | category | Str |
|
||||
| test.py:36:12:36:24 | AssignExpr | longline | l |
|
||||
| test.py:38:4:38:53 | AssignExpr | env_base | Attribute() |
|
||||
| test.py:40:26:40:65 | AssignExpr | ans | Attribute() |
|
||||
| test.py:42:5:42:10 | AssignExpr | b | IntegerLiteral |
|
||||
| test.py:43:6:43:11 | AssignExpr | b | IntegerLiteral |
|
||||
| test.py:44:8:44:13 | AssignExpr | b | IntegerLiteral |
|
||||
| test.py:46:7:46:15 | AssignExpr | x | f() |
|
||||
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from AssignExpr e
|
||||
select e, e.getTarget().toString(), e.getValue().toString()
|
||||
69
python/ql/test/3/extractor-tests/walrus_operator/test.py
Normal file
69
python/ql/test/3/extractor-tests/walrus_operator/test.py
Normal file
@@ -0,0 +1,69 @@
|
||||
# Based on https://github.com/psf/black/blob/d8fa8df0526de9c0968e0a3568008f58eae45364/tests/data/pep_572.py
|
||||
|
||||
# See license at end of file.
|
||||
|
||||
(a := 1)
|
||||
(a := a)
|
||||
if (match := pattern.search(data)) is None:
|
||||
pass
|
||||
[y := f(x), y ** 2, y ** 3]
|
||||
filtered_data = [y for x in data if (y := f(x)) is None]
|
||||
(y := f(x))
|
||||
y0 = (y1 := f(x))
|
||||
foo(x=(y := f(x)))
|
||||
|
||||
|
||||
def foo(answer=(p := 42)):
|
||||
pass
|
||||
|
||||
|
||||
def foo(answer: (p := 42) = 5):
|
||||
pass
|
||||
|
||||
|
||||
lambda: (x := 1)
|
||||
(x := lambda: 1)
|
||||
(x := lambda: (y := 1))
|
||||
lambda line: (m := re.match(pattern, line)) and m.group(1)
|
||||
x = (y := 0)
|
||||
(z := (y := (x := 0)))
|
||||
(info := (name, phone, *rest))
|
||||
(x := 1, 2)
|
||||
(total := total + tax)
|
||||
len(lines := f.readlines())
|
||||
foo(x := 3, cat="vector")
|
||||
foo(cat=(category := "vector"))
|
||||
if any(len(longline := l) >= 100 for l in lines):
|
||||
print(longline)
|
||||
if env_base := os.environ.get("PYTHONUSERBASE", None):
|
||||
return env_base
|
||||
if self._is_special and (ans := self._check_nans(context=context)):
|
||||
return ans
|
||||
foo(b := 2, a=1)
|
||||
foo((b := 2), a=1)
|
||||
foo(c=(b := 2), a=1)
|
||||
|
||||
while x := f(x):
|
||||
pass
|
||||
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2018 Łukasz Langa
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
26
python/ql/test/3/library-tests/calls/NewApi.expected
Normal file
26
python/ql/test/3/library-tests/calls/NewApi.expected
Normal file
@@ -0,0 +1,26 @@
|
||||
| 4 | position | 0 | IntegerLiteral |
|
||||
| 4 | position | 1 | IntegerLiteral |
|
||||
| 4 | position | 2 | Starred |
|
||||
| 5 | named | 0 | DictUnpacking |
|
||||
| 6 | named | 0 | Keyword |
|
||||
| 6 | named | 1 | DictUnpacking |
|
||||
| 6 | position | 0 | IntegerLiteral |
|
||||
| 6 | position | 1 | Starred |
|
||||
| 7 | named | 0 | Keyword |
|
||||
| 7 | named | 1 | DictUnpacking |
|
||||
| 11 | position | 0 | Starred |
|
||||
| 11 | position | 1 | Starred |
|
||||
| 11 | position | 2 | IntegerLiteral |
|
||||
| 11 | position | 3 | Starred |
|
||||
| 12 | named | 0 | DictUnpacking |
|
||||
| 12 | named | 1 | DictUnpacking |
|
||||
| 13 | named | 0 | Keyword |
|
||||
| 13 | named | 1 | Keyword |
|
||||
| 13 | named | 2 | DictUnpacking |
|
||||
| 13 | position | 0 | IntegerLiteral |
|
||||
| 13 | position | 1 | Starred |
|
||||
| 13 | position | 2 | IntegerLiteral |
|
||||
| 13 | position | 3 | Starred |
|
||||
| 14 | named | 0 | DictUnpacking |
|
||||
| 14 | named | 1 | Keyword |
|
||||
| 14 | named | 2 | DictUnpacking |
|
||||
10
python/ql/test/3/library-tests/calls/NewApi.ql
Normal file
10
python/ql/test/3/library-tests/calls/NewApi.ql
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
import python
|
||||
|
||||
from Call c, AstNode arg, int n, string what
|
||||
where
|
||||
what = "position" and arg = c.getPositionalArg(n)
|
||||
or
|
||||
what = "named" and arg = c.getNamedArg(n)
|
||||
select
|
||||
c.getLocation().getStartLine(), what, n, arg.toString()
|
||||
23
python/ql/test/3/library-tests/calls/OldApi.expected
Normal file
23
python/ql/test/3/library-tests/calls/OldApi.expected
Normal file
@@ -0,0 +1,23 @@
|
||||
| 4 | test.py:4:3:4:3 | IntegerLiteral | 0 |
|
||||
| 4 | test.py:4:6:4:6 | IntegerLiteral | 1 |
|
||||
| 4 | test.py:4:10:4:14 | List | * |
|
||||
| 5 | test.py:5:5:5:20 | Dict | ** |
|
||||
| 6 | test.py:6:3:6:3 | IntegerLiteral | 0 |
|
||||
| 6 | test.py:6:7:6:7 | x | * |
|
||||
| 6 | test.py:6:12:6:12 | y | a |
|
||||
| 6 | test.py:6:17:6:17 | p | ** |
|
||||
| 7 | test.py:7:5:7:5 | IntegerLiteral | a |
|
||||
| 7 | test.py:7:9:7:9 | y | ** |
|
||||
| 11 | test.py:11:8:11:10 | List | * |
|
||||
| 11 | test.py:11:14:11:16 | List | * |
|
||||
| 11 | test.py:11:23:11:28 | List | * |
|
||||
| 12 | test.py:12:6:12:21 | Dict | ** |
|
||||
| 12 | test.py:12:26:12:41 | Dict | ** |
|
||||
| 13 | test.py:13:3:13:3 | IntegerLiteral | 0 |
|
||||
| 13 | test.py:13:7:13:7 | x | * |
|
||||
| 13 | test.py:13:15:13:15 | y | a |
|
||||
| 13 | test.py:13:19:13:19 | z | * |
|
||||
| 13 | test.py:13:24:13:24 | IntegerLiteral | b |
|
||||
| 13 | test.py:13:29:13:29 | p | ** |
|
||||
| 14 | test.py:14:5:14:5 | x | ** |
|
||||
| 14 | test.py:14:13:14:13 | y | ** |
|
||||
20
python/ql/test/3/library-tests/calls/OldApi.ql
Normal file
20
python/ql/test/3/library-tests/calls/OldApi.ql
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
import python
|
||||
|
||||
from Call c, Expr arg, string what
|
||||
where
|
||||
exists(int n |
|
||||
arg = c.getArg(n) and what = n.toString()
|
||||
)
|
||||
or
|
||||
arg = c.getStarargs() and what = "*"
|
||||
or
|
||||
arg = c.getKwargs() and what = "**"
|
||||
or
|
||||
exists(Keyword k |
|
||||
c.getAKeyword() = k |
|
||||
what = k.getArg() and
|
||||
arg = k.getValue()
|
||||
)
|
||||
|
||||
select c.getLocation().getStartLine(), arg, what
|
||||
14
python/ql/test/3/library-tests/calls/test.py
Normal file
14
python/ql/test/3/library-tests/calls/test.py
Normal file
@@ -0,0 +1,14 @@
|
||||
#Multi-version
|
||||
|
||||
|
||||
a(1, 2, *[3,4])
|
||||
b(**{'b': 2, 'd': 4})
|
||||
c(1, *x, a=y, **p)
|
||||
d(a=1,**y)
|
||||
|
||||
#Python 3.5 only
|
||||
|
||||
print(*[1], *[2], 3, *[4, 5])
|
||||
fn(**{'a': 1, 'c': 3}, **{'b': 2, 'd': 4})
|
||||
g(1, *x, 2, a=y, *z, b=3, **p)
|
||||
h(**x,a=1,**y)
|
||||
Reference in New Issue
Block a user