Remove workaround for "values" being both a Mapping method name

and sometimes a STIX property name.  It didn't work (caused
crashes under some circumstances).  Now, attributes whose names
conflict with Mapping methods will have the Mapping
interpretation.  Same-named STIX object properties will not be
accessible as attributes.
master
Michael Chisholm 2020-01-28 18:13:36 -05:00
parent 4b8fda0c2f
commit 176cb980a2
5 changed files with 9 additions and 32 deletions

View File

@ -11,7 +11,7 @@ from six import string_types, text_type
import stix2
from .base import _Observable, _STIXBase
from .base import _STIXBase
from .core import STIX2_OBJ_MAPS, parse, parse_observable
from .exceptions import (
CustomContentError, DictionaryKeyError, MissingPropertiesError,
@ -219,19 +219,6 @@ class ListProperty(Property):
return result
class CallableValues(list):
"""Wrapper to allow `values()` method on WindowsRegistryKey objects.
Needed because `values` is also a property.
"""
def __init__(self, parent_instance, *args, **kwargs):
self.parent_instance = parent_instance
super(CallableValues, self).__init__(*args, **kwargs)
def __call__(self):
return _Observable.values(self.parent_instance)
class StringProperty(Property):
def __init__(self, **kwargs):

View File

@ -1301,9 +1301,9 @@ def test_windows_registry_key_example():
values=[v],
)
assert w.key == "hkey_local_machine\\system\\bar\\foo"
assert w.values[0].name == "Foo"
assert w.values[0].data == "qwerty"
assert w.values[0].data_type == "REG_SZ"
assert w["values"][0].name == "Foo"
assert w["values"][0].data == "qwerty"
assert w["values"][0].data_type == "REG_SZ"
# ensure no errors in serialization because of 'values'
assert "Foo" in str(w)

View File

@ -1382,9 +1382,9 @@ def test_windows_registry_key_example():
values=[v],
)
assert w.key == "hkey_local_machine\\system\\bar\\foo"
assert w.values[0].name == "Foo"
assert w.values[0].data == "qwerty"
assert w.values[0].data_type == "REG_SZ"
assert w["values"][0].name == "Foo"
assert w["values"][0].data == "qwerty"
assert w["values"][0].data_type == "REG_SZ"
# ensure no errors in serialization because of 'values'
assert "Foo" in str(w)

View File

@ -12,7 +12,7 @@ from ..base import _Extension, _Observable, _STIXBase
from ..custom import _custom_extension_builder, _custom_observable_builder
from ..exceptions import AtLeastOnePropertyError, DependentPropertiesError
from ..properties import (
BinaryProperty, BooleanProperty, CallableValues, DictionaryProperty,
BinaryProperty, BooleanProperty, DictionaryProperty,
EmbeddedObjectProperty, EnumProperty, ExtensionsProperty, FloatProperty,
HashesProperty, HexProperty, IntegerProperty, ListProperty,
ObjectReferenceProperty, StringProperty, TimestampProperty, TypeProperty,
@ -723,11 +723,6 @@ class WindowsRegistryKey(_Observable):
('extensions', ExtensionsProperty(spec_version="2.0", enclosing_type=_type)),
])
@property
def values(self):
# Needed because 'values' is a property on collections.Mapping objects
return CallableValues(self, self._inner['values'])
class X509V3ExtenstionsType(_STIXBase):
"""For more detailed information on this object's properties, see

View File

@ -15,7 +15,7 @@ from ..exceptions import (
AtLeastOnePropertyError, DependentPropertiesError, STIXDeprecationWarning,
)
from ..properties import (
BinaryProperty, BooleanProperty, CallableValues, DictionaryProperty,
BinaryProperty, BooleanProperty, DictionaryProperty,
EmbeddedObjectProperty, EnumProperty, ExtensionsProperty, FloatProperty,
HashesProperty, HexProperty, IDProperty, IntegerProperty, ListProperty,
ObjectReferenceProperty, ReferenceProperty, StringProperty,
@ -935,11 +935,6 @@ class WindowsRegistryKey(_Observable):
])
_id_contributing_properties = ["key", "values"]
@property
def values(self):
# Needed because 'values' is a property on collections.Mapping objects
return CallableValues(self, self._inner['values'])
class X509V3ExtenstionsType(_STIXBase):
# TODO: Add link