pre-commit stylistic fixes

pull/1/head
Michael Chisholm 2021-07-06 20:40:50 -04:00
parent 2cda97cf5e
commit 99a8ade4cd
8 changed files with 52 additions and 56 deletions

View File

@ -137,7 +137,7 @@ class _STIXBase(collections.abc.Mapping):
) )
if registered_ext_class: if registered_ext_class:
registered_toplevel_extension_props.update( registered_toplevel_extension_props.update(
registered_ext_class._toplevel_properties registered_ext_class._toplevel_properties,
) )
else: else:
has_unregistered_toplevel_extension = True has_unregistered_toplevel_extension = True
@ -175,7 +175,7 @@ class _STIXBase(collections.abc.Mapping):
# properties defined on this instance as a result of toplevel property # properties defined on this instance as a result of toplevel property
# extensions. # extensions.
defined_properties = collections.ChainMap( defined_properties = collections.ChainMap(
self._properties, registered_toplevel_extension_props self._properties, registered_toplevel_extension_props,
) )
assigned_properties = collections.ChainMap(kwargs, custom_props) assigned_properties = collections.ChainMap(kwargs, custom_props)
@ -186,7 +186,7 @@ class _STIXBase(collections.abc.Mapping):
property_order = itertools.chain( property_order = itertools.chain(
self._properties, self._properties,
toplevel_extension_props, toplevel_extension_props,
sorted(all_custom_prop_names) sorted(all_custom_prop_names),
) )
setting_kwargs = {} setting_kwargs = {}
@ -208,7 +208,7 @@ class _STIXBase(collections.abc.Mapping):
# Detect any missing required properties # Detect any missing required properties
required_properties = set( required_properties = set(
get_required_properties(defined_properties) get_required_properties(defined_properties),
) )
missing_kwargs = required_properties - setting_kwargs.keys() missing_kwargs = required_properties - setting_kwargs.keys()
if missing_kwargs: if missing_kwargs:

View File

@ -110,14 +110,14 @@ def _custom_extension_builder(cls, type, properties, version, base_class):
extension_type_prop = EnumProperty( extension_type_prop = EnumProperty(
[ [
"new-sdo", "new-sco", "new-sro", "property-extension", "new-sdo", "new-sco", "new-sro", "property-extension",
"toplevel-property-extension" "toplevel-property-extension",
], ],
required=False, required=False,
fixed=extension_type, fixed=extension_type,
) )
nested_properties = { nested_properties = {
"extension_type": extension_type_prop "extension_type": extension_type_prop,
} }
if extension_type == "toplevel-property-extension": if extension_type == "toplevel-property-extension":

View File

@ -1,6 +1,5 @@
"""STIX2 core serialization methods.""" """STIX2 core serialization methods."""
import copy
import datetime as dt import datetime as dt
import io import io

View File

@ -10,7 +10,7 @@ import stix2.registry
import stix2.v21 import stix2.v21
from ...exceptions import ( from ...exceptions import (
DuplicateRegistrationError, InvalidValueError, MissingPropertiesError DuplicateRegistrationError, InvalidValueError, MissingPropertiesError,
) )
from .constants import FAKE_TIME, IDENTITY_ID, MARKING_DEFINITION_ID from .constants import FAKE_TIME, IDENTITY_ID, MARKING_DEFINITION_ID
@ -1685,7 +1685,7 @@ def _register_extension(ext, props):
stix2.v21.CustomExtension( stix2.v21.CustomExtension(
ext_def_id, ext_def_id,
props props,
)(ext) )(ext)
try: try:
@ -1703,8 +1703,8 @@ def test_nested_ext_prop_meta():
props = { props = {
"intprop": stix2.properties.IntegerProperty(required=True), "intprop": stix2.properties.IntegerProperty(required=True),
"strprop": stix2.properties.StringProperty( "strprop": stix2.properties.StringProperty(
required=False, default=lambda: "foo" required=False, default=lambda: "foo",
) ),
} }
with _register_extension(TestExt, props) as ext_def_id: with _register_extension(TestExt, props) as ext_def_id:
@ -1715,9 +1715,9 @@ def test_nested_ext_prop_meta():
ext_def_id: { ext_def_id: {
"extension_type": "property-extension", "extension_type": "property-extension",
"intprop": "1", "intprop": "1",
"strprop": 2 "strprop": 2,
} },
} },
) )
assert obj.extensions[ext_def_id].extension_type == "property-extension" assert obj.extensions[ext_def_id].extension_type == "property-extension"
@ -1730,8 +1730,8 @@ def test_nested_ext_prop_meta():
ext_def_id: { ext_def_id: {
"extension_type": "property-extension", "extension_type": "property-extension",
"intprop": "1", "intprop": "1",
} },
} },
) )
# Ensure default kicked in # Ensure default kicked in
@ -1744,9 +1744,9 @@ def test_nested_ext_prop_meta():
ext_def_id: { ext_def_id: {
"extension_type": "property-extension", "extension_type": "property-extension",
# wrong value type # wrong value type
"intprop": "foo" "intprop": "foo",
} },
} },
) )
with pytest.raises(InvalidValueError): with pytest.raises(InvalidValueError):
@ -1756,9 +1756,9 @@ def test_nested_ext_prop_meta():
ext_def_id: { ext_def_id: {
"extension_type": "property-extension", "extension_type": "property-extension",
# missing required property # missing required property
"strprop": "foo" "strprop": "foo",
} },
} },
) )
with pytest.raises(InvalidValueError): with pytest.raises(InvalidValueError):
@ -1770,8 +1770,8 @@ def test_nested_ext_prop_meta():
"intprop": 1, "intprop": 1,
# Use of undefined property # Use of undefined property
"foo": False, "foo": False,
} },
} },
) )
with pytest.raises(InvalidValueError): with pytest.raises(InvalidValueError):
@ -1783,8 +1783,8 @@ def test_nested_ext_prop_meta():
"extension_type": "new-sdo", "extension_type": "new-sdo",
"intprop": 1, "intprop": 1,
"strprop": "foo", "strprop": "foo",
} },
} },
) )
@ -1796,8 +1796,8 @@ def test_toplevel_ext_prop_meta():
props = { props = {
"intprop": stix2.properties.IntegerProperty(required=True), "intprop": stix2.properties.IntegerProperty(required=True),
"strprop": stix2.properties.StringProperty( "strprop": stix2.properties.StringProperty(
required=False, default=lambda: "foo" required=False, default=lambda: "foo",
) ),
} }
with _register_extension(TestExt, props) as ext_def_id: with _register_extension(TestExt, props) as ext_def_id:
@ -1808,9 +1808,9 @@ def test_toplevel_ext_prop_meta():
strprop=2, strprop=2,
extensions={ extensions={
ext_def_id: { ext_def_id: {
"extension_type": "toplevel-property-extension" "extension_type": "toplevel-property-extension",
} },
} },
) )
assert obj.extensions[ext_def_id].extension_type == "toplevel-property-extension" assert obj.extensions[ext_def_id].extension_type == "toplevel-property-extension"
@ -1822,9 +1822,9 @@ def test_toplevel_ext_prop_meta():
intprop=1, intprop=1,
extensions={ extensions={
ext_def_id: { ext_def_id: {
"extension_type": "toplevel-property-extension" "extension_type": "toplevel-property-extension",
} },
} },
) )
# Ensure default kicked in # Ensure default kicked in
@ -1836,9 +1836,9 @@ def test_toplevel_ext_prop_meta():
intprop="foo", # wrong value type intprop="foo", # wrong value type
extensions={ extensions={
ext_def_id: { ext_def_id: {
"extension_type": "toplevel-property-extension" "extension_type": "toplevel-property-extension",
} },
} },
) )
with pytest.raises(InvalidValueError): with pytest.raises(InvalidValueError):
@ -1850,8 +1850,8 @@ def test_toplevel_ext_prop_meta():
"extension_type": "toplevel-property-extension", "extension_type": "toplevel-property-extension",
# Use of undefined property # Use of undefined property
"foo": False, "foo": False,
} },
} },
) )
with pytest.raises(MissingPropertiesError): with pytest.raises(MissingPropertiesError):
@ -1860,9 +1860,9 @@ def test_toplevel_ext_prop_meta():
strprop="foo", # missing required property strprop="foo", # missing required property
extensions={ extensions={
ext_def_id: { ext_def_id: {
"extension_type": "toplevel-property-extension" "extension_type": "toplevel-property-extension",
} },
} },
) )

View File

@ -25,14 +25,13 @@ from .common import (
) )
from .observables import ( from .observables import (
URL, AlternateDataStream, ArchiveExt, Artifact, AutonomousSystem, URL, AlternateDataStream, ArchiveExt, Artifact, AutonomousSystem,
CustomObservable, Directory, DomainName, EmailAddress, CustomObservable, Directory, DomainName, EmailAddress, EmailMessage,
EmailMessage, EmailMIMEComponent, File, HTTPRequestExt, ICMPExt, EmailMIMEComponent, File, HTTPRequestExt, ICMPExt, IPv4Address,
IPv4Address, IPv6Address, MACAddress, Mutex, NetworkTraffic, NTFSExt, IPv6Address, MACAddress, Mutex, NetworkTraffic, NTFSExt, PDFExt, Process,
PDFExt, Process, RasterImageExt, SocketExt, Software, TCPExt, RasterImageExt, SocketExt, Software, TCPExt, UNIXAccountExt, UserAccount,
UNIXAccountExt, UserAccount, WindowsPEBinaryExt, WindowsPEBinaryExt, WindowsPEOptionalHeaderType, WindowsPESection,
WindowsPEOptionalHeaderType, WindowsPESection, WindowsProcessExt, WindowsProcessExt, WindowsRegistryKey, WindowsRegistryValueType,
WindowsRegistryKey, WindowsRegistryValueType, WindowsServiceExt, WindowsServiceExt, X509Certificate, X509V3ExtensionsType,
X509Certificate, X509V3ExtensionsType,
) )
from .sdo import ( from .sdo import (
AttackPattern, Campaign, CourseOfAction, CustomObject, Grouping, Identity, AttackPattern, Campaign, CourseOfAction, CustomObject, Grouping, Identity,

View File

@ -3,7 +3,7 @@
from collections import OrderedDict from collections import OrderedDict
from . import _Extension from . import _Extension
from ..custom import _custom_marking_builder, _custom_extension_builder from ..custom import _custom_extension_builder, _custom_marking_builder
from ..exceptions import InvalidValueError, PropertyPresenceError from ..exceptions import InvalidValueError, PropertyPresenceError
from ..markings import _MarkingsMixin from ..markings import _MarkingsMixin
from ..markings.utils import check_tlp_marking from ..markings.utils import check_tlp_marking
@ -268,8 +268,6 @@ def CustomMarking(type='x-custom-marking', properties=None, extension_name=None)
""" """
def wrapper(cls): def wrapper(cls):
if extension_name: if extension_name:
from . import observables
@CustomExtension(type=extension_name, properties=properties) @CustomExtension(type=extension_name, properties=properties)
class NameExtension: class NameExtension:
extension_type = 'property-extension' extension_type = 'property-extension'

View File

@ -18,7 +18,7 @@ from ..properties import (
TypeProperty, TypeProperty,
) )
from .base import _Extension, _Observable, _STIXBase21 from .base import _Extension, _Observable, _STIXBase21
from .common import GranularMarking, CustomExtension from .common import CustomExtension, GranularMarking
from .vocab import ( from .vocab import (
ACCOUNT_TYPE, ENCRYPTION_ALGORITHM, HASHING_ALGORITHM, ACCOUNT_TYPE, ENCRYPTION_ALGORITHM, HASHING_ALGORITHM,
NETWORK_SOCKET_ADDRESS_FAMILY, NETWORK_SOCKET_TYPE, NETWORK_SOCKET_ADDRESS_FAMILY, NETWORK_SOCKET_TYPE,
@ -877,7 +877,7 @@ def CustomObservable(type='x-custom-observable', properties=None, id_contrib_pro
[ [
('type', TypeProperty(type, spec_version='2.1')), ('type', TypeProperty(type, spec_version='2.1')),
('spec_version', StringProperty(fixed='2.1')), ('spec_version', StringProperty(fixed='2.1')),
('id', IDProperty(type, spec_version='2.1')) ('id', IDProperty(type, spec_version='2.1')),
], ],
properties, properties,
[ [

View File

@ -19,7 +19,7 @@ from ..properties import (
from ..utils import NOW from ..utils import NOW
from .base import _DomainObject from .base import _DomainObject
from .common import ( from .common import (
CustomExtension, ExternalReference, GranularMarking, KillChainPhase CustomExtension, ExternalReference, GranularMarking, KillChainPhase,
) )
from .vocab import ( from .vocab import (
ATTACK_MOTIVATION, ATTACK_RESOURCE_LEVEL, GROUPING_CONTEXT, IDENTITY_CLASS, ATTACK_MOTIVATION, ATTACK_RESOURCE_LEVEL, GROUPING_CONTEXT, IDENTITY_CLASS,