From f33b562cf799e655f4f534b5e79e7f0af2ec94f6 Mon Sep 17 00:00:00 2001 From: BlauFeuer Date: Mon, 20 Feb 2017 01:47:12 -0500 Subject: [PATCH] Markup and whitespace updates --- evennia/utils/batchprocessors.py | 37 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/evennia/utils/batchprocessors.py b/evennia/utils/batchprocessors.py index cf89634f58..70a741c713 100644 --- a/evennia/utils/batchprocessors.py +++ b/evennia/utils/batchprocessors.py @@ -183,12 +183,13 @@ _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.MULTILINE + re.DOTALL) +_RE_CODE_OR_HEADER = re.compile(r"(\A|^\#CODE|^\#HEADER).*?$(.*?)(?=^#CODE.*?$|^#HEADER.*?$|\Z)", + re.MULTILINE + re.DOTALL) -#------------------------------------------------------------ +# ------------------------------------------------------------- # Helper function -#------------------------------------------------------------ +# ------------------------------------------------------------- def read_batchfile(pythonpath, file_ending='.py'): """ @@ -212,8 +213,7 @@ def read_batchfile(pythonpath, file_ending='.py'): """ # find all possible absolute paths - abspaths = utils.pypath_to_realpath(pythonpath, - file_ending, settings.BASE_BATCHPROCESS_PATHS) + abspaths = utils.pypath_to_realpath(pythonpath, file_ending, settings.BASE_BATCHPROCESS_PATHS) if not abspaths: raise IOError text = None @@ -237,11 +237,11 @@ def read_batchfile(pythonpath, file_ending='.py'): return text -#------------------------------------------------------------ +# ------------------------------------------------------------- # # Batch-command processor # -#------------------------------------------------------------ +# ------------------------------------------------------------- class BatchCommandProcessor(object): """ @@ -271,35 +271,35 @@ class BatchCommandProcessor(object): text = "".join(read_batchfile(pythonpath, file_ending='.ev')) def replace_insert(match): - "Map replace entries" + """Map replace entries""" return "\n#".join(self.parse_file(match.group(1))) # insert commands from inserted files text = _RE_INSERT.sub(replace_insert, text) - #text = re.sub(r"^\#INSERT (.*?)", replace_insert, text, flags=re.MULTILINE) + # re.sub(r"^\#INSERT (.*?)", replace_insert, text, flags=re.MULTILINE) # get all commands commands = _RE_CMD_SPLIT.split(text) - #commands = re.split(r"^\#.*?$", text, flags=re.MULTILINE) - #remove eventual newline at the end of commands + # re.split(r"^\#.*?$", text, flags=re.MULTILINE) + # remove eventual newline at the end of commands commands = [c.strip('\r\n') for c in commands] commands = [c for c in commands if c] return commands -#------------------------------------------------------------ +# ------------------------------------------------------------- # # Batch-code processor # -#------------------------------------------------------------ +# ------------------------------------------------------------- def tb_filename(tb): - "Helper to get filename from traceback" + """Helper to get filename from traceback""" return tb.tb_frame.f_code.co_filename def tb_iter(tb): - "Traceback iterator." + """Traceback iterator.""" while tb is not None: yield tb tb = tb.tb_next @@ -341,7 +341,7 @@ class BatchCodeProcessor(object): text = "".join(read_batchfile(pythonpath, file_ending='.py')) def replace_insert(match): - "Run parse_file on the import before sub:ing it into this file" + """Run parse_file on the import before sub:ing it into this file""" path = match.group(1) return "# batchcode insert (%s):" % path + "\n".join(self.parse_file(path)) @@ -356,7 +356,7 @@ class BatchCodeProcessor(object): code = text[istart:iend] if mtype == "#HEADER": headers.append(code) - else: # either #CODE or matching from start of file + else: # either #CODE or matching from start of file codes.append(code) # join all headers together to one @@ -365,7 +365,6 @@ class BatchCodeProcessor(object): codes = ["%s# batchcode code:\n%s" % (header, code) for code in codes] return codes - def code_exec(self, code, extra_environ=None, debug=False): """ Execute a single code block, including imports and appending @@ -406,7 +405,7 @@ class BatchCodeProcessor(object): err = "" for iline, line in enumerate(code.split("\n")): if iline == lineno: - err += "\n{w%02i{n: %s" % (iline + 1, line) + err += "\n|w%02i|n: %s" % (iline + 1, line) elif lineno - 5 < iline < lineno + 5: err += "\n%02i: %s" % (iline + 1, line)