Ejemplo n.º 1
0
 def request(self,
             rpc: PendingRpc,
             request,
             context,
             override_pending: bool = True,
             keep_open: bool = False) -> bytes:
     """Starts the provided RPC and returns the encoded packet to send."""
     # Ensure that every context is a unique object by wrapping it in a list.
     self.open(rpc, context, override_pending, keep_open)
     _LOG.debug('Starting %s', rpc)
     return packets.encode_request(rpc, request)
Ejemplo n.º 2
0
    def request(self,
                rpc: PendingRpc,
                request,
                context,
                override_pending: bool = False) -> bytes:
        """Starts the provided RPC and returns the encoded packet to send."""
        # Ensure that every context is a unique object by wrapping it in a list.
        unique_ctx = [context]

        if override_pending:
            self._pending[rpc] = unique_ctx
        elif self._pending.setdefault(rpc, unique_ctx) is not unique_ctx:
            # If the context was not added, the RPC was already pending.
            raise Error(f'Sent request for {rpc}, but it is already pending! '
                        'Cancel the RPC before invoking it again')

        _LOG.debug('Starting %s', rpc)
        return packets.encode_request(rpc, request)
Ejemplo n.º 3
0
    def test_encode_request(self):
        data = packets.encode_request((1, 2, 3), RpcPacket(status=321))
        packet = RpcPacket()
        packet.ParseFromString(data)

        self.assertEqual(_TEST_REQUEST, packet)