Skip to content

Parsing of Date/Time/Datetime in bindings #66

Open

Description

@CyberDaedalus00

It appears the generated parsing code is incorrect with regards to the parsing of xs:date, xs:time, and xs:datetime in the bindings API of python-maec 4.1.0.9. The attributes are actually python strings instead of python datetime.

As an example of the source of this, the parsing of the 'start_datetime' attribute on the AnalysisType complexType is handled as follows:

    value = find_attr_value_('start_datetime', node)
    if value is not None and 'start_datetime' not in already_processed:
        already_processed.add('start_datetime')
        try:
            self.start_datetime = value
        except ValueError, exp:
            raise ValueError('Bad date-time attribute (start_datetime): %s' % exp)

but should be handled as follows, as is done in the handling of equivalent types in the python-stix Bindings API:

    value = find_attr_value_('timestamp', node)
    if value is not None and 'timestamp' not in already_processed:
        already_processed.add('timestamp')
        try:
            self.timestamp = self.gds_parse_datetime(value, node, 'timestamp')
        except ValueError, exp:
            raise ValueError('Bad date-time attribute (timestamp): %s' % exp)

The issue is the 'value' returned from find-attr_value is a python string and needs to be converted to a datetime object by calling self.gds_parse_datetime(). Given that self.gds_validate_datetime() wasn't called nor was self.gds_parse_datetime() was call and yet there is exception handling, it appears as if the parsing code was modified.

Activity

  1. ikiril01 commented on Feb 25, 2015

    @ikiril01
    Member

    @CyberDaedalus00 thanks for reporting this! You're right in that we modified the parsing code to remove the gds_parse_datetime usage; its been a while, but I believe it was because it caused issues when dumping parsed MAEC XML documents as JSON:

    0d844b6

    I'm going to do some further testing to see if this is still an issue.

  2. ikiril01 commented on Feb 25, 2015

    @ikiril01
    Member

    This is related to the CybOX issue I linked to above. Once we have consensus on the solution, we may able to revert the bindings to function as before.

  3. gtback commented on Feb 26, 2015

    @gtback
    Contributor

    @ikiril01: I believe that the commit you reference has the effect of treating dates parsed from XML as strings rather than date-times. I don't think that's we want to work with them in the Python APIs; better to use the Python datetime class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions