From 8154150a6e97621ab8ab8ec798eba8ea241b5016 Mon Sep 17 00:00:00 2001 From: stonebig Date: Sat, 11 May 2024 09:28:01 +0200 Subject: [PATCH] compatibility with PEP 667 in Python-3.13 --- sqlite_bro/sqlite_bro.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sqlite_bro/sqlite_bro.py b/sqlite_bro/sqlite_bro.py index 1e1d67a..b6a4d06 100644 --- a/sqlite_bro/sqlite_bro.py +++ b/sqlite_bro/sqlite_bro.py @@ -34,14 +34,16 @@ tipwindow = None +# starting Python-3.13, PEP 667 forces us to us a specific dictionnary pydef_locals instead of locals() +pydef_locals ={} class App: """the GUI graphic application""" def __init__(self, use_gui=True): """create a tkk graphic interface with a main window tk_win""" - self.__version__ = "0.12.2" - self._title = "of 2022-02-04a : 'Filling the blanks !'" + self.__version__ = "0.13.0" + self._title = "of 2024-05-11a : 'PEP 667 me up !'" self.conn = None # Baresql database object self.database_file = "" self.initialdir = "." @@ -1942,19 +1944,20 @@ def createpydef(self, sql): instruction = sql.strip("; \t\n\r") # create Python function in Python - exec(instruction[2:], globals(), locals()) + exec(instruction[2:], globals(), pydef_locals) # add Python function in SQLite instr_header = re.findall(r"\w+", instruction[: (instruction + ")").find(")")]) instr_name = instr_header[1] instr_parms = len(instr_header) - 2 + instr_pointer=eval(instr_name, globals(), pydef_locals) + self.conn.create_function(instr_name, instr_parms, instr_pointer) instr_add = "self.conn.create_function('%s', %s, %s)" % ( instr_name, instr_parms, instr_name, ) - exec(instr_add, globals(), locals()) # housekeeping definition of pydef in a dictionnary - the_help = dict(globals(), **locals())[instr_name].__doc__ + the_help = pydef_locals[instr_name].__doc__ self.conn_def[instr_name] = { "parameters": instr_parms, "inst": instr_add,