Improve handling of str values for Duration#1165
Merged
mvantellingen merged 1 commit intomvantellingen:masterfrom Aug 15, 2021
backbord:master
Merged
Improve handling of str values for Duration#1165mvantellingen merged 1 commit intomvantellingen:masterfrom backbord:master
mvantellingen merged 1 commit intomvantellingen:masterfrom
backbord:master
Conversation
Passing a str to `Duration.xmlvalue(value)` will result in a properly formatted iso duration.
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.
Hi @mvantellingen,
I really like your project but recently stumbled into #876 when I wanted to specify a duration as
"PT15M"and got"P%P"in the generated SOAP message.Here's my attempt to improve the behaviour. Two simple and small test cases are included.
I hope you might consider merging the PR or giving advice if there's another desired way to do things.
In this PR, two things happen:
datetime.timedeltavalue is allowed.strvalue will result in thestrbeing parsed byisodate.parse_duration()to ensure the provided value is indeed an iso duration.The result of the parsing is then handed over to
isodate.duration_isoformat()to produce the desired duration string.This round-trip mimics one of your test cases and results in
builtins.Duration().xmlvalue("P0Y1347M0D") == "P1347M"where the superfluous zeros are eliminated. This should also ensure that the string is a valid duration in isoformat and raise aValueErrorif it cannot be parsed as such.Thanks and best regards,
Tim