Skip to content

Remove iso8601 dependency - #1176

Merged
lukpueh merged 2 commits into
theupdateframework:developfrom
jku:remove-iso8601
Oct 14, 2020
Merged

Remove iso8601 dependency#1176
lukpueh merged 2 commits into
theupdateframework:developfrom
jku:remove-iso8601

Conversation

@jku

@jkujku commented Oct 13, 2020

Copy link
Copy Markdown
Member

Our 'expires' strings are constrained by the ISO8601_DATETIME_SCHEMA
(meaning regex '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z'). This can be
parsed with just a datetime.strptime(): iso8601 module is not needed.

  • Add formats.expiry_string_to_datetime() helper function
  • Modify the 3 locations that used iso8601 and the api/metadata.py usage
    of datetime.strptime()
  • Remove related unnecessary logger setup
  • Add the missing exception documentation to relevant functions (in many
    cases the exception is rather unlikely as the schema has been verified
    many times before this though...)

Fixes#1065


The reason for doing this is again vendoring into pip: I'd like to not have to vendor iso8601 as well.

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

Jussi Kukkonen added 2 commits October 13, 2020 12:11
sig does not use iso8601: no need to silence its logging
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
Our 'expires' strings are constrained by the ISO8601_DATETIME_SCHEMA
which matches regex '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z'. This can be
parsed with just a datetime.strptime(): iso8601 module is not needed.
* Add formats.expiry_string_to_datetime() helper function
* Modify the 3 locations that used iso8601 and the api/metadata.py usage
of datetime.strptime()
* Remove related unnecessary logger setup
* Add the missing exception documentation to relevant functions (in many
cases the exception is rather unlikely as the schema has been verified
many times before this though...)
Fixestheupdateframework#1065
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
Comment threadtuf/api/metadata.py
# is implemented in 'to_dict'.
signed_dict['expires'] = datetime.strptime(
signed_dict['expires'],
"%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=None)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that I'm not doing the replace() in my version: I could not think of a case where it would be useful.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes perfect sense. I guess I thought that strptime might adopt the system timezone. Thanks for removing unnecessary code!

@lukpuehlukpueh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impeccable work! Thanks, @jku!

Comment threadtuf/api/metadata.py
# is implemented in 'to_dict'.
signed_dict['expires'] = datetime.strptime(
signed_dict['expires'],
"%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=None)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes perfect sense. I guess I thought that strptime might adopt the system timezone. Thanks for removing unnecessary code!

@lukpueh
lukpueh merged commit c392361 into theupdateframework:developOct 14, 2020
@jku
jku deleted the remove-iso8601 branch December 30, 2024 09:07
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove iso8601 dependency

2 participants

@jku@lukpueh