Skip to content

Parsing of Date/Time/Datetime in bindings #66

Open
@CyberDaedalus00

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.

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