diff --git a/py/execnet/testing/test_xspec.py b/py/execnet/testing/test_xspec.py new file mode 100644 index 000000000..706ed8cf8 --- /dev/null +++ b/py/execnet/testing/test_xspec.py @@ -0,0 +1,34 @@ +import py + +def test_XSpec_attributes(): + XSpec = py.execnet.XSpec + spec = XSpec("socket=192.168.102.2:8888//python=c:/this/python2.5//path=d:\hello") + assert spec.socket == "192.168.102.2:8888" + assert spec.python == "c:/this/python2.5" + assert spec.path == "d:\hello" + assert spec.xyz is None + + py.test.raises(AttributeError, "spec._hello") + + spec = XSpec("socket=192.168.102.2:8888//python=python2.5") + assert spec.socket == "192.168.102.2:8888" + assert spec.python == "python2.5" + assert spec.path is None + + spec = XSpec("ssh=user@host//path=/hello/this//python=/usr/bin/python2.5") + assert spec.ssh == "user@host" + assert spec.python == "/usr/bin/python2.5" + assert spec.path == "/hello/this" + + spec = XSpec("popen") + assert spec.popen == True + +@py.test.mark.xfail +def test_makegateway_popen(): + spec = py.execnet.XSpec("popen") + gw = py.execnet.makegateway(spec) + assert gw.spec == spec + rinfo = gw.remote_info() + assert rinfo.executable == py.std.sys.executable + assert rinfo.curdir == py.std.os.getcwd() + assert rinfo.version_info == py.std.sys.version_info diff --git a/py/execnet/xspec.py b/py/execnet/xspec.py new file mode 100644 index 000000000..b9eaffc39 --- /dev/null +++ b/py/execnet/xspec.py @@ -0,0 +1,29 @@ + +import py + +class XSpec: + """ Execution Specification: key1=value1//key2=value2 ... + * keys need to be unique within the specification scope + * neither key nor value are allowed to contain "//" + * keys are not allowed to contain "=" + * keys are not allowed to start with underscore + * if no "=value" is given, assume a boolean True value + """ + def __init__(self, *strings): + for string in strings: + for keyvalue in string.split("//"): + i = keyvalue.find("=") + if i == -1: + setattr(self, keyvalue, True) + else: + setattr(self, keyvalue[:i], keyvalue[i+1:]) + + def __getattr__(self, name): + if name[0] == "_": + raise AttributeError(name) + return None + +def makegateway(spec): + pass + +