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 __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
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
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