예제 #1
0
    def encode(self):
        """Build a dictionary that represent the ResourceDescriptor.

        Returns:
            dict. the corresponding dictionary.
        """
        if isclass(self.type) and issubclass(self.type, ResourceData):
            name = extract_type_path(self.type)

        else:
            name = extract_type_path(self.type.DATA_CLASS)

        return {TYPE_NAME: name, PROPERTIES: self.properties}
예제 #2
0
    def _encode_class(self, data_type):
        """Encode a class to an json string.

        Args:
            data_type (type): class to encode.

        Returns:
            dict. json element represent the class.
        """
        return {
            self._CLASS_TYPE: {
                TYPE_NAME: self._encode(extract_type_path(data_type))
            }
        }
예제 #3
0
    def _encode_class(self, data_type):
        """Encode a class to an XML string.

        Args:
            data_type (type): class to encode.

        Returns:
            ElementTree. XML element represent the class.
        """
        class_element = builder.E(self._CLASS_TYPE)
        type_element = builder.E(TYPE_NAME,
                                 self._encode(extract_type_path(data_type)))
        class_element.append(type_element)

        return class_element
예제 #4
0
    def _encode_resource_data(self, resource_data):
        """Encode resource data to an json string.

        Args:
            resource_data (ResourceData): resource to encode.

        Returns:
            dict. json element represent a resource.
        """
        type_name = extract_type_path(type(resource_data))

        return {
            self._RESOURCE_DATA_TYPE: {
                TYPE_NAME: self._encode(type_name),
                PROPERTIES: self._encode(resource_data.get_fields())
            }
        }
예제 #5
0
    def _encode_resource(self, resource):
        """Encode a resource to an json string.

        Args:
            resource (BaseResource): resource to encode.

        Returns:
            dict. json element represent a resource.
        """
        type_name = extract_type_path(type(resource))

        return {
            self._RESOURCE_TYPE: {
                TYPE_NAME: self._encode(type_name),
                DATA_NAME: self._encode(resource.data)
            }
        }
예제 #6
0
    def _encode_resource(self, resource):
        """Encode a resource to an XML string.

        Args:
            resource (BaseResource): resource to encode.

        Returns:
            ElementTree. XML element represent a resource.
        """
        resource_element = builder.E(self._RESOURCE_TYPE)

        type_name = extract_type_path(type(resource))

        type_element = builder.E(TYPE_NAME, self._encode(type_name))
        resource_element.append(type_element)

        data_element = builder.E(DATA_NAME, self._encode(resource.data))
        resource_element.append(data_element)

        return resource_element
예제 #7
0
    def _encode_resource_data(self, resource_data):
        """Encode resource data to an XML string.

        Args:
            resource_data (ResourceData): resource to encode.

        Returns:
            ElementTree. XML element represent a resource.
        """
        resource_element = builder.E(self._RESOURCE_DATA_TYPE)

        type_name = extract_type_path(type(resource_data))

        type_element = builder.E(TYPE_NAME, self._encode(type_name))
        resource_element.append(type_element)

        properties_element = \
            builder.E(PROPERTIES,
                      self._encode(resource_data.get_fields()))
        resource_element.append(properties_element)

        return resource_element