From 2bb0b236888dbc1e89d442c88f1a17904d4eae26 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 3 Sep 2017 00:09:24 +0200 Subject: [PATCH] Fix of batchcode to correctly handle code inserted at the beginning of the file, outside a block --- evennia/utils/batchprocessors.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/evennia/utils/batchprocessors.py b/evennia/utils/batchprocessors.py index 87a12daa61..1e782ce7e5 100644 --- a/evennia/utils/batchprocessors.py +++ b/evennia/utils/batchprocessors.py @@ -183,7 +183,7 @@ _ENCODINGS = settings.ENCODINGS _RE_INSERT = re.compile(r"^\#INSERT (.*)", re.MULTILINE) _RE_CLEANBLOCK = re.compile(r"^\#.*?$|^\s*$", re.MULTILINE) _RE_CMD_SPLIT = re.compile(r"^\#.*?$", re.MULTILINE) -_RE_CODE_OR_HEADER = re.compile(r"(\A|^\#CODE|^\#HEADER).*?$(.*?)(?=^#CODE.*?$|^#HEADER.*?$|\Z)", +_RE_CODE_OR_HEADER = re.compile(r"((?:\A|^)#CODE|(?:/A|^)#HEADER|\A)(.*?)$(.*?)(?=^#CODE.*?$|^#HEADER.*?$|\Z)", re.MULTILINE + re.DOTALL) @@ -352,8 +352,10 @@ class BatchCodeProcessor(object): headers = [] codes = [] for imatch, match in enumerate(list(_RE_CODE_OR_HEADER.finditer(text))): - mtype = match.group(1) - istart, iend = match.span(2) + mtype = match.group(1).strip() + # we need to handle things differently at the start of the file + mgroup = 3 if mtype else 2 + istart, iend = match.span(mgroup) code = text[istart:iend] if mtype == "#HEADER": headers.append(code)