Skip to content

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

Open

Description

@kkuehl

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?

...

Activity

  1. gtback commented on Feb 2, 2015

    @gtback
    Contributor

    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

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