From 67935d08fee87a8c2b11bcb20eb633888b44266f Mon Sep 17 00:00:00 2001 From: clenk Date: Tue, 9 May 2017 18:03:46 -0400 Subject: [PATCH] Fix isort settings, rename Observable to clarify it's an internal class --- .isort.cfg | 7 +++++++ stix2/base.py | 6 +++--- stix2/observables.py | 38 +++++++++++++++++++------------------- stix2/properties.py | 10 ++++++---- stix2/sdo.py | 4 ++-- stix2/utils.py | 2 +- tox.ini | 2 +- 7 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 .isort.cfg diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000..56f50d1 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,7 @@ +[settings] +check=1 +diff=1 +known_third_party=dateutil,pytest,pytz,six +known_first_party=stix2 +not_skip=__init__.py +force_sort_within_sections=1 diff --git a/stix2/base.py b/stix2/base.py index c3a8944..645ab67 100644 --- a/stix2/base.py +++ b/stix2/base.py @@ -143,7 +143,7 @@ class _STIXBase(collections.Mapping): return self.new_version(revoked=True) -class Observable(_STIXBase): +class _Observable(_STIXBase): def __init__(self, **kwargs): # the constructor might be called independently of an observed data object @@ -151,10 +151,10 @@ class Observable(_STIXBase): self._STIXBase__valid_refs = kwargs.pop('_valid_refs') else: self._STIXBase__valid_refs = [] - super(Observable, self).__init__(**kwargs) + super(_Observable, self).__init__(**kwargs) def _check_property(self, prop_name, prop, kwargs): - super(Observable, self)._check_property(prop_name, prop, kwargs) + super(_Observable, self)._check_property(prop_name, prop, kwargs) if prop_name.endswith('_ref') and prop_name in kwargs: ref = kwargs[prop_name] if ref not in self._STIXBase__valid_refs: diff --git a/stix2/observables.py b/stix2/observables.py index 3a5a49f..f63b7cf 100644 --- a/stix2/observables.py +++ b/stix2/observables.py @@ -5,7 +5,7 @@ embedded in Email Message objects, inherit from _STIXBase instead of Observable and do not have a '_type' attribute. """ -from .base import Observable, _STIXBase +from .base import _Observable, _STIXBase from .properties import (BinaryProperty, BooleanProperty, DictionaryProperty, EmbeddedObjectProperty, HashesProperty, HexProperty, IntegerProperty, ListProperty, @@ -13,7 +13,7 @@ from .properties import (BinaryProperty, BooleanProperty, DictionaryProperty, TimestampProperty, TypeProperty) -class Artifact(Observable): +class Artifact(_Observable): _type = 'artifact' _properties = { 'type': TypeProperty(_type), @@ -24,7 +24,7 @@ class Artifact(Observable): } -class AutonomousSystem(Observable): +class AutonomousSystem(_Observable): _type = 'autonomous-system' _properties = { 'type': TypeProperty(_type), @@ -34,7 +34,7 @@ class AutonomousSystem(Observable): } -class Directory(Observable): +class Directory(_Observable): _type = 'directory' _properties = { 'type': TypeProperty(_type), @@ -48,7 +48,7 @@ class Directory(Observable): } -class DomainName(Observable): +class DomainName(_Observable): _type = 'domain-name' _properties = { 'type': TypeProperty(_type), @@ -57,7 +57,7 @@ class DomainName(Observable): } -class EmailAddress(Observable): +class EmailAddress(_Observable): _type = 'email-address' _properties = { 'type': TypeProperty(_type), @@ -76,7 +76,7 @@ class EmailMIMEComponent(_STIXBase): } -class EmailMessage(Observable): +class EmailMessage(_Observable): _type = 'email-message' _properties = { 'type': TypeProperty(_type), @@ -97,7 +97,7 @@ class EmailMessage(Observable): } -class File(Observable): +class File(_Observable): _type = 'file' _properties = { 'type': TypeProperty(_type), @@ -121,7 +121,7 @@ class File(Observable): } -class IPv4Address(Observable): +class IPv4Address(_Observable): _type = 'ipv4-addr' _properties = { 'type': TypeProperty(_type), @@ -131,7 +131,7 @@ class IPv4Address(Observable): } -class IPv6Address(Observable): +class IPv6Address(_Observable): _type = 'ipv6-addr' _properties = { 'type': TypeProperty(_type), @@ -141,7 +141,7 @@ class IPv6Address(Observable): } -class MACAddress(Observable): +class MACAddress(_Observable): _type = 'mac-addr' _properties = { 'type': TypeProperty(_type), @@ -149,7 +149,7 @@ class MACAddress(Observable): } -class Mutex(Observable): +class Mutex(_Observable): _type = 'mutex' _properties = { 'type': TypeProperty(_type), @@ -157,7 +157,7 @@ class Mutex(Observable): } -class NetworkTraffic(Observable): +class NetworkTraffic(_Observable): _type = 'network-traffic' _properties = { 'type': TypeProperty(_type), @@ -182,7 +182,7 @@ class NetworkTraffic(Observable): } -class Process(Observable): +class Process(_Observable): _type = 'process' _properties = { 'type': TypeProperty(_type), @@ -204,7 +204,7 @@ class Process(Observable): } -class Software(Observable): +class Software(_Observable): _type = 'software' _properties = { 'type': TypeProperty(_type), @@ -216,7 +216,7 @@ class Software(Observable): } -class URL(Observable): +class URL(_Observable): _type = 'url' _properties = { 'type': TypeProperty(_type), @@ -224,7 +224,7 @@ class URL(Observable): } -class UserAccount(Observable): +class UserAccount(_Observable): _type = 'user-account' _properties = { 'type': TypeProperty(_type), @@ -254,7 +254,7 @@ class WindowsRegistryValueType(_STIXBase): } -class WindowsRegistryKey(Observable): +class WindowsRegistryKey(_Observable): _type = 'windows-registry-key' _properties = { 'type': TypeProperty(_type), @@ -267,7 +267,7 @@ class WindowsRegistryKey(Observable): } -class X509Certificate(Observable): +class X509Certificate(_Observable): _type = 'x509-certificate' _properties = { 'type': TypeProperty(_type), diff --git a/stix2/properties.py b/stix2/properties.py index 5b0a677..47ec345 100644 --- a/stix2/properties.py +++ b/stix2/properties.py @@ -5,10 +5,12 @@ import datetime as dt import inspect import re import uuid -from six import text_type -import pytz + from dateutil import parser -from .base import Observable, _STIXBase +import pytz +from six import text_type + +from .base import _Observable, _STIXBase from .exceptions import DictionaryKeyError @@ -226,7 +228,7 @@ class ObservableProperty(Property): from .__init__ import parse_observable # avoid circular import for key, obj in dictified.items(): parsed_obj = parse_observable(obj, dictified.keys()) - if not issubclass(type(parsed_obj), Observable): + if not issubclass(type(parsed_obj), _Observable): raise ValueError("Objects in an observable property must be " "Cyber Observable Objects") dictified[key] = parsed_obj diff --git a/stix2/sdo.py b/stix2/sdo.py index ca1e5b4..57968f0 100644 --- a/stix2/sdo.py +++ b/stix2/sdo.py @@ -4,8 +4,8 @@ from .base import _STIXBase from .common import COMMON_PROPERTIES from .other import KillChainPhase from .properties import (IDProperty, IntegerProperty, ListProperty, - ObservableProperty, ReferenceProperty, - StringProperty, TimestampProperty, TypeProperty) + ObservableProperty, ReferenceProperty, StringProperty, + TimestampProperty, TypeProperty) from .utils import NOW diff --git a/stix2/utils.py b/stix2/utils.py index 6f3425f..a2493e2 100644 --- a/stix2/utils.py +++ b/stix2/utils.py @@ -3,8 +3,8 @@ import datetime as dt import json -import pytz from dateutil import parser +import pytz # Sentinel value for fields that should be set to the current time. # We can't use the standard 'default' approach, since if there are multiple diff --git a/tox.ini b/tox.ini index 106db9d..ff386d6 100644 --- a/tox.ini +++ b/tox.ini @@ -32,7 +32,7 @@ max-line-length=160 [testenv:isort-check] deps = isort -commands = isort -ns __init__.py -c -rc stix2 +commands = isort -rc stix2 -c -df [travis] python =