From: Oleg Broytman Date: Tue, 31 Oct 2023 19:03:00 +0000 (+0300) Subject: Fix(Py3): `exec` in a local namespce X-Git-Tag: 5.0.0~65 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=5c36d7d49c7b00d5ef1054804fcd0bf7daaa834b;p=bookmarks_db.git Fix(Py3): `exec` in a local namespce --- 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)