From 12d07e873ea21263fbacb5e0193d38893ceff846 Mon Sep 17 00:00:00 2001 From: Qrius Date: Wed, 5 Mar 2025 11:10:07 +0100 Subject: Seemingly up to scratch now --- src/smp/builtins.py | 13 +++++++++++++ src/smp/macro_processor.py | 7 +++---- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src/smp') diff --git a/src/smp/builtins.py b/src/smp/builtins.py index 9a27864..c1d67ce 100644 --- a/src/smp/builtins.py +++ b/src/smp/builtins.py @@ -2,6 +2,7 @@ import subprocess import urllib.request import urllib.error +import urllib.parse import datetime import markdown from gfm import AutolinkExtension, TaskListExtension # type: ignore @@ -151,6 +152,14 @@ LINK_CACHE: dict[str, tuple[bool, int, str]] = dict() def smp_builtin_wodl(macro_processor, link, timeout_seconds=5): + url = urllib.parse.urlparse(link) + link = ( + url.scheme + + "://" + + url.netloc.encode("idna").decode("ascii") + + urllib.parse.quote(url.path) + ) + if link in LINK_CACHE: return LINK_CACHE[link] @@ -179,3 +188,7 @@ def smp_builtin_dumpenv(macro_processor): out += f"{repr(key)}: {repr(val)}\n" out += "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" return out + + +# TODO Add macro that spawns a interactive shell with the python env. would allow interactive debugging :) +# needs to have a continue function or something (probably on C-d diff --git a/src/smp/macro_processor.py b/src/smp/macro_processor.py index 8fa9d91..bda6c6f 100644 --- a/src/smp/macro_processor.py +++ b/src/smp/macro_processor.py @@ -124,8 +124,9 @@ class MacroProcessor: try: return str(macro(*macro_args)) except Exception as e: - s = f"{macro_name}({','.join([repr(x) for x in macro_args])})" - raise Exception(s) + s = f"{macro_name}({','.join([repr(x) for x in args])})" + self.warnings.append(f"Error expanding macro {s} ({e})") + return s if isinstance(macro, str): expanded = macro for i, arg in enumerate(args): @@ -157,8 +158,6 @@ class MacroProcessor: skip_next_line_ending = False - line_begin = True - # We should keep track of filename, linenumber, and character number on line here # So we can give sensible error messages # Probably add to python stack trace? -- cgit v1.2.3