示例#1
0
    def test_size_property(self, simple_union: PointOrPointArray):
        assert simple_union.size == (PointArray().size + u64().size)

        point = Point()
        simple_union["point"] = point

        assert simple_union.size == (point.size + u64().size)
示例#2
0
    def serialize(self) -> bytes:
        out = bytearray()
        tag = u64(self.NAME_TO_TAG[self.name])
        out.extend(tag.serialize())
        out.extend(self.value.serialize())

        return out
示例#3
0
    def serialize(self) -> bytes:
        out = bytearray()
        sz = u64(len(self._values))

        out.extend(sz.serialize())
        for v in self._values:
            out.extend(v.serialize())

        return out
示例#4
0
    async def register_notifications(self):
        """
        register_notifications handles the "register" command.
        """
        facility = await self._prompt_facility()
        monitoring_time = await self._prompt_monitoring_time()

        res = await self._proxy.register_notification(u32(self._cbport),
                                                      u64(0), String(facility),
                                                      monitoring_time)

        if "error" in res:
            self._print_error(res.value)
            return

        self._known_facilities.add(facility)

        clear()
        print(
            HTML(
                f"<ansigreen>Successfully</ansigreen> registered for notifications regarding <u>{facility}</u>."
            ))
示例#5
0
    async def send_notification(
        self, action: Action.VALUES, facility: str, dtranges: Sequence[DateTimeRange]
    ):
        """
        Send notifications to notification servers regarding booking actions.

        :param facility: facility name.
        :param action: booking action performed.
        :param dtranges: time ranges involved.
        """

        rpc_dtranges = ArrayTimeRange(map(dtrange_as_rpc_tr, dtranges))
        rpc_action = Action(action)
        rpc_facility = String(facility)
        tasks = dict(
            (
                asyncio.create_task(
                    s.proxy.notify(u64(s.key), rpc_action, rpc_facility, rpc_dtranges)
                ),
                s,
            )
            for s in self._notification_servers
            if s.facility == facility
        )

        # We use wait() here because we don't want the "don't abandon" behavior
        if tasks:
            await asyncio.wait(tasks)

        # Disconnect notification servers that can't be contacted.
        for task, ns in tasks.items():
            # Ignore invocation timeouts because notifications are best-effort only.
            # The connection will eventually be closed due to the inactivity timeouts.
            if (task.exception() is not None) and (
                not isinstance(task.exception(), asyncio.TimeoutError)
            ):
                ns.task.cancel()
示例#6
0
 def serialize(self) -> bytes:
     return u64(self.value.value).serialize()
示例#7
0
 def size(self) -> int:
     return u64().size
示例#8
0
 def size(self) -> int:
     return u64().size + self.value.size
示例#9
0
 def size(self) -> int:
     return u64().size + sum(elem.size for elem in self._values)
示例#10
0
 def test_cannot_assign_wrong_type(self, simple_array: PointArray):
     with pytest.raises(TypeError):
         simple_array[0] = u64(0)
示例#11
0
 def test_size_property(self, simple_point: Point):
     assert simple_point.size == (u64().size + u64().size)
示例#12
0
 def test_cannot_assign_wrong_type(self, simple_point: Point):
     with pytest.raises(TypeError):
         simple_point["x"] = u64()
示例#13
0
 def test_size_property(self, simple_string: String):
     assert simple_string.size == (u64().size +
                                   len(simple_string.value.encode("UTF-8")))
示例#14
0
 def test_size_property(self, simple_color: Color):
     assert simple_color.size == u64().size
示例#15
0
 def test_cannot_assign_wrong_type(self, simple_union: PointOrPointArray):
     with pytest.raises(TypeError):
         simple_union["point"] = u64()
示例#16
0
 def size(self) -> int:
     return u64().size + len(self.value.encode("UTF-8"))
示例#17
0
 def serialize(self) -> bytes:
     out = bytearray()
     out.extend(u64(len(self.value)).serialize())
     out.extend(self.value.encode("UTF-8"))
     return out
示例#18
0
 def test_size_property(self, simple_array: PointArray):
     assert simple_array.size == (2 * Point().size + u64().size)