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

Pass setval calls through SubstructureField to the contained Structure #31

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions suitcase/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import six
from suitcase.exceptions import SuitcaseChecksumException, SuitcaseProgrammingError, \
SuitcaseParseError, SuitcaseException, SuitcasePackStructException
import suitcase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stylistically, I think I would prefer:

from suitcase.structure import Structure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it would look nicer, but it introduces a circular dependency between fields.py and structure.py.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be resolved by adding from suitcase.structure import Structure to the setval method.

from six import BytesIO, StringIO


Expand Down Expand Up @@ -831,6 +832,12 @@ def unpack(self, data, **kwargs):
self._value = self.substructure()
return self._value.unpack(data, **kwargs)

def setval(self, value):
if value is None or isinstance(value, suitcase.structure.Structure):
BaseField.setval(self, value)
else:
self._value.setval(value)


class FieldArray(BaseField):
"""Field which contains a list of some other field.
Expand Down