Skip to content

Commit

Permalink
Merge pull request #272 from STIXProject/issue271
Browse files Browse the repository at this point in the history
Made STIXPackage's version property read-only.
  • Loading branch information
Bryan Worrell committed Jul 7, 2015
2 parents 2e601d6 + daf800e commit 80bba07
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
15 changes: 3 additions & 12 deletions stix/core/stix_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self, id_=None, idref=None, timestamp=None, stix_header=None,

self.id_ = id_ or idgen.create_id("Package")
self.idref = idref
self.version = STIXPackage._version
self._version = STIXPackage._version
self.stix_header = stix_header
self.campaigns = campaigns
self.courses_of_action = courses_of_action
Expand Down Expand Up @@ -149,15 +149,6 @@ def version(self):
"""
return self._version

@version.setter
def version(self, value):
if not value:
self._version = None
else:
utils.check_version(self._ALL_VERSIONS, value)
self._version = value


@property
def stix_header(self):
"""The :class:`.STIXHeader` section of the STIX Package.
Expand Down Expand Up @@ -462,7 +453,7 @@ def from_obj(cls, obj, return_obj=None):

# Don't overwrite this unless passed in.
if obj.version:
return_obj.version = obj.version
return_obj._version = obj.version

return return_obj

Expand All @@ -475,7 +466,7 @@ def from_dict(cls, dict_repr, return_obj=None):
return_obj.id_ = get('id')
return_obj.idref = get('idref')
return_obj.timestamp = get('timestamp')
return_obj.version = get('version', cls._version)
return_obj._version = get('version', cls._version)
return_obj.stix_header = STIXHeader.from_dict(get('stix_header'))
return_obj.campaigns = Campaigns.from_dict(get('campaigns'))
return_obj.courses_of_action = CoursesOfAction.from_dict(get('courses_of_action'))
Expand Down
16 changes: 0 additions & 16 deletions stix/test/core/stix_package_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,6 @@ def test_related_package_idref_deprecation(self):
package = core.STIXPackage()
package.add_related_package(core.STIXPackage(idref='foo'))

def test_version(self):
"""Tests that setting the version property of a STIXPackage does
not affect the serialized versions.
"""
p = core.STIXPackage()
p.version = "1.0" # old version

s = p.to_xml()
sio = StringIO.StringIO(s)

# Reparse the package
p = core.STIXPackage.from_xml(sio)

self.assertEqual(p.version, core.STIXPackage._version)


if __name__ == "__main__":
unittest.main()

0 comments on commit 80bba07

Please sign in to comment.