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

AttributeError: 'MeasureSource' object has no attribute 'export' #225

Open
kkuehl opened this issue Dec 22, 2014 · 1 comment
Open

AttributeError: 'MeasureSource' object has no attribute 'export' #225

kkuehl opened this issue Dec 22, 2014 · 1 comment

Comments

@kkuehl
Copy link

kkuehl commented Dec 22, 2014

I am attempting to add Observable_Package_Source.

            source = MeasureSource()
            source.name = "Automatically Generated SCI NAME"
            source.description = "Automatic Description"
            contributors = Personnel()
            contrib = Contributor()
            contrib.name = "Support"
            contributors.append(contrib)
            source.contributors = contributors
            tools = ToolInformationList()
            tool = ToolInformation()
            tool.name = "Test"
            tool.version = "2.2.0"
            tools.append(tool)
            source.tools = tools
            observables.observable_package_source = source
            observables.set_Observable_Package_Source(source)
            # debug print
            print "This: %s" % observables.get_Observable_Package_Source().to_xml()
            outfile = open(outfilename, 'w')
            outfile.write('<?xml version="1.0" encoding="utf-8"?>\n')
            nsparser = NamespaceParser(observables.get_Observable())
            ns_string = nsparser.build_namespaces_schemalocations_str()
            observables.export(outfile, 0, namespacedef_=ns_string)

File "/usr/lib/python2.7/site-packages/cybox-2.0.1.2-py2.7.egg/cybox/bindings/cybox_core.py", line 912, in exportChildren
self.Observable_Package_Source.export(outfile, level, "cybox:", name_='Observable_Package_Source', pretty_print=pretty_print)
AttributeError: 'MeasureSource' object has no attribute 'export'

Am I adding the Observable_Package_Source incorrectly?

...

@gtback
Copy link
Contributor

gtback commented Feb 2, 2015

Hey, @kkuehl, sorry for the (woefully) late response.

It looks like you might be mixing "bindings" objects and "API" objects. Most bindings objects have class names ending in Type, and you manipulate them by calling get_X or set_X. API classes do not end in Type, and you manipulate them by directly getting or setting attributes. It looks like "observables" is a binding object (cybox.bindings.cybox_core.ObservablesType), while source is an API object cybox.common.MeasureSource.

You can get around this by changing:

observables.set_Observable_Package_Source(source)

to

observables.set_Observable_Package_Source(source.to_obj())

but you might be better off using the API version: cybox.core.Observables. API objects were designed to be easier to use than the bindings objects, which are defined in auto-generated code. to_obj converts an API object to a binding object, and you can do the reverse with Observables.from_obj(<binding_obj>)

For a larger discussion of API objects vs. Binding objects (in the context of STIX, but the concept is identical), see http://stix.readthedocs.org/en/latest/api_vs_bindings/index.html

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

2 participants