def test_range_as_function(): ns = {} exec( '\n'.join(['def func():'] + ['\t' + x for x in CODE.splitlines() + ['return result']]), ns) assert with_goto(ns['func'])() == EXPECTED
def test_range_as_function(): ns = {} exec('\n'.join( ['def func():'] + ['\t' + x for x in CODE.splitlines() + ['return result']] ), ns) assert with_goto(ns['func'])() == EXPECTED
def test_function_is_copy(): def func(): pass func.foo = 'bar' newfunc = with_goto(func) assert newfunc is not func assert newfunc.foo == 'bar'
def test_EXTENDED_ARG(): code = [] code.append('result = True') code.append('goto .foo') for i in range(2**16): code.append('label .l{0}'.format(i)) code.append('result = "dead code"') code.append('label .foo') assert with_goto(make_function(code))() is True
def main(): print("1、添加目录 2、更新目录") a = input() if a == "1": print("输入想要添加的文件夹目录") path = input() path = path.replace("\\", "/") md5.dir_md5_insert(path, "169.254.252.154") with_goto(main()) if a == "2": print("请输入密码:") key_1 = input() if (md5.string_md5(key_1) == key): print("输入想要更新的文件夹目录") path = input() path = path.replace("\\", "/") md5.dir_md5_update(path, "169.254.252.154") with_goto(main()) else: print("密码错误") with_goto(main())
def test_range_as_code(): ns = {} exec(with_goto(compile(CODE, '', 'exec')), ns) assert ns['result'] == EXPECTED
def test_range_as_function(): assert with_goto(make_function(CODE.splitlines()))() == EXPECTED
from goto import with_goto CODIGO = """ a = int(input('Introduce el primer sumando: ')) b = int(input('Introduce el segundo sumando: ')) label .inicio if a == 0: goto .fin a -= 1 b += 1 goto .inicio label .fin print('La suma vale', b) """ exec(with_goto(compile(CODIGO, '', 'exec')))