Fix fairly deep flaw where resolved templates could be modified by casting or creating an object.

This commit is contained in:
Mike Auty
2016-12-18 19:21:27 +00:00
parent 1754f3bc85
commit 09ee0e6258
4 changed files with 11 additions and 3 deletions
+8 -1
View File
@@ -89,6 +89,7 @@ class ObjectInterface(validity.ValidityRoutines, metaclass = ABCMeta):
"""Returns a new object at the offset and from the layer that the current object inhabits"""
# TODO: Carefully consider the implications of casting and how it should work
object_template = self._context.symbol_space.get_type(new_type_name)
object_template = object_template.clone()
object_template.update_vol(**additional)
object_info = ObjectInformation(layer_name = self.vol.layer_name,
offset = self.vol.offset,
@@ -132,7 +133,8 @@ class Template(validity.ValidityRoutines):
"""Stores the keyword arguments for later use"""
# Allow the updating of template arguments whilst still in template form
super().__init__()
self._vol = collections.ChainMap(arguments, {'type_name': type_name})
self._arguments = arguments
self._vol = collections.ChainMap({}, self._arguments, {'type_name': type_name})
@property
def vol(self):
@@ -163,6 +165,11 @@ class Template(validity.ValidityRoutines):
def replace_child(self, old_child, new_child):
"""A function for replacing one child with another"""
def clone(self):
"""Returns a copy of the original Template as constructed (without update_vol having been called)"""
clone = self.__class__(**self._vol.parents.new_child())
return clone
def update_vol(self, **new_arguments):
"""Updates the keyword arguments"""
self._vol.update(new_arguments)