-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adapter.{json,xml}: make (de-)serialization interfaces coherent
lxml supports paths already, no modification is necessary there. However, the `lxml.etree.ElementTree.write()` function requires `BinaryIO`, i.e. files opened with the 'b' mode. While it would be possible to access the underlying binary buffer of files opened in text mode via `open()`, this isn't possible for `io.StringIO()`, as it doesn't have the `buffer` property. Thus, even if we could support files opened via `open()` in text mode, we couldn't annotate the XML serialization functions with `TextIO`, as `io.StringIO()` remains unsupported. Because of that, I decided to not support `TextIO` for the XML serialization. The builtin JSON module only supports file handles, with the `json.dump()` method only supporting `TextIO` and `json.load()` supporting `TextIO` and `BinaryIO`. Thus, the JSON adapter is modified to `open()` given paths, while the JSON serialization is additionally modified to wrap `BinaryIO` with `io.TextIOWrapper`. Fix #42
- Loading branch information
Showing
5 changed files
with
76 additions
and
20 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