Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing of Date/Time/Datetime in bindings #66

Open
CyberDaedalus00 opened this issue Feb 21, 2015 · 3 comments
Open

Parsing of Date/Time/Datetime in bindings #66

CyberDaedalus00 opened this issue Feb 21, 2015 · 3 comments

Comments

@CyberDaedalus00
Copy link

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.

@ikiril01
Copy link
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.

@ikiril01
Copy link
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.

@gtback
Copy link
Contributor

gtback commented Feb 26, 2015

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants