| 873 | range_constructor = Range |
| 874 | |
| 875 | def __init__(self, parent=None, session=None, **kwargs): |
| 876 | if parent and session: |
| 877 | raise ValueError('Need a parent or a session but not both') |
| 878 | |
| 879 | self.session = parent.session if parent else session |
| 880 | |
| 881 | cloud_data = kwargs.get(self._cloud_data_key, {}) |
| 882 | |
| 883 | self.object_id = cloud_data.get('name', None) |
| 884 | |
| 885 | # Choose the main_resource passed in kwargs over parent main_resource |
| 886 | main_resource = kwargs.pop('main_resource', None) or ( |
| 887 | getattr(parent, 'main_resource', None) if parent else None) |
| 888 | |
| 889 | main_resource = '{}/names/{}'.format(main_resource, self.object_id) |
| 890 | |
| 891 | super().__init__( |
| 892 | protocol=parent.protocol if parent else kwargs.get('protocol'), |
| 893 | main_resource=main_resource) |
| 894 | |
| 895 | self.name = cloud_data.get('name', None) |
| 896 | self.comment = cloud_data.get('comment', '') |
| 897 | self.scope = cloud_data.get('scope', '') |
| 898 | self.data_type = cloud_data.get('type', '') |
| 899 | self.value = cloud_data.get('value', '') |
| 900 | self.visible = cloud_data.get('visible', True) |
| 901 | |
| 902 | def __str__(self): |
| 903 | return self.__repr__() |