Merge pull request #237 from oasis-open/236-WindowsRegistryKey

Fix error when printing WindowsRegistryKey
master
Chris Lenk 2019-01-09 11:12:46 -05:00 committed by GitHub
commit 8c3ecd1c48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 5 deletions

View File

@ -11,7 +11,7 @@ import uuid
from six import string_types, text_type
from stix2patterns.validator import run_validator
from .base import _STIXBase
from .base import _Observable, _STIXBase
from .core import STIX2_OBJ_MAPS, parse, parse_observable
from .exceptions import CustomContentError, DictionaryKeyError
from .utils import _get_dict, get_class_hierarchy_names, parse_into_datetime
@ -167,6 +167,19 @@ 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

@ -1291,6 +1291,8 @@ def test_windows_registry_key_example():
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)
def test_x509_certificate_example():

View File

@ -1264,6 +1264,8 @@ def test_windows_registry_key_example():
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)
def test_x509_certificate_example():

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, DictionaryProperty,
BinaryProperty, BooleanProperty, CallableValues, DictionaryProperty,
EmbeddedObjectProperty, EnumProperty, ExtensionsProperty, FloatProperty,
HashesProperty, HexProperty, IntegerProperty, ListProperty,
ObjectReferenceProperty, StringProperty, TimestampProperty, TypeProperty,
@ -726,7 +726,7 @@ class WindowsRegistryKey(_Observable):
@property
def values(self):
# Needed because 'values' is a property on collections.Mapping objects
return self._inner['values']
return CallableValues(self, self._inner['values'])
class X509V3ExtenstionsType(_STIXBase):

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, DictionaryProperty,
BinaryProperty, BooleanProperty, CallableValues, DictionaryProperty,
EmbeddedObjectProperty, EnumProperty, ExtensionsProperty, FloatProperty,
HashesProperty, HexProperty, IntegerProperty, ListProperty,
ObjectReferenceProperty, StringProperty, TimestampProperty, TypeProperty,
@ -779,7 +779,7 @@ class WindowsRegistryKey(_Observable):
@property
def values(self):
# Needed because 'values' is a property on collections.Mapping objects
return self._inner['values']
return CallableValues(self, self._inner['values'])
class X509V3ExtenstionsType(_STIXBase):