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:
registered_toplevel_extension_props.update(
registered_ext_class._toplevel_properties
registered_ext_class._toplevel_properties,
)
else:
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
# extensions.
defined_properties = collections.ChainMap(
self._properties, registered_toplevel_extension_props
self._properties, registered_toplevel_extension_props,
)
assigned_properties = collections.ChainMap(kwargs, custom_props)
@ -186,7 +186,7 @@ class _STIXBase(collections.abc.Mapping):
property_order = itertools.chain(
self._properties,
toplevel_extension_props,
sorted(all_custom_prop_names)
sorted(all_custom_prop_names),
)
setting_kwargs = {}
@ -208,7 +208,7 @@ class _STIXBase(collections.abc.Mapping):
# Detect any missing required properties
required_properties = set(
get_required_properties(defined_properties)
get_required_properties(defined_properties),
)
missing_kwargs = required_properties - setting_kwargs.keys()
if missing_kwargs:

View File

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

View File

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

View File

@ -10,7 +10,7 @@ import stix2.registry
import stix2.v21
from ...exceptions import (
DuplicateRegistrationError, InvalidValueError, MissingPropertiesError
DuplicateRegistrationError, InvalidValueError, MissingPropertiesError,
)
from .constants import FAKE_TIME, IDENTITY_ID, MARKING_DEFINITION_ID
@ -1685,7 +1685,7 @@ def _register_extension(ext, props):
stix2.v21.CustomExtension(
ext_def_id,
props
props,
)(ext)
try:
@ -1703,8 +1703,8 @@ def test_nested_ext_prop_meta():
props = {
"intprop": stix2.properties.IntegerProperty(required=True),
"strprop": stix2.properties.StringProperty(
required=False, default=lambda: "foo"
)
required=False, default=lambda: "foo",
),
}
with _register_extension(TestExt, props) as ext_def_id:
@ -1715,9 +1715,9 @@ def test_nested_ext_prop_meta():
ext_def_id: {
"extension_type": "property-extension",
"intprop": "1",
"strprop": 2
}
}
"strprop": 2,
},
},
)
assert obj.extensions[ext_def_id].extension_type == "property-extension"
@ -1730,8 +1730,8 @@ def test_nested_ext_prop_meta():
ext_def_id: {
"extension_type": "property-extension",
"intprop": "1",
}
}
},
},
)
# Ensure default kicked in
@ -1744,9 +1744,9 @@ def test_nested_ext_prop_meta():
ext_def_id: {
"extension_type": "property-extension",
# wrong value type
"intprop": "foo"
}
}
"intprop": "foo",
},
},
)
with pytest.raises(InvalidValueError):
@ -1756,9 +1756,9 @@ def test_nested_ext_prop_meta():
ext_def_id: {
"extension_type": "property-extension",
# missing required property
"strprop": "foo"
}
}
"strprop": "foo",
},
},
)
with pytest.raises(InvalidValueError):
@ -1770,8 +1770,8 @@ def test_nested_ext_prop_meta():
"intprop": 1,
# Use of undefined property
"foo": False,
}
}
},
},
)
with pytest.raises(InvalidValueError):
@ -1783,8 +1783,8 @@ def test_nested_ext_prop_meta():
"extension_type": "new-sdo",
"intprop": 1,
"strprop": "foo",
}
}
},
},
)
@ -1796,8 +1796,8 @@ def test_toplevel_ext_prop_meta():
props = {
"intprop": stix2.properties.IntegerProperty(required=True),
"strprop": stix2.properties.StringProperty(
required=False, default=lambda: "foo"
)
required=False, default=lambda: "foo",
),
}
with _register_extension(TestExt, props) as ext_def_id:
@ -1808,9 +1808,9 @@ def test_toplevel_ext_prop_meta():
strprop=2,
extensions={
ext_def_id: {
"extension_type": "toplevel-property-extension"
}
}
"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,
extensions={
ext_def_id: {
"extension_type": "toplevel-property-extension"
}
}
"extension_type": "toplevel-property-extension",
},
},
)
# Ensure default kicked in
@ -1836,9 +1836,9 @@ def test_toplevel_ext_prop_meta():
intprop="foo", # wrong value type
extensions={
ext_def_id: {
"extension_type": "toplevel-property-extension"
}
}
"extension_type": "toplevel-property-extension",
},
},
)
with pytest.raises(InvalidValueError):
@ -1850,8 +1850,8 @@ def test_toplevel_ext_prop_meta():
"extension_type": "toplevel-property-extension",
# Use of undefined property
"foo": False,
}
}
},
},
)
with pytest.raises(MissingPropertiesError):
@ -1860,9 +1860,9 @@ def test_toplevel_ext_prop_meta():
strprop="foo", # missing required property
extensions={
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 (
URL, AlternateDataStream, ArchiveExt, Artifact, AutonomousSystem,
CustomObservable, Directory, DomainName, EmailAddress,
EmailMessage, EmailMIMEComponent, File, HTTPRequestExt, ICMPExt,
IPv4Address, IPv6Address, MACAddress, Mutex, NetworkTraffic, NTFSExt,
PDFExt, Process, RasterImageExt, SocketExt, Software, TCPExt,
UNIXAccountExt, UserAccount, WindowsPEBinaryExt,
WindowsPEOptionalHeaderType, WindowsPESection, WindowsProcessExt,
WindowsRegistryKey, WindowsRegistryValueType, WindowsServiceExt,
X509Certificate, X509V3ExtensionsType,
CustomObservable, Directory, DomainName, EmailAddress, EmailMessage,
EmailMIMEComponent, File, HTTPRequestExt, ICMPExt, IPv4Address,
IPv6Address, MACAddress, Mutex, NetworkTraffic, NTFSExt, PDFExt, Process,
RasterImageExt, SocketExt, Software, TCPExt, UNIXAccountExt, UserAccount,
WindowsPEBinaryExt, WindowsPEOptionalHeaderType, WindowsPESection,
WindowsProcessExt, WindowsRegistryKey, WindowsRegistryValueType,
WindowsServiceExt, X509Certificate, X509V3ExtensionsType,
)
from .sdo import (
AttackPattern, Campaign, CourseOfAction, CustomObject, Grouping, Identity,

View File

@ -3,7 +3,7 @@
from collections import OrderedDict
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 ..markings import _MarkingsMixin
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):
if extension_name:
from . import observables
@CustomExtension(type=extension_name, properties=properties)
class NameExtension:
extension_type = 'property-extension'

View File

@ -18,7 +18,7 @@ from ..properties import (
TypeProperty,
)
from .base import _Extension, _Observable, _STIXBase21
from .common import GranularMarking, CustomExtension
from .common import CustomExtension, GranularMarking
from .vocab import (
ACCOUNT_TYPE, ENCRYPTION_ALGORITHM, HASHING_ALGORITHM,
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')),
('spec_version', StringProperty(fixed='2.1')),
('id', IDProperty(type, spec_version='2.1'))
('id', IDProperty(type, spec_version='2.1')),
],
properties,
[

View File

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