Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove return_obj from Entity parse/serialize/transform methods #18

Open
bworrell opened this issue Sep 29, 2015 · 0 comments
Open

Remove return_obj from Entity parse/serialize/transform methods #18

bworrell opened this issue Sep 29, 2015 · 0 comments
Assignees

Comments

@bworrell
Copy link
Contributor

This would need to carry through to python-stix|cybox|maec. We don't need it except in places where we have extension points.

We have code that passes around a return_obj to handle type inheritance in to/from dict/obj methods.

class Foo(Entity):
    _binding_class = some.binding.classname

    def to_obj(self, return_obj=None, ns_info=None):

        if return_obj is None:
            return_obj = self._binding_class()

        return_obj.value = self.value
        return return_obj

class DerivedFoo(Foo):
    _binding_class = some.other.binding.classname

    def to_obj(self, return_obj=None, ns_info=None):
        if return_obj is None:
            return_obj = self._binding_class()

        # Apply super attributes to the return_obj we created here
        super(DerivedFoo, self).to_obj(return_obj=return_obj, ns_info=ns_info)

        # Apply our own attribtes and return
        return_obj.foo = "bar"
        return return_obj

But it could be replaced with code that makes better use of super().

class Foo(Entity):
    _binding_class = some.binding.classname

    def __init__(self):
        self.value = "value"

    def to_obj(self, ns_info=None):
        obj = self._binding_class()
        obj.value = self.value
        return obj


class DerivedFoo(Foo):
    _binding_class = some.other.binding.classname

    def __init__(self):
        super(DerivedFoo, self).__init__()
        self.bar = "bar"

    def to_obj(self, ns_info=None):
        obj = super(DerivedFoo, self).to_obj(ns_info=ns_info)
        obj.foo = self.foo
        return obj

Most of this would be in python-stix|cybox|maec, but the changes would start in mixbox.

@bworrell bworrell self-assigned this Oct 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant