Fix isort settings, rename Observable to clarify

it's an internal class
stix2.1
clenk 2017-05-09 18:03:46 -04:00
parent bdd18be6c3
commit 67935d08fe
7 changed files with 39 additions and 30 deletions

7
.isort.cfg Normal file
View File

@ -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

View File

@ -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:

View File

@ -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),

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 =