]> git.phdru.name Git - bookmarks_db.git/commitdiff
Fix(Py3): `exec` in a local namespce
authorOleg Broytman <phd@phdru.name>
Tue, 31 Oct 2023 19:03:00 +0000 (22:03 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 12 Nov 2023 19:21:09 +0000 (22:21 +0300)
robots.py
storage.py
writers.py

index 84a3a2bcac5069158e5acd243629d5305c145b9b..8fac908dd92bec6117d8a59a36eab17bd73b41e4 100644 (file)
--- 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)
index abf8f48014a9d35d2442ded84822386dbb086830..84c8dd5167de64112df1ee3431fa738ff1511df7 100644 (file)
@@ -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)
index 8d856704c96371581b917f41ac758b9741588a48..50f74c5c1168772d31afef5ff4c5d04b3d37465c 100644 (file)
@@ -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)