Franck Pommereau

fixed missing imp module in Python 3.12

......@@ -40,3 +40,10 @@ except NameError :
unicode = str
PY3 = sys.version > "3"
try:
from imp import new_module
except (NameError, ImportError):
import types
def new_module(name):
return types.ModuleType(name)
......
......@@ -662,7 +662,7 @@ class Value (ArcAnnotation) :
class Variable (ArcAnnotation) :
"A variable which may be bound to a token."
input_allowed = True
syntax = re.compile("^[a-zA-Z]\w*$")
syntax = re.compile(r"^[a-zA-Z]\w*$")
def __init__ (self, name) :
"""Variable names must start with a letter and may continue with
any alphanumeric character.
......
......@@ -49,8 +49,9 @@ Hello from a net
((0, 0), (0, 0))
"""
import imp, sys, inspect
import sys, inspect
from functools import wraps
from snakes.compat import new_module
# apidoc skip
def update (module, objects) :
......@@ -203,7 +204,7 @@ def build (name, module, *objects) :
@return: the new module
@rtype: `module`
"""
result = imp.new_module(name)
result = new_module(name)
result.__dict__.update(module.__dict__)
update(result, objects)
result.__plugins__ = (module.__dict__.get("__plugins__",
......
......@@ -2,9 +2,10 @@
@todo: revise (actually make) documentation
"""
from snakes.compat import new_module
from snakes.plugins import plugin
from snakes.pnml import Tree, loads, dumps
import imp, sys, socket, traceback, operator
import sys, socket, traceback, operator
class QueryError (Exception) :
pass
......@@ -116,7 +117,7 @@ class Query (object) :
def run (self, envt) :
"""
>>> import imp
>>> env = imp.new_module('environment')
>>> env = new_module('environment')
>>> Query('set', 'x', 'hello').run(env)
>>> env.x
'hello'
......@@ -156,7 +157,7 @@ class Query (object) :
def _run_set (self, name, value) :
"""
>>> import imp
>>> env = imp.new_module('environment')
>>> env = new_module('environment')
>>> Query('set', 'x', 1).run(env)
>>> env.x
1
......@@ -166,7 +167,7 @@ class Query (object) :
def _run_get (self, name) :
"""
>>> import imp
>>> env = imp.new_module('environment')
>>> env = new_module('environment')
>>> env.x = 2
>>> Query('get', 'x').run(env)
2
......@@ -176,7 +177,7 @@ class Query (object) :
def _run_del (self, name) :
"""
>>> import imp
>>> env = imp.new_module('environment')
>>> env = new_module('environment')
>>> env.x = 2
>>> Query('del', 'x').run(env)
>>> env.x
......@@ -189,7 +190,7 @@ class Query (object) :
def _run_call (self, fun, *larg, **karg) :
"""
>>> import imp
>>> env = imp.new_module('environment')
>>> env = new_module('environment')
>>> env.x = 'hello'
>>> Query('call', 'x.center', 7).run(env)
' hello '
......@@ -211,7 +212,7 @@ def extend (module) :
self._verbose = verbose
self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self._sock.bind(("", port))
self._env = imp.new_module("snk")
self._env = new_module("snk")
self._env.__dict__.update(__builtins__)
self._env.__dict__.update(operator.__dict__)
self._env.__dict__.update(module.__dict__)
......@@ -259,7 +260,7 @@ def extend (module) :
self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._sock.bind(("", port))
self._sock.listen(1)
self._env = imp.new_module("snk")
self._env = new_module("snk")
self._env.__dict__.update(__builtins__)
self._env.__dict__.update(operator.__dict__)
self._env.__dict__.update(module.__dict__)
......
......@@ -12,7 +12,7 @@ abuse the term PNML for the XML produced and read by SNAKES.
import xml.dom.minidom
import pickle
import sys, inspect, os, os.path, imp, pkgutil
import sys, inspect, os, os.path, pkgutil
import snakes, snakes.plugins
from snakes import SnakesError
from snakes.compat import *
......