def _find_class_for_collection(cls, collection_name):
        """Look in the parent modules for classes matching the element name.

        One or both of element/class name must be specified.

        Args:
            collection_name: The name of the collection type.
        Returns:
            A Resource class.
        """
        return cls._find_class_for(util.singularize(collection_name))
    def _find_class_for_collection(cls, collection_name):
        """Look in the parent modules for classes matching the element name.

        One or both of element/class name must be specified.

        Args:
            collection_name: The name of the collection type.
        Returns:
            A Resource class.
        """
        return cls._find_class_for(util.singularize(collection_name))
Esempio n. 3
0
    def __to_xml_element(obj, root, dasherize):
        root = dasherize and root.replace('_', '-') or root
        root_element = util.ET.Element(root)
        if isinstance(obj, list):
            root_element.set('type', 'array')
            for value in obj:
                root_element.append(ShopifyResource.__to_xml_element(value, util.singularize(root), dasherize))
        elif isinstance(obj, dict):
            for key, value in obj.iteritems():
                root_element.append(ShopifyResource.__to_xml_element(value, key, dasherize))
        else:
            util.serialize(obj, root_element)

        return root_element
Esempio n. 4
0
    def __to_xml_element(obj, root, dasherize):
        root = dasherize and root.replace('_', '-') or root
        root_element = util.ET.Element(root)
        if isinstance(obj, list):
            root_element.set('type', 'array')
            for value in obj:
                root_element.append(
                    ShopifyResource.__to_xml_element(value,
                                                     util.singularize(root),
                                                     dasherize))
        elif isinstance(obj, dict):
            for key, value in obj.iteritems():
                root_element.append(
                    ShopifyResource.__to_xml_element(value, key, dasherize))
        else:
            util.serialize(obj, root_element)

        return root_element
Esempio n. 5
0
    def _update(self, attributes):
        """Update the object with the given attributes.

        Args:
            attributes: A dictionary of attributes.
        Returns:
            None
        """
        if not isinstance(attributes, dict):
            return
        for key, value in attributes.items():
            if isinstance(value, dict):
                klass = self._find_class_for(key)
                attr = klass(value)
            elif isinstance(value, list):
                klass = self._find_class_for(util.singularize(key))
                attr = [klass(child) for child in value]
            else:
                attr = value
            # Store the actual value in the attributes dictionary
            self.attributes[key] = attr
Esempio n. 6
0
    def _update(self, attributes):
        """Update the object with the given attributes.

        Args:
            attributes: A dictionary of attributes.
        Returns:
            None
        """
        if not isinstance(attributes, dict):
            return
        for key, value in attributes.items():
            if isinstance(value, dict):
                klass = self._find_class_for(key)
                attr = klass(value)
            elif isinstance(value, list):
                klass = self._find_class_for(util.singularize(key))
                attr = [klass(child) for child in value]
            else:
                attr = value
            # Store the actual value in the attributes dictionary
            self.attributes[key] = attr