-
Notifications
You must be signed in to change notification settings - Fork 47
MsgpackSerializer.loadsCall: honor ext_hook (symmetric with loads) #117
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f5045ce
Update serializers.py. Added ext_hook to loadsCall in MsgpackSerializ…
daqiii 8526e4d
Create test_msgpack_ext_hook_loadsCall.py
daqiii 089d7af
Move the loadsCall ext_hook regression tests into test_serialize.py
daqiii 3d6154f
Remove the standalone test file (moved into test_serialize.py)
daqiii 4ebec4d
Address round 2 review: remove redundant msgpack import, fix indent
daqiii 03bf0f5
updates to incorrect indents
daqiii 36edd6d
Add files via upload
daqiii ef24828
Address round 2 review: remove redundant msgpack import, fix indent, …
daqiii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,7 +110,50 @@ class TestJsonSerializer(TestSerpentSerializer): | |
| if "msgpack" in Pyro5.serializers.serializers: | ||
| class TestMsgpackSerializer(TestSerpentSerializer): | ||
| serializer = Pyro5.serializers.serializers["msgpack"] | ||
|
|
||
| import msgpack | ||
|
|
||
| class Thing: | ||
| def __init__(self, value): | ||
| self.value = value | ||
| self.value = value | ||
|
|
||
| class CustomMsgpackSerializer(Pyro5.serializers.MsgpackSerializer): | ||
| CUSTOM_EXT_CODE = 0x40 | ||
|
|
||
| def default(self, obj): | ||
| if isinstance(obj, Thing): | ||
| return msgpack.ExtType(self.CUSTOM_EXT_CODE, str(obj.value).encode("ascii")) | ||
| return super().default(obj) | ||
|
|
||
| def ext_hook(self, code, data): | ||
| if code == self.CUSTOM_EXT_CODE: | ||
| return Thing(int(data)) | ||
| return super().ext_hook(code, data) | ||
|
|
||
| class TestMsgpackExtHookLoadsCall: | ||
| """Regression: MsgpackSerializer.loadsCall must honor ext_hook so | ||
| custom-ExtType-encoded call arguments round-trip when a subclass | ||
| overrides ext_hook for custom codes. Without the fix, loadsCall | ||
| returns raw msgpack.ExtType objects instead of decoded values.""" | ||
|
|
||
| serializer = CustomMsgpackSerializer() | ||
|
|
||
| def testLoadsCallHonorsExtHook(self): | ||
| data = self.serializer.dumpsCall("obj-id", "method-name", (Thing(42),), {}) | ||
| obj, method, vargs, kwargs = self.serializer.loadsCall(data) | ||
| assert obj == "obj-id" | ||
| assert method == "method-name" | ||
| assert isinstance(vargs[0], Thing) | ||
| assert vargs[0].value == 42 | ||
| assert kwargs == {} | ||
|
|
||
| def testLoadsAlreadyHonorsExtHook(self): | ||
| """Sanity check on the sibling that always worked, so future | ||
| regressions on either method surface symmetrically.""" | ||
| data = self.serializer.dumps(Thing(7)) | ||
| back = self.serializer.loads(data) | ||
| assert isinstance(back, Thing) | ||
| assert back.value == 7 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please fix this indentation error, it breaks the test |
||
|
|
||
| class TestSerializer2_serpent: | ||
| SERIALIZER = "serpent" | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is redundant because the import is already done at line 21