Exemplo n.º 1
0
 def replace_child(cls, template: interfaces.objects.Template,
                   old_child: interfaces.objects.Template,
                   new_child: interfaces.objects.Template) -> None:
     """Substitutes the old_child for the new_child."""
     if 'subtype' in template.vol:
         if template.vol['subtype'] == old_child:
             template.update_vol(subtype=new_child)
Exemplo n.º 2
0
 def _subresolve(
     self, object_template: interfaces.objects.Template
 ) -> interfaces.objects.Template:
     """Ensure an ObjectTemplate doesn't contain any ReferenceTemplates"""
     for child in object_template.children:
         if isinstance(child, objects.templates.ReferenceTemplate):
             new_child = self.get_type(child.vol.type_name)
         else:
             new_child = self._subresolve(child)
         object_template.replace_child(old_child=child, new_child=new_child)
     return object_template
Exemplo n.º 3
0
 def replace_child(cls, template: interfaces.objects.Template, old_child: interfaces.objects.Template,
                   new_child: interfaces.objects.Template) -> None:
     """Replace a child elements within the arguments handed to the
     template."""
     for member in template.vol.members.get('members', {}):
         relative_offset, member_template = template.vol.members[member]
         if member_template == old_child:
             # Members will give access to the mutable members list,
             # but in case that ever changes, do the update correctly
             tmp_list = template.vol.members
             tmp_list[member] = (relative_offset, new_child)
             # If there's trouble with mutability, consider making update_vol return a clone with the changes
             # (there will be a few other places that will be necessary) and/or making these part of the
             # permanent dictionaries rather than the non-clonable ones
             template.update_vol(members = tmp_list)