Coverage for d7a/alp/action.py: 82%
22 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-24 08:03 +0200
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-24 08:03 +0200
1#
2# Copyright (c) 2015-2021 University of Antwerp, Aloxy NV.
3#
4# This file is part of pyd7a.
5# See https://github.com/Sub-IoT/pyd7a for further info.
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
20# author: Christophe VG <contact@christophe.vg>
21# class implementation of action parameters
23# D7A ALP Action
24from d7a.alp.operations.requests import ReadFileData
25from d7a.alp.operations.responses import ReturnFileData
26from d7a.alp.operations.write_operations import WriteFileData
27from d7a.support.schema import Validatable, Types
29from d7a.alp.operations.operation import Operation
30from d7a.alp.operations.nop import NoOperation
32class Action(Validatable):
34 SCHEMA = [{
35 "op" : Types.BITS(6),
36 "operation": Types.OBJECT(Operation),
37 "operand" : Types.OBJECT(nullable=True) # there is no Operand base-class
38 }]
40 def __init__(self, operation=NoOperation()):
41 self.operation = operation
42 super(Action, self).__init__()
44 @property
45 def op(self):
46 return self.operation.op
48 @property
49 def operand(self):
50 return self.operation.operand
52 def __str__(self):
53 if isinstance(self.operation, ReturnFileData):
54 # when reading a known system files we output the parsed data
55 if self.operation.file_type != None and self.operation.file_data_parsed != None:
56 return "Received {} content: {}".format(self.operation.file_type.__class__.__name__,
57 self.operation.file_data_parsed)
59 return str(self.operation)