From 1ad64dfc0c134bdf90f714e068513f1b45712d91 Mon Sep 17 00:00:00 2001 From: Chris Lenk Date: Wed, 9 Jan 2019 10:46:48 -0500 Subject: [PATCH] Move CallableValues to prevent duplicate code --- stix2/properties.py | 15 ++++++++++++++- stix2/v20/observables.py | 15 +-------------- stix2/v21/observables.py | 15 +-------------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/stix2/properties.py b/stix2/properties.py index 24549aa..5e1b07f 100644 --- a/stix2/properties.py +++ b/stix2/properties.py @@ -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): diff --git a/stix2/v20/observables.py b/stix2/v20/observables.py index a462661..55872cd 100644 --- a/stix2/v20/observables.py +++ b/stix2/v20/observables.py @@ -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, @@ -706,19 +706,6 @@ class WindowsRegistryValueType(_STIXBase): ]) -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 WindowsRegistryKey(_Observable): """For more detailed information on this object's properties, see `the STIX 2.0 specification `__. diff --git a/stix2/v21/observables.py b/stix2/v21/observables.py index 92fe36a..f383899 100644 --- a/stix2/v21/observables.py +++ b/stix2/v21/observables.py @@ -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, @@ -758,19 +758,6 @@ class WindowsRegistryValueType(_STIXBase): ]) -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 WindowsRegistryKey(_Observable): # TODO: Add link """For more detailed information on this object's properties, see