Commits

Ronny Pfannschmidt committed 00d0d72

strconfig decuple patch

Comments (0)

Files changed (3)

gateway-io-proxying.patch

+# HG changeset patch
+# Parent 7bdfdda4dfb68a8f9b3be89ab390e847078d626e
+
+diff --git a/execnet/bootstraper.py b/execnet/bootstraper.py
+new file mode 100644
+--- /dev/null
++++ b/execnet/bootstraper.py
+@@ -0,0 +1,2 @@
++"""
++tools to send over bootstrap code to a given io
+diff --git a/execnet/initialize_io.py b/execnet/initialize_io.py
+new file mode 100644
+--- /dev/null
++++ b/execnet/initialize_io.py
+@@ -0,0 +1,3 @@
++"""
++tools to create io's on local or remotes
++"""
+strconfig-decouple-effects
+gateway-io-proxying.patch
 find-globals-no-ast

strconfig-decouple-effects

+# HG changeset patch
+# Parent 7bdfdda4dfb68a8f9b3be89ab390e847078d626e
+
+diff --git a/execnet/gateway_base.py b/execnet/gateway_base.py
+--- a/execnet/gateway_base.py
++++ b/execnet/gateway_base.py
+@@ -253,6 +253,8 @@ class Channel(object):
+     def __init__(self, gateway, id):
+         assert isinstance(id, int)
+         self.gateway = gateway
++        #XXX: defaults copied from Unserializer
++        self._strconfig = getattr(gateway, '_strconfig', (True, False))
+         self.id = id
+         self._items = queue.Queue()
+         self._closed = False
+@@ -285,8 +287,11 @@ class Channel(object):
+                     olditem = items.get(block=False)
+                 except queue.Empty:
+                     if not (self._closed or self._receiveclosed.isSet()):
+-                        _callbacks[self.id] = (callback, endmarker, 
+-                                               getattr(self, '_strconfig', None))
++                        _callbacks[self.id] = (
++                            callback,
++                            endmarker,
++                            self._strconfig,
++                        )
+                     break
+                 else:
+                     if olditem is ENDMARKER:
+@@ -636,6 +641,7 @@ class BaseGateway(object):
+     def __init__(self, io, id, _startcount=2):
+         self._io = io
+         self.id = id
++        self._strconfig = Unserializer.py2str_as_py3str, Unserializer.py3str_as_py2str
+         self._channelfactory = ChannelFactory(self, _startcount)
+         self._receivelock = threading.RLock()
+         # globals may be NONE at process-termination
+@@ -720,7 +726,7 @@ class BaseGateway(object):
+ 
+ class SlaveGateway(BaseGateway):
+     def _local_schedulexec(self, channel, sourcetask):
+-        sourcetask = deserialize(sourcetask, self._channelfactory)
++        sourcetask = deserialize(sourcetask, self)
+         self._execqueue.put((channel, sourcetask))
+ 
+     def _terminate_execution(self):
+@@ -833,14 +839,10 @@ class Unserializer(object):
+     py3str_as_py2str = False  # false means py2 will get unicode
+ 
+     def __init__(self, stream, channel_or_gateway=None, strconfig=None):
+-        default = self.py2str_as_py3str, self.py3str_as_py2str
+-        if strconfig is None:
+-            strconfig = default
+         gateway = getattr(channel_or_gateway, 'gateway', channel_or_gateway)
+-        strconfig = getattr(channel_or_gateway, '_strconfig', default)
+-        if strconfig is default:
+-            strconfig = getattr(gateway, '_strconfig', default)
+-        self.py2str_as_py3str, self.py3str_as_py2str = strconfig
++        strconfig = getattr(channel_or_gateway, '_strconfig', strconfig)
++        if strconfig:
++            self.py2str_as_py3str, self.py3str_as_py2str = strconfig
+         self.stream = stream
+         self.channelfactory = getattr(gateway, '_channelfactory', gateway)
+ 
+diff --git a/testing/test_channel.py b/testing/test_channel.py
+--- a/testing/test_channel.py
++++ b/testing/test_channel.py
+@@ -356,6 +356,18 @@ class TestStringCoerce:
+         ch.send('a')
+         res = ch.receive()
+         assert isinstance(res, str)
++
++        gw.reconfigure(py3str_as_py2str=True)
++        ch = gw.remote_exec('channel.send(channel.receive());'*2)
++
++        ch.send('a')
++        res = ch.receive()
++        assert isinstance(res, str)
++        ch.reconfigure(py3str_as_py2str=False, py2str_as_py3str=False)
++
++        ch.send('a')
++        res = ch.receive()
++        assert isinstance(res, str)
+         gw.exit()
+ 
+     @py.test.mark.skipif('sys.version<"3.0"')
+@@ -373,5 +385,18 @@ class TestStringCoerce:
+         ch.send('a')
+         res = ch.receive()
+         assert isinstance(res, bytes)
++
++        gw.reconfigure(py3str_as_py2str=True, py2str_as_py3str=False)
++        ch = gw.remote_exec('channel.send(channel.receive());'*2)
++
++        ch.send('a')
++        res = ch.receive()
++        assert isinstance(res, bytes)
++
++        ch.reconfigure(py3str_as_py2str=False, py2str_as_py3str=True)
++        ch.send(bytes('a', 'ascii'))
++        res = ch.receive()
++        assert isinstance(res, str)
++
+         gw.exit()
+