forked from Thriftpy/thriftpy
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve binary and compact binary handling
I believe this improves [1] which addresses a bytes/str inconsistency issue reported some time ago[2]. The goal of this patch is to have an option to always deseriaize binary fields as bytes and string fields as str (on Python 2, respectively: str and unicode). It achieves it by adding a third option to previously purely boolean decode_response parameter (I admit I'm not a fan of mixing types like this but I'm doing this strictly for backwards compatibility and I'd argue the "auto" behavior should become the default in the future and decode_response should be removed altogether). Internally the goal of this change is achieved by keeping the ttype of binary fields as STRING but putting a non-None value in their "container spec" which introduces a bit of inconsistency (string fields are TType.STRING but binary fields are (TType.STRING, BINARY)) but I believe we can live with it. I've renamed and reorganized parts of the code in order for the names to be reasonably truthful and to avoid too much code redundancy connected to the fact that I've added more tests. Ideally some of the test code would be shared so reduce the redundancy even further but I feel that it's out of scope here. Similarly there's some almost identical code in Python and Cython protocol implementations but I lack expertise regarding possible ways to mitigate that. Casting of values in the parser is fixed as a bonus, the following code never worked because TType.STRING and TType.BINARY had the same value: if t == TType.STRING: return _cast_string if t == TType.BINARY: return _cast_binary [1] Thriftpy@00c6553 [2] Thriftpy#190
- Loading branch information
Showing
11 changed files
with
209 additions
and
107 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
Oops, something went wrong.