mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-02 04:35:45 +00:00
Python: Fixed a bug with import,
and whitelisted wesnoth, random and heapq modules - so now all old legal scripts should be working without change.
This commit is contained in:
parent
818c89a9ed
commit
32f4192601
@ -1,5 +1,8 @@
|
|||||||
import re, os, safe
|
import re, os, safe
|
||||||
|
|
||||||
|
whitelisted = ["wesnoth", "heapq", "random"]
|
||||||
|
rex = re.compile(r"^import\s+(.*)", re.M)
|
||||||
|
|
||||||
def include(matchob):
|
def include(matchob):
|
||||||
"""
|
"""
|
||||||
Regular expression callback. Handles a single import statement, returning
|
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(",")]
|
names = [x.strip() for x in matchob.group(1).split(",")]
|
||||||
r = ""
|
r = ""
|
||||||
for name in names:
|
for name in names:
|
||||||
|
if name in whitelisted: continue
|
||||||
for path in pathes:
|
for path in pathes:
|
||||||
includefile = os.path.join(path, name)
|
includefile = os.path.join(path, name)
|
||||||
try:
|
try:
|
||||||
@ -28,8 +32,8 @@ def parse_file(name):
|
|||||||
abspath = os.path.abspath(name)
|
abspath = os.path.abspath(name)
|
||||||
if abspath in already: return ""
|
if abspath in already: return ""
|
||||||
already[abspath] = 1
|
already[abspath] = 1
|
||||||
code = file(abspath).read()
|
code = file(abspath).read().replace(chr(13), "")
|
||||||
code = re.sub(r"^import\s+(.*)", include, code, re.M)
|
code = rex.sub(include, code)
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def parse(name):
|
def parse(name):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user