pre-commit stylistic fixes
parent
92a478b39b
commit
38067a6ec7
|
@ -73,8 +73,8 @@ def class_for_type(stix_type, stix_version, category=None):
|
|||
or cat_map["observables"].get(stix_type) \
|
||||
or cat_map["markings"].get(stix_type)
|
||||
|
||||
# Left "observable-extensions" out; it has a different
|
||||
# substructure. A version->category->type lookup would result
|
||||
# in another map, not a class. So it doesn't fit the pattern.
|
||||
# Left "observable-extensions" out; it has a different
|
||||
# substructure. A version->category->type lookup would result
|
||||
# in another map, not a class. So it doesn't fit the pattern.
|
||||
|
||||
return cls
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import pytest
|
||||
|
||||
import stix2.utils
|
||||
|
||||
|
||||
###
|
||||
### Tests using types/behaviors common to STIX 2.0 and 2.1.
|
||||
# Tests using types/behaviors common to STIX 2.0 and 2.1.
|
||||
###
|
||||
|
||||
|
||||
|
@ -21,8 +21,8 @@ import stix2.utils
|
|||
"report",
|
||||
"threat-actor",
|
||||
"tool",
|
||||
"vulnerability"
|
||||
]
|
||||
"vulnerability",
|
||||
],
|
||||
)
|
||||
def test_is_sdo(type_, stix_version):
|
||||
assert stix2.utils.is_sdo(type_, stix_version)
|
||||
|
@ -31,7 +31,7 @@ def test_is_sdo(type_, stix_version):
|
|||
assert stix2.utils.is_sdo(id_, stix_version)
|
||||
|
||||
assert stix2.utils.is_stix_type(
|
||||
type_, stix_version, stix2.utils.STIXTypeClass.SDO
|
||||
type_, stix_version, stix2.utils.STIXTypeClass.SDO,
|
||||
)
|
||||
|
||||
|
||||
|
@ -44,8 +44,8 @@ def test_is_sdo(type_, stix_version):
|
|||
"bundle",
|
||||
"language-content",
|
||||
"ipv4-addr",
|
||||
"foo"
|
||||
]
|
||||
"foo",
|
||||
],
|
||||
)
|
||||
def test_is_not_sdo(type_, stix_version):
|
||||
assert not stix2.utils.is_sdo(type_, stix_version)
|
||||
|
@ -54,12 +54,12 @@ def test_is_not_sdo(type_, stix_version):
|
|||
assert not stix2.utils.is_sdo(id_, stix_version)
|
||||
|
||||
d = {
|
||||
"type": type_
|
||||
"type": type_,
|
||||
}
|
||||
assert not stix2.utils.is_sdo(d, stix_version)
|
||||
|
||||
assert not stix2.utils.is_stix_type(
|
||||
type_, stix_version, stix2.utils.STIXTypeClass.SDO
|
||||
type_, stix_version, stix2.utils.STIXTypeClass.SDO,
|
||||
)
|
||||
|
||||
|
||||
|
@ -83,8 +83,8 @@ def test_is_not_sdo(type_, stix_version):
|
|||
"url",
|
||||
"user-account",
|
||||
"windows-registry-key",
|
||||
"x509-certificate"
|
||||
]
|
||||
"x509-certificate",
|
||||
],
|
||||
)
|
||||
def test_is_sco(type_, stix_version):
|
||||
assert stix2.utils.is_sco(type_, stix_version)
|
||||
|
@ -93,7 +93,7 @@ def test_is_sco(type_, stix_version):
|
|||
assert stix2.utils.is_sco(id_, stix_version)
|
||||
|
||||
assert stix2.utils.is_stix_type(
|
||||
type_, stix_version, stix2.utils.STIXTypeClass.SCO
|
||||
type_, stix_version, stix2.utils.STIXTypeClass.SCO,
|
||||
)
|
||||
|
||||
|
||||
|
@ -105,8 +105,8 @@ def test_is_sco(type_, stix_version):
|
|||
"marking-definition",
|
||||
"bundle",
|
||||
"language-content",
|
||||
"foo"
|
||||
]
|
||||
"foo",
|
||||
],
|
||||
)
|
||||
def test_is_not_sco(type_, stix_version):
|
||||
assert not stix2.utils.is_sco(type_, stix_version)
|
||||
|
@ -115,12 +115,12 @@ def test_is_not_sco(type_, stix_version):
|
|||
assert not stix2.utils.is_sco(id_, stix_version)
|
||||
|
||||
d = {
|
||||
"type": type_
|
||||
"type": type_,
|
||||
}
|
||||
assert not stix2.utils.is_sco(d, stix_version)
|
||||
|
||||
assert not stix2.utils.is_stix_type(
|
||||
type_, stix_version, stix2.utils.STIXTypeClass.SCO
|
||||
type_, stix_version, stix2.utils.STIXTypeClass.SCO,
|
||||
)
|
||||
|
||||
|
||||
|
@ -128,8 +128,8 @@ def test_is_not_sco(type_, stix_version):
|
|||
@pytest.mark.parametrize(
|
||||
"type_", [
|
||||
"relationship",
|
||||
"sighting"
|
||||
]
|
||||
"sighting",
|
||||
],
|
||||
)
|
||||
def test_is_sro(type_, stix_version):
|
||||
assert stix2.utils.is_sro(type_, stix_version)
|
||||
|
@ -138,7 +138,7 @@ def test_is_sro(type_, stix_version):
|
|||
assert stix2.utils.is_sro(id_, stix_version)
|
||||
|
||||
assert stix2.utils.is_stix_type(
|
||||
type_, stix_version, stix2.utils.STIXTypeClass.SRO
|
||||
type_, stix_version, stix2.utils.STIXTypeClass.SRO,
|
||||
)
|
||||
|
||||
|
||||
|
@ -150,8 +150,8 @@ def test_is_sro(type_, stix_version):
|
|||
"bundle",
|
||||
"language-content",
|
||||
"ipv4-addr",
|
||||
"foo"
|
||||
]
|
||||
"foo",
|
||||
],
|
||||
)
|
||||
def test_is_not_sro(type_, stix_version):
|
||||
assert not stix2.utils.is_sro(type_, stix_version)
|
||||
|
@ -160,12 +160,12 @@ def test_is_not_sro(type_, stix_version):
|
|||
assert not stix2.utils.is_sro(id_, stix_version)
|
||||
|
||||
d = {
|
||||
"type": type_
|
||||
"type": type_,
|
||||
}
|
||||
assert not stix2.utils.is_sro(d, stix_version)
|
||||
|
||||
assert not stix2.utils.is_stix_type(
|
||||
type_, stix_version, stix2.utils.STIXTypeClass.SRO
|
||||
type_, stix_version, stix2.utils.STIXTypeClass.SRO,
|
||||
)
|
||||
|
||||
|
||||
|
@ -177,7 +177,7 @@ def test_is_marking(stix_version):
|
|||
assert stix2.utils.is_marking(id_, stix_version)
|
||||
|
||||
assert stix2.utils.is_stix_type(
|
||||
"marking-definition", stix_version, "marking-definition"
|
||||
"marking-definition", stix_version, "marking-definition",
|
||||
)
|
||||
|
||||
|
||||
|
@ -188,8 +188,8 @@ def test_is_marking(stix_version):
|
|||
"bundle",
|
||||
"language-content",
|
||||
"ipv4-addr",
|
||||
"foo"
|
||||
]
|
||||
"foo",
|
||||
],
|
||||
)
|
||||
def test_is_not_marking(type_, stix_version):
|
||||
assert not stix2.utils.is_marking(type_, stix_version)
|
||||
|
@ -198,12 +198,12 @@ def test_is_not_marking(type_, stix_version):
|
|||
assert not stix2.utils.is_marking(id_, stix_version)
|
||||
|
||||
d = {
|
||||
"type": type_
|
||||
"type": type_,
|
||||
}
|
||||
assert not stix2.utils.is_marking(d, stix_version)
|
||||
|
||||
assert not stix2.utils.is_stix_type(
|
||||
type_, stix_version, "marking-definition"
|
||||
type_, stix_version, "marking-definition",
|
||||
)
|
||||
|
||||
|
||||
|
@ -215,8 +215,8 @@ def test_is_not_marking(type_, stix_version):
|
|||
"sighting",
|
||||
"marking-definition",
|
||||
"bundle",
|
||||
"ipv4-addr"
|
||||
]
|
||||
"ipv4-addr",
|
||||
],
|
||||
)
|
||||
def test_is_object(type_, stix_version):
|
||||
assert stix2.utils.is_object(type_, stix_version)
|
||||
|
@ -233,7 +233,7 @@ def test_is_not_object(stix_version):
|
|||
assert not stix2.utils.is_object(id_, stix_version)
|
||||
|
||||
d = {
|
||||
"type": "foo"
|
||||
"type": "foo",
|
||||
}
|
||||
assert not stix2.utils.is_object(d, stix_version)
|
||||
|
||||
|
@ -242,21 +242,21 @@ def test_is_not_object(stix_version):
|
|||
def test_is_stix_type(stix_version):
|
||||
|
||||
assert not stix2.utils.is_stix_type(
|
||||
"foo", stix_version, stix2.utils.STIXTypeClass.SDO, "foo"
|
||||
"foo", stix_version, stix2.utils.STIXTypeClass.SDO, "foo",
|
||||
)
|
||||
|
||||
assert stix2.utils.is_stix_type(
|
||||
"bundle", stix_version, "foo", "bundle"
|
||||
"bundle", stix_version, "foo", "bundle",
|
||||
)
|
||||
|
||||
assert stix2.utils.is_stix_type(
|
||||
"identity", stix_version,
|
||||
stix2.utils.STIXTypeClass.SDO,
|
||||
stix2.utils.STIXTypeClass.SRO
|
||||
stix2.utils.STIXTypeClass.SRO,
|
||||
)
|
||||
|
||||
assert stix2.utils.is_stix_type(
|
||||
"software", stix_version,
|
||||
stix2.utils.STIXTypeClass.SDO,
|
||||
stix2.utils.STIXTypeClass.SCO
|
||||
stix2.utils.STIXTypeClass.SCO,
|
||||
)
|
||||
|
|
|
@ -252,12 +252,12 @@ def test_iterate_over_values(dict_value, tuple_to_find, expected_index):
|
|||
"report",
|
||||
"threat-actor",
|
||||
"tool",
|
||||
"vulnerability"
|
||||
]
|
||||
"vulnerability",
|
||||
],
|
||||
)
|
||||
def test_is_sdo_dict(type_):
|
||||
d = {
|
||||
"type": type_
|
||||
"type": type_,
|
||||
}
|
||||
assert stix2.utils.is_sdo(d, "2.0")
|
||||
|
||||
|
@ -277,7 +277,7 @@ def test_is_sdo_dict(type_):
|
|||
{"type": "relationship"},
|
||||
{"type": "foo", "spec_version": "2.1"},
|
||||
{"type": "foo"},
|
||||
]
|
||||
],
|
||||
)
|
||||
def test_is_not_sdo_dict(dict_):
|
||||
assert not stix2.utils.is_sdo(dict_, "2.0")
|
||||
|
@ -285,7 +285,7 @@ def test_is_not_sdo_dict(dict_):
|
|||
|
||||
def test_is_sco_dict():
|
||||
d = {
|
||||
"type": "file"
|
||||
"type": "file",
|
||||
}
|
||||
|
||||
assert stix2.utils.is_sco(d, "2.0")
|
||||
|
@ -306,7 +306,7 @@ def test_is_sco_dict():
|
|||
{"type": "relationship"},
|
||||
{"type": "foo", "spec_version": "2.1"},
|
||||
{"type": "foo"},
|
||||
]
|
||||
],
|
||||
)
|
||||
def test_is_not_sco_dict(dict_):
|
||||
assert not stix2.utils.is_sco(dict_, "2.0")
|
||||
|
@ -316,7 +316,7 @@ def test_is_not_sco_dict(dict_):
|
|||
"dict_", [
|
||||
{"type": "relationship"},
|
||||
{"type": "sighting"},
|
||||
]
|
||||
],
|
||||
)
|
||||
def test_is_sro_dict(dict_):
|
||||
assert stix2.utils.is_sro(dict_, "2.0")
|
||||
|
@ -338,7 +338,7 @@ def test_is_sro_dict(dict_):
|
|||
{"type": "sighting", "spec_version": "2.1"},
|
||||
{"type": "foo", "spec_version": "2.1"},
|
||||
{"type": "foo"},
|
||||
]
|
||||
],
|
||||
)
|
||||
def test_is_not_sro_dict(dict_):
|
||||
assert not stix2.utils.is_sro(dict_, "2.0")
|
||||
|
@ -357,9 +357,9 @@ def test_is_not_sro_dict(dict_):
|
|||
{"type": "identity"},
|
||||
{"type": "software"},
|
||||
{"type": "marking-definition"},
|
||||
]
|
||||
],
|
||||
},
|
||||
]
|
||||
],
|
||||
)
|
||||
def test_is_object_dict(dict_):
|
||||
assert stix2.utils.is_object(dict_, "2.0")
|
||||
|
@ -376,7 +376,7 @@ def test_is_object_dict(dict_):
|
|||
{"type": "sighting", "spec_version": "2.1"},
|
||||
{"type": "foo", "spec_version": "2.1"},
|
||||
{"type": "foo"},
|
||||
]
|
||||
],
|
||||
)
|
||||
def test_is_not_object_dict(dict_):
|
||||
assert not stix2.utils.is_object(dict_, "2.0")
|
||||
|
|
|
@ -264,13 +264,13 @@ def test_iterate_over_values(dict_value, tuple_to_find, expected_index):
|
|||
"location",
|
||||
"malware-analysis",
|
||||
"note",
|
||||
"opinion"
|
||||
]
|
||||
"opinion",
|
||||
],
|
||||
)
|
||||
def test_is_sdo_dict(type_):
|
||||
d = {
|
||||
"type": type_,
|
||||
"spec_version": "2.1"
|
||||
"spec_version": "2.1",
|
||||
}
|
||||
assert stix2.utils.is_sdo(d, "2.1")
|
||||
|
||||
|
@ -289,7 +289,7 @@ def test_is_sdo_dict(type_):
|
|||
{"type": "relationship", "spec_version": "2.1"},
|
||||
{"type": "relationship"},
|
||||
{"type": "foo", "spec_version": "2.1"},
|
||||
]
|
||||
],
|
||||
)
|
||||
def test_is_not_sdo_dict(dict_):
|
||||
assert not stix2.utils.is_sdo(dict_, "2.1")
|
||||
|
@ -298,7 +298,7 @@ def test_is_not_sdo_dict(dict_):
|
|||
def test_is_sco_dict():
|
||||
d = {
|
||||
"type": "file",
|
||||
"spec_version": "2.1"
|
||||
"spec_version": "2.1",
|
||||
}
|
||||
|
||||
assert stix2.utils.is_sco(d, "2.1")
|
||||
|
@ -318,7 +318,7 @@ def test_is_sco_dict():
|
|||
{"type": "relationship", "spec_version": "2.1"},
|
||||
{"type": "relationship"},
|
||||
{"type": "foo", "spec_version": "2.1"},
|
||||
]
|
||||
],
|
||||
)
|
||||
def test_is_not_sco_dict(dict_):
|
||||
assert not stix2.utils.is_sco(dict_, "2.1")
|
||||
|
@ -328,7 +328,7 @@ def test_is_not_sco_dict(dict_):
|
|||
"dict_", [
|
||||
{"type": "relationship", "spec_version": "2.1"},
|
||||
{"type": "sighting", "spec_version": "2.1"},
|
||||
]
|
||||
],
|
||||
)
|
||||
def test_is_sro_dict(dict_):
|
||||
assert stix2.utils.is_sro(dict_, "2.1")
|
||||
|
@ -349,7 +349,7 @@ def test_is_sro_dict(dict_):
|
|||
{"type": "relationship"},
|
||||
{"type": "sighting"},
|
||||
{"type": "foo", "spec_version": "2.1"},
|
||||
]
|
||||
],
|
||||
)
|
||||
def test_is_not_sro_dict(dict_):
|
||||
assert not stix2.utils.is_sro(dict_, "2.1")
|
||||
|
@ -369,9 +369,9 @@ def test_is_not_sro_dict(dict_):
|
|||
{"type": "software", "spec_version": "2.1"},
|
||||
{"type": "marking-definition", "spec_version": "2.1"},
|
||||
{"type": "language-content", "spec_version": "2.1"},
|
||||
]
|
||||
],
|
||||
},
|
||||
]
|
||||
],
|
||||
)
|
||||
def test_is_object_dict(dict_):
|
||||
assert stix2.utils.is_object(dict_, "2.1")
|
||||
|
@ -387,7 +387,7 @@ def test_is_object_dict(dict_):
|
|||
{"type": "relationship"},
|
||||
{"type": "sighting"},
|
||||
{"type": "foo"},
|
||||
]
|
||||
],
|
||||
)
|
||||
def test_is_not_object_dict(dict_):
|
||||
assert not stix2.utils.is_object(dict_, "2.1")
|
||||
|
|
|
@ -369,7 +369,7 @@ def test_version_sco_id_contributing_properties_dict():
|
|||
"name": "data.txt",
|
||||
"created": "1973-11-23T02:31:37Z",
|
||||
"modified": "1991-05-13T19:24:57Z",
|
||||
"revoked": False
|
||||
"revoked": False,
|
||||
}
|
||||
|
||||
with pytest.raises(stix2.exceptions.UnmodifiablePropertyError) as e:
|
||||
|
|
|
@ -10,6 +10,7 @@ import pytz
|
|||
import six
|
||||
|
||||
import stix2.version
|
||||
|
||||
try:
|
||||
import stix2.registry as mappings
|
||||
except ImportError:
|
||||
|
@ -408,7 +409,7 @@ def is_sdo(value, stix_version=stix2.version.DEFAULT_VERSION):
|
|||
type_ = _stix_type_of(value)
|
||||
result = type_ in cls_maps["objects"] and type_ not in {
|
||||
"relationship", "sighting", "marking-definition", "bundle",
|
||||
"language-content"
|
||||
"language-content",
|
||||
}
|
||||
|
||||
return result
|
||||
|
@ -500,7 +501,7 @@ def is_object(value, stix_version=stix2.version.DEFAULT_VERSION):
|
|||
cls_maps = mappings.STIX2_OBJ_MAPS[stix_version]
|
||||
type_ = _stix_type_of(value)
|
||||
result = type_ in cls_maps["observables"] \
|
||||
or type_ in cls_maps["objects"]
|
||||
or type_ in cls_maps["objects"]
|
||||
|
||||
return result
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ from six.moves.collections_abc import Mapping
|
|||
import stix2.base
|
||||
import stix2.registry
|
||||
from stix2.utils import (
|
||||
get_timestamp, parse_into_datetime, detect_spec_version,
|
||||
is_sdo, is_sro, is_sco
|
||||
detect_spec_version, get_timestamp, is_sco, is_sdo, is_sro,
|
||||
parse_into_datetime,
|
||||
)
|
||||
import stix2.v20
|
||||
|
||||
|
@ -83,7 +83,6 @@ def _is_versionable(data):
|
|||
|
||||
# First, determine spec version. It's easy for our stix2 objects; more
|
||||
# work for dicts.
|
||||
is_21 = False
|
||||
if isinstance(data, stix2.v20._STIXBase20):
|
||||
stix_version = "2.0"
|
||||
elif isinstance(data, stix2.v21._STIXBase21):
|
||||
|
@ -121,7 +120,7 @@ def _is_versionable(data):
|
|||
elif is_sco(obj_type, stix_version):
|
||||
# but do check SCOs
|
||||
cls = stix2.registry.class_for_type(
|
||||
obj_type, stix_version, "observables"
|
||||
obj_type, stix_version, "observables",
|
||||
)
|
||||
is_versionable = _VERSIONING_PROPERTIES.issubset(
|
||||
cls._properties,
|
||||
|
@ -174,7 +173,7 @@ def new_version(data, allow_custom=None, **kwargs):
|
|||
cls = data.__class__
|
||||
else:
|
||||
cls = stix2.registry.class_for_type(
|
||||
data["type"], stix_version, "observables"
|
||||
data["type"], stix_version, "observables",
|
||||
)
|
||||
|
||||
sco_locked_props = cls._id_contributing_properties
|
||||
|
@ -199,7 +198,7 @@ def new_version(data, allow_custom=None, **kwargs):
|
|||
|
||||
new_modified = get_timestamp()
|
||||
new_modified = _fudge_modified(
|
||||
old_modified, new_modified, stix_version == "2.1"
|
||||
old_modified, new_modified, stix_version == "2.1",
|
||||
)
|
||||
|
||||
kwargs['modified'] = new_modified
|
||||
|
|
Loading…
Reference in New Issue