Skip to content

'printed' question #277

@jsmith173

Description

@jsmith173

My protection function starts this way, so I'm appended the results = printed line to my code and returning with safe_globals["results"] at the end of this function. Is this the correct way to collect the print messages? Sometimes I have got error messages like this

"Line 2: SyntaxError: invalid syntax at statement: 'results = printed'"
However results = printed is not in the original code.

For the follwing input for example
@__builtins__

def interpret(code, my_dict, enable_exec=True):
	"""Interprets the given python code inside a safe execution environment"""
	warnings.filterwarnings('ignore') 
	  
	code += "\nresults = printed"
	byte_code = compile_restricted(
		code,
		filename="<string>",
		mode="exec",
	)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions