Skip to content
This repository was archived by the owner on Feb 28, 2026. It is now read-only.

Make RFC parsing not dependent of locale - #201

Merged
Laurent Mazuel (lmazuel) merged 5 commits into
masterfrom
rfc_parsing
May 14, 2020
Merged

Make RFC parsing not dependent of locale#201
Laurent Mazuel (lmazuel) merged 5 commits into
masterfrom
rfc_parsing

Conversation

@lmazuel

@lmazuelLaurent Mazuel (lmazuel) commented May 6, 2020

Copy link
Copy Markdown
Member

Fix#192

Code inspired from the one I wrote for azure-core

@lmazuel

Copy link
Copy Markdown
MemberAuthor

Without the PR, trying to deserialize in a french VM:

>>>frommsrest.serializationimportDeserializer>>>Deserializer.deserialize_rfc("Mon, 20 Nov 1995 19:12:08 -0500")
Traceback (mostrecentcalllast):
File"/home/lmazuel/rfctest/lib/python3.6/site-packages/msrest/serialization.py", line1818, indeserialize_rfcattr, "%a, %d %b %Y %H:%M:%S %Z")
File"/usr/lib/python3.6/_strptime.py", line565, in_strptime_datetimett, fraction=_strptime(data_string, format)
File"/usr/lib/python3.6/_strptime.py", line362, in_strptime
(data_string, format))
ValueError: timedata'Mon, 20 Nov 1995 19:12:08 -0500'doesnotmatchformat'%a, %d %b %Y %H:%M:%S %Z'Duringhandlingoftheaboveexception, anotherexceptionoccurred:
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"/home/lmazuel/rfctest/lib/python3.6/site-packages/msrest/serialization.py", line1823, indeserialize_rfcraise_with_traceback(DeserializationError, msg, err)
File"/home/lmazuel/rfctest/lib/python3.6/site-packages/msrest/exceptions.py", line51, inraise_with_tracebackraiseerror.with_traceback(exc_traceback)
File"/home/lmazuel/rfctest/lib/python3.6/site-packages/msrest/serialization.py", line1818, indeserialize_rfcattr, "%a, %d %b %Y %H:%M:%S %Z")
File"/usr/lib/python3.6/_strptime.py", line565, in_strptime_datetimett, fraction=_strptime(data_string, format)
File"/usr/lib/python3.6/_strptime.py", line362, in_strptime
(data_string, format))
msrest.exceptions.DeserializationError: Cannotdeserializetorfcdatetimeobject., ValueError: timedata'Mon, 20 Nov 1995 19:12:08 -0500'doesnotmatchformat'%a, %d %b %Y %H:%M:%S %Z'

With the PR:

>>>frommsrest.serializationimportDeserializer>>>Deserializer.deserialize_rfc("Mon, 20 Nov 1995 19:12:08 -0500")
datetime.datetime(1995, 11, 20, 19, 12, 8, tzinfo=<FixedOffset-5.0>)

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parsing RFC date assumes current local is English

1 participant

@lmazuel