From 32f4192601281a25bf7d969cdb040b6fa678df06 Mon Sep 17 00:00:00 2001 From: Elias Pschernig Date: Thu, 29 Mar 2007 09:06:56 +0000 Subject: [PATCH] Python: Fixed a bug with import, and whitelisted wesnoth, random and heapq modules - so now all old legal scripts should be working without change. --- data/ais/parse.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/data/ais/parse.py b/data/ais/parse.py index 06563e2ec9c..c89090fe322 100644 --- a/data/ais/parse.py +++ b/data/ais/parse.py @@ -1,5 +1,8 @@ import re, os, safe +whitelisted = ["wesnoth", "heapq", "random"] +rex = re.compile(r"^import\s+(.*)", re.M) + def include(matchob): """ Regular expression callback. Handles a single import statement, returning @@ -8,6 +11,7 @@ def include(matchob): names = [x.strip() for x in matchob.group(1).split(",")] r = "" for name in names: + if name in whitelisted: continue for path in pathes: includefile = os.path.join(path, name) try: @@ -28,8 +32,8 @@ def parse_file(name): abspath = os.path.abspath(name) if abspath in already: return "" already[abspath] = 1 - code = file(abspath).read() - code = re.sub(r"^import\s+(.*)", include, code, re.M) + code = file(abspath).read().replace(chr(13), "") + code = rex.sub(include, code) return code def parse(name):