adapter.{json,xml}: make (de-)serialization interfaces coherent#251
Merged
s-heppner merged 6 commits intoeclipse-basyx:mainfrom Mar 14, 2024
Merged
Conversation
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
... by using `StringIO` instead of `BytesIO`.
Member
|
LGTM, that might make the integration of aas-core easier as well. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
lxml supports paths already, no modification is necessary there.
However, the
lxml.etree.ElementTree.write()function requiresBinaryIO, i.e. files opened with the 'b' mode. While it would bepossible to access the underlying binary buffer of files opened in text
mode via
open(), this isn't possible forio.StringIO(), as itdoesn't have the
bufferproperty. Thus, even if we could support filesopened via
open()in text mode, we couldn't annotate the XMLserialization functions with
TextIO, asio.StringIO()remainsunsupported. Because of that, I decided to not support
TextIOfor theXML serialization.
The builtin JSON module only supports file handles, with the
json.dump()method only supportingTextIOandjson.load()supporting
TextIOandBinaryIO. Thus, the JSON adapter is modifiedto
open()given paths, while the JSON serialization is additionallymodified to wrap
BinaryIOwithio.TextIOWrapper.Fix #42