コード例 #1
0
def test_for_loop_is_allowed():
    script = """
for i in range(10):
    pass
    """

    node = ast.parse(script, filename='script1', mode='exec')
    validator = ScriptValidator()
    validator.visit(node)
コード例 #2
0
def test_func_call_is_allowed():
    script = """
a = b()
c = func2(1, 2, 3)
    """

    node = ast.parse(script, filename='script1', mode='exec')
    validator = ScriptValidator()
    validator.visit(node)
コード例 #3
0
def test_eval_not_allowed():
    script = """
eval('1+1')
    """

    node = ast.parse(script, filename='script1', mode='exec')
    validator = ScriptValidator()
    with pytest.raises(Exception):
        validator.visit(node)
コード例 #4
0
def test_name_with_double_underscores_not_allowed():
    script = """
__get('1+1')
    """

    node = ast.parse(script, filename='script1', mode='exec')
    validator = ScriptValidator()
    with pytest.raises(Exception):
        validator.visit(node)
コード例 #5
0
def test_func_definition_not_allowed():
    script = """def f():
        print('hi')
    """

    node = ast.parse(script, filename='script1', mode='exec')
    validator = ScriptValidator()
    with pytest.raises(Exception):
        validator.visit(node)
コード例 #6
0
def test_while_loop_not_allowed():
    script = """while True:
        print('hi')
    """

    node = ast.parse(script, filename='script1', mode='exec')
    validator = ScriptValidator()
    with pytest.raises(Exception):
        validator.visit(node)
コード例 #7
0
def test_func_call_is_allowed():
    script = """
a = b()
c = func2(1, 2, 3)
    """

    node = ast.parse(script, filename='script1', mode='exec')
    validator = ScriptValidator()
    validator.visit(node)
コード例 #8
0
def test_for_loop_is_allowed():
    script = """
for i in range(10):
    print(i)
    """

    node = ast.parse(script, filename='script1', mode='exec')
    validator = ScriptValidator()
    validator.visit(node)
コード例 #9
0
def test_name_with_double_underscores_not_allowed():
    script = """
__get('1+1')
    """

    node = ast.parse(script, filename='script1', mode='exec')
    validator = ScriptValidator()
    with pytest.raises(Exception):
        validator.visit(node)
コード例 #10
0
def test_eval_not_allowed():
    script = """
eval('1+1')
    """

    node = ast.parse(script, filename='script1', mode='exec')
    validator = ScriptValidator()
    with pytest.raises(Exception):
        validator.visit(node)
コード例 #11
0
def test_while_loop_not_allowed():
    script = """while True:
        print('hi')
    """

    node = ast.parse(script, filename='script1', mode='exec')
    validator = ScriptValidator()
    with pytest.raises(Exception):
        validator.visit(node)
コード例 #12
0
def test_func_definition_not_allowed():
    script = """def f():
        print('hi')
    """

    node = ast.parse(script, filename='script1', mode='exec')
    validator = ScriptValidator()
    with pytest.raises(Exception):
        validator.visit(node)
コード例 #13
0
def test_import_not_allowed():
    script1 = """import os
    """

    validator = ScriptValidator()
    node = ast.parse(script1, filename='script1', mode='exec')
    with pytest.raises(Exception):
        validator.visit(node)

    script2 = """from os import path"""
    node = ast.parse(script2, filename='script2', mode='exec')
    with pytest.raises(Exception):
        validator.visit(node)
コード例 #14
0
ファイル: console.py プロジェクト: nickchen-mitac/fork
 def __init__(self, shell):
     win32gui.InitCommonControls()
     self.hinst = win32gui.dllhandle
     # win32api.LoadLibrary('MSFTEDIT.dll')
     self.shell = shell
     self.hicon = None
     self.list_data = {}
     self.className = "AvaConsole"
     self.title = 'Ava Console'
     self.hwnd = None
     self.job_name = 'job-1'
     self.script = ''
     self.row = 1
     self.col = 1
     self.hidden = False
     self.validator = ScriptValidator()
コード例 #15
0
def test_import_not_allowed():
    script1 = """import os
    """

    validator = ScriptValidator()
    node = ast.parse(script1, filename='script1', mode='exec')
    with pytest.raises(Exception):
        validator.visit(node)

    script2 = """from os import path"""
    node = ast.parse(script2, filename='script2', mode='exec')
    with pytest.raises(Exception):
        validator.visit(node)