|
| 1 | +# The MIT License (MIT) |
| 2 | +# |
| 3 | +# Copyright (C) 2025 - Ericsson |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in |
| 13 | +# all copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
| 23 | +"""OutputDescriptor class file.""" |
| 24 | + |
| 25 | +import json |
| 26 | + |
| 27 | +CAN_CREATE_KEY = "canCreate" |
| 28 | +CAN_DELETE_KEY = "canDelete" |
| 29 | + |
| 30 | +# pylint: disable=too-few-public-methods,too-many-instance-attributes |
| 31 | +class OutputCapabilities: |
| 32 | + ''' |
| 33 | + classdocs |
| 34 | + ''' |
| 35 | + |
| 36 | + # pylint: disable=too-many-branches |
| 37 | + def __init__(self, params): |
| 38 | + ''' |
| 39 | + Constructor |
| 40 | + ''' |
| 41 | + |
| 42 | + # Capability canCreate |
| 43 | + if CAN_CREATE_KEY in params: |
| 44 | + # pylint: disable=invalid-name |
| 45 | + self.can_create = params.get(CAN_CREATE_KEY) |
| 46 | + del params[CAN_CREATE_KEY] |
| 47 | + else: # pragma: no cover |
| 48 | + self.can_create = None |
| 49 | + |
| 50 | + if CAN_DELETE_KEY in params: |
| 51 | + # pylint: disable=invalid-name |
| 52 | + self.can_delete = params.get(CAN_DELETE_KEY) |
| 53 | + del params[CAN_DELETE_KEY] |
| 54 | + else: # pragma: no cover |
| 55 | + self.can_delete = None |
| 56 | + |
| 57 | + def __repr__(self): |
| 58 | + return 'OutputCapabilities(canCreate={}, canDelete={})'.format(self.can_create, self.can_delete) |
| 59 | + |
| 60 | + def to_json(self): |
| 61 | + return json.dumps(self, cls=OutputCapabilities, indent=4) |
| 62 | + |
| 63 | +class OutputCapabilitiesEncoder(json.JSONEncoder): |
| 64 | + def default(self, obj): |
| 65 | + if isinstance(obj, OutputCapabilities): |
| 66 | + return { |
| 67 | + 'canCreate': obj.can_create, |
| 68 | + 'canDelete': obj.can_delete |
| 69 | + } |
| 70 | + return super().default(obj) |
0 commit comments