Skip to content

Commit

Permalink
Update guide docs, remove outdated comments
Browse files Browse the repository at this point in the history
  • Loading branch information
clenk committed Apr 14, 2021
1 parent 9f96d76 commit a002c17
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 140 deletions.
6 changes: 3 additions & 3 deletions docs/guide/extensions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"source": [
"## STIX Extensions\n",
"\n",
"This page is specific for the STIX Extensions mechanism defined in STIX 2.1 CS 02, for the deprecated STIX Customization mechanisms see the [Custom](custom.ipynb) section.\n",
"This page is specific for the STIX Extensions mechanism defined in STIX 2.1 CS 02. For the deprecated STIX Customization mechanisms see the [Custom](custom.ipynb) section.\n",
"\n",
"### Top Level Property Extensions\n",
"\n",
Expand Down Expand Up @@ -336,7 +336,7 @@
"source": [
"### Using CustomExtension decorator\n",
"\n",
"However, in order to prevent repetitive instantiation of the same extension, the `@CustomExtension` when used in a class for registering the `extension-definition` with stix2, it allows passing the id. Use the `extension_type` class variable to define what kind of extension it is."
"However, in order to prevent repetitive instantiation of the same extension, the `@CustomExtension` decorator can be used to register the `extension-definition` with stix2. Use the `extension_type` class variable to define what kind of extension it is. Then its id can be passed into objects that use this extension."
]
},
{
Expand Down Expand Up @@ -922,7 +922,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.9.2"
}
},
"nbformat": 4,
Expand Down
331 changes: 206 additions & 125 deletions docs/guide/markings.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/guide/patterns.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@
"\n",
"ece14 = ObservationExpression(EqualityComparisonExpression(ObjectPath(\"file\", [\"name\"]), \"$$t00rzch$$.elf\"))\n",
"ind = Indicator(name=\"Cryptotorch\", pattern_type=\"stix\", pattern=ece14)\n",
"print(ind)"
"print(ind.serialize(pretty=True))"
]
}
],
Expand All @@ -1522,7 +1522,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0a6"
"version": "3.9.2"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/serializing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
"---\n",
"**New in 3.0.0:** \n",
"\n",
"Calling `str()` on a STIX object will call `serialize()` without any formatting options. The change was made to address the performance penalty induced by unknowingly calling with the pretty formatted option. As shown above, to get effect `str()` would in the past versions of the library use the method directly and pass the pretty argument directly `serialize(pretty=True)`.\n",
"Calling `str()` on a STIX object will call `serialize()` without any formatting options. The change was made to address the performance penalty induced by unknowingly calling with the pretty formatted option. As shown above, to get the same effect as `str()` had in past versions of the library, use the method directly and pass in the pretty argument `serialize(pretty=True)`.\n",
"\n",
"---\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions stix2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def __init__(self, allow_custom=False, **kwargs):
if ext_found is False:
raise ExtraPropertiesError(cls, extra_kwargs)

# because allow_custom is true, any extra kwargs are custom
if custom_props or extra_kwargs:
self._allow_custom = True
if isinstance(self, stix2.v21._STIXBase21):
Expand All @@ -153,7 +152,8 @@ def __init__(self, allow_custom=False, **kwargs):
if missing_kwargs:
new_ext_check = (
bool(getattr(self, "extension_type", None))
) and issubclass(cls, stix2.v21._Extension)
and issubclass(cls, stix2.v21._Extension)
)
if new_ext_check is False:
raise MissingPropertiesError(cls, missing_kwargs)

Expand Down
9 changes: 6 additions & 3 deletions stix2/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,14 @@ def dict_to_stix2(stix_dict, allow_custom=False, version=None):
# be parsed into STIX object, returned as is
return stix_dict
for key_id, ext_def in stix_dict.get('extensions', {}).items():
if key_id.startswith('extension-definition--') and ext_def.get('extension_type', None):
if (
key_id.startswith('extension-definition--') and
'property-extension' not in ext_def.get('extension_type', '')
):
# prevents ParseError for unregistered objects when
# 'is_new_object' or 'is_extension_so' are set to True and allow_custom=False
# allow_custom=False and the extension defines a new object
return stix_dict
raise ParseError("Can't parse unknown object type '%s'! For custom types, use the CustomObject decorator." % stix_dict['type'])
raise ParseError("Can't parse unknown object type '%s'! For custom types, use the CustomObject decorator." % obj_type)

return obj_class(allow_custom=allow_custom, **stix_dict)

Expand Down
4 changes: 0 additions & 4 deletions stix2/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,4 @@ def class_for_type(stix_type, stix_version, category=None):
cat_map["extensions"].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.

return cls

0 comments on commit a002c17

Please sign in to comment.