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

Remove workaround for "values" being both a Mapping method name and STIX property name #331

Merged
merged 3 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions docs/guide/creating.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,19 @@
"indicator.name"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-warning\">\n",
"\n",
"**Warning**\n",
"\n",
"Note that there are several attributes on these objects used for method names. Accessing those will return a bound method, not the attribute value.\n",
"\n",
"</div>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -1110,21 +1123,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 2",
"language": "python",
"name": "python3"
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"pygments_lexer": "ipython2",
"version": "2.7.15"
}
},
"nbformat": 4,
Expand Down
15 changes: 1 addition & 14 deletions stix2/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

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,
Expand Down Expand Up @@ -219,19 +219,6 @@ def clean(self, value):
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):
Expand Down
6 changes: 3 additions & 3 deletions stix2/test/v20/test_observed_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions stix2/test/v21/test_observed_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 1 addition & 6 deletions stix2/v20/observables.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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,
Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions stix2/v21/observables.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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,
Expand Down Expand Up @@ -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
Expand Down