Support passing through functions from specific to generic template.

This commit is contained in:
Mike Auty
2019-08-10 00:25:21 +01:00
parent b2da35c05a
commit 4cde0da8a9
3 changed files with 6 additions and 5 deletions
@@ -174,6 +174,7 @@ class ObjectInterface(metaclass = ABCMeta):
Each method also takes a template since the templates may contain the necessary data about the
yet-to-be-constructed object. It allows objects to control how their templates respond without needing to write
new templates for each and every potental object type."""
_methods = []
@classmethod
@abc.abstractmethod
+1
View File
@@ -451,6 +451,7 @@ class Enumeration(interfaces.objects.ObjectInterface, int):
raise NotImplementedError("Writing to Enumerations is not yet implemented")
class VolTemplateProxy(interfaces.objects.ObjectInterface.VolTemplateProxy):
_methods = ['lookup']
@classmethod
def lookup(cls, template: interfaces.objects.Template, value: int) -> str:
+4 -5
View File
@@ -17,6 +17,7 @@
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
# specific language governing rights and limitations under the License.
#
import functools
import logging
from typing import Any, ClassVar, Dict, List, Type
@@ -40,11 +41,9 @@ class ObjectTemplate(interfaces.objects.Template):
super().__init__(type_name = type_name, **arguments)
self._arguments['object_class'] = object_class
# proxy_cls = self.vol.object_class.VolTemplateProxy
# for method_name in dir(proxy_cls):
# if (method_name not in dir(interfaces.objects.ObjectInterface.VolTemplateProxy)
# and callable(getattr(proxy_cls, method_name)) and not method_name.startswith('_')):
# setattr(self, method_name, functools.partial(getattr(proxy_cls, method_name), self))
proxy_cls = self.vol.object_class.VolTemplateProxy
for method_name in proxy_cls._methods:
setattr(self, method_name, functools.partial(getattr(proxy_cls, method_name), self))
@property
def size(self) -> int: