mirror of https://github.com/m-labs/artiq.git
sync_struct/Notifier: do not pass root param to publish
This commit is contained in:
parent
0e92cfe053
commit
8b02b58a77
|
@ -13,6 +13,7 @@ immutable types. Lists and dicts can be nested arbitrarily.
|
|||
|
||||
import asyncio
|
||||
from operator import getitem
|
||||
from functools import partial
|
||||
|
||||
from artiq.protocols import pyon
|
||||
from artiq.protocols.asyncio_server import AsyncioServer
|
||||
|
@ -154,7 +155,7 @@ class Notifier:
|
|||
"""
|
||||
self._backing_struct.append(x)
|
||||
if self.root.publish is not None:
|
||||
self.root.publish(self.root, {"action": "append",
|
||||
self.root.publish({"action": "append",
|
||||
"path": self._path,
|
||||
"x": x})
|
||||
|
||||
|
@ -164,7 +165,7 @@ class Notifier:
|
|||
"""
|
||||
self._backing_struct.insert(i, x)
|
||||
if self.root.publish is not None:
|
||||
self.root.publish(self.root, {"action": "insert",
|
||||
self.root.publish({"action": "insert",
|
||||
"path": self._path,
|
||||
"i": i, "x": x})
|
||||
|
||||
|
@ -176,7 +177,7 @@ class Notifier:
|
|||
"""
|
||||
r = self._backing_struct.pop(i)
|
||||
if self.root.publish is not None:
|
||||
self.root.publish(self.root, {"action": "pop",
|
||||
self.root.publish({"action": "pop",
|
||||
"path": self._path,
|
||||
"i": i})
|
||||
return r
|
||||
|
@ -184,7 +185,7 @@ class Notifier:
|
|||
def __setitem__(self, key, value):
|
||||
self._backing_struct.__setitem__(key, value)
|
||||
if self.root.publish is not None:
|
||||
self.root.publish(self.root, {"action": "setitem",
|
||||
self.root.publish({"action": "setitem",
|
||||
"path": self._path,
|
||||
"key": key,
|
||||
"value": value})
|
||||
|
@ -192,7 +193,7 @@ class Notifier:
|
|||
def __delitem__(self, key):
|
||||
self._backing_struct.__delitem__(key)
|
||||
if self.root.publish is not None:
|
||||
self.root.publish(self.root, {"action": "delitem",
|
||||
self.root.publish({"action": "delitem",
|
||||
"path": self._path,
|
||||
"key": key})
|
||||
|
||||
|
@ -217,7 +218,7 @@ class Publisher(AsyncioServer):
|
|||
self._notifier_names = {id(v): k for k, v in notifiers.items()}
|
||||
|
||||
for notifier in notifiers.values():
|
||||
notifier.publish = self.publish
|
||||
notifier.publish = partial(self.publish, notifier)
|
||||
|
||||
@asyncio.coroutine
|
||||
def _handle_connection_cr(self, reader, writer):
|
||||
|
@ -256,8 +257,8 @@ class Publisher(AsyncioServer):
|
|||
finally:
|
||||
writer.close()
|
||||
|
||||
def publish(self, notifier, obj):
|
||||
line = pyon.encode(obj) + "\n"
|
||||
def publish(self, notifier, mod):
|
||||
line = pyon.encode(mod) + "\n"
|
||||
line = line.encode()
|
||||
notifier_name = self._notifier_names[id(notifier)]
|
||||
for recipient in self._recipients[notifier_name]:
|
||||
|
|
|
@ -67,7 +67,7 @@ class SchedulerCase(unittest.TestCase):
|
|||
expect = _get_basic_steps(1, expid)
|
||||
done = asyncio.Event()
|
||||
expect_idx = 0
|
||||
def notify(notifier, mod):
|
||||
def notify(mod):
|
||||
nonlocal expect_idx
|
||||
self.assertEqual(mod, expect[expect_idx])
|
||||
expect_idx += 1
|
||||
|
@ -104,7 +104,7 @@ class SchedulerCase(unittest.TestCase):
|
|||
background_running = asyncio.Event()
|
||||
done = asyncio.Event()
|
||||
expect_idx = 0
|
||||
def notify(notifier, mod):
|
||||
def notify(mod):
|
||||
nonlocal expect_idx
|
||||
if mod == {"path": [0],
|
||||
"value": "running",
|
||||
|
@ -138,7 +138,7 @@ class SchedulerCase(unittest.TestCase):
|
|||
first_preparing = asyncio.Event()
|
||||
done = asyncio.Event()
|
||||
expect_idx = 0
|
||||
def notify(notifier, mod):
|
||||
def notify(mod):
|
||||
nonlocal expect_idx
|
||||
if mod == {"path": [0],
|
||||
"value": "preparing",
|
||||
|
|
Loading…
Reference in New Issue