From 5c36d7d49c7b00d5ef1054804fcd0bf7daaa834b Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 31 Oct 2023 22:03:00 +0300 Subject: [PATCH] Fix(Py3): `exec` in a local namespce --- robots.py | 7 ++++--- storage.py | 7 ++++--- writers.py | 7 ++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/robots.py b/robots.py index 84a3a2b..8fac908 100644 --- a/robots.py +++ b/robots.py @@ -18,9 +18,10 @@ robot_name, robot_params = parse_params(environ.get("BKMK_ROBOT", "forking")) def import_robot(robot_name): - exec("from Robots import bkmk_r%s" % robot_name) - exec("robot = bkmk_r%s.robot_%s" % (robot_name, robot_name)) - return robot + ns = locals() + exec("from Robots import bkmk_r%s" % robot_name, globals(), ns) + exec("robot = bkmk_r%s.robot_%s" % (robot_name, robot_name), globals(), ns) + return ns['robot'] robot = import_robot(robot_name) diff --git a/storage.py b/storage.py index abf8f48..84c8dd5 100644 --- a/storage.py +++ b/storage.py @@ -19,9 +19,10 @@ storage_name, storage_params = parse_params( def import_storage(storage_name): - exec("from Storage import bkmk_st%s" % storage_name) - exec("storage = bkmk_st%s.storage_%s" % (storage_name, storage_name)) - return storage + ns = locals() + exec("from Storage import bkmk_st%s" % storage_name, globals(), ns) + exec("storage = bkmk_st%s.storage_%s" % (storage_name, storage_name), globals(), ns) + return ns['storage'] storage = import_storage(storage_name) diff --git a/writers.py b/writers.py index 8d85670..50f74c5 100644 --- a/writers.py +++ b/writers.py @@ -18,9 +18,10 @@ writer_name, writer_params = parse_params(environ.get("BKMK_WRITER", "html")) def import_writer(writer_name): - exec("from Writers import bkmk_w%s" % writer_name) - exec("writer = bkmk_w%s.writer_%s" % (writer_name, writer_name)) - return writer + ns = locals() + exec("from Writers import bkmk_w%s" % writer_name, globals(), ns) + exec("writer = bkmk_w%s.writer_%s" % (writer_name, writer_name), globals(), ns) + return ns['writer'] writer = import_writer(writer_name) -- 2.39.5