Commit Graph

14 Commits (631460f45f83a7b50b7db221c60edaa9c0cc89d5)

Author SHA1 Message Date
Michael Chisholm 473e7d0068 Change versioning module to use some of the is_* utility
functions.  Changed some ">= 2.1" stix version semantics to be
"== 2.1", because we don't have any version >= 2.1, so they are
currently equivalent, and the is_*() functions don't support
STIX version ranges.  They only support exact versions.  We can
look at this again if a newer STIX version ever emerges.

Also added a class_for_type() function to the registry module,
which was useful for the versioning module changes described
above.  I thought that function would be helpful in the parsing
module, to simplify code there, so I changed that module a bit
to use it.
2021-01-20 16:59:39 -05:00
Michael Chisholm fe2330af07 Improve is_sdo() et al utility functions with respect to
dict/mapping values: do a simple verification of the value's
STIX version, not just its type.  Added a lot more unit tests to
test behavior on dicts.  To make the implementation work, I had
to move the detect_spec_version() function out of the parsing
module and into utils.  So that required small changes at all
its previous call sites.
2021-01-20 16:59:39 -05:00
Michael Chisholm f8c86f7352 Fixups after a rebase. There were several conflict resolutions
and I probably forgot some stuff...
2021-01-20 16:59:39 -05:00
Michael Chisholm f88fba6751 Change the stix2 class map structure to be keyed at the top
level with STIX versions in the same format as is used everywhere
else in the API: "X.Y", as opposed to the "vXY" format used by
the version-specific python packages.  This eliminates all of
the awkward conversion from public API format to "vXX" format.

Also a little bit of code rearranging in the registration module
to ensure that some STIX 2.1-specific checks are done whether
version 2.1 is given explicitly or is defaulted to.

In the same module I also added a missing import of
stix2.properties, since my IDE was claiming it could not find a
function from that module.
2021-01-20 16:59:38 -05:00
Chris Lenk a0d535336e Merge 'master' and fix imports for consistency 2021-01-15 12:34:10 -05:00
Chris Lenk a3f20dde7a Use consistent import style in parsing.py 2021-01-15 10:27:23 -05:00
Emmanuelle Vargas-Gonzalez 85c14d1502 all changes from add-trailing-commas v2.0.2 2021-01-13 17:52:15 -05:00
Michael Chisholm f51e309775 Refactor stix2.parsing into more focused modules:
- stix2.registry, which contains the class mapping structure
  and code for scanning stix2 modules for its initial population
- stix2.registration, which contains code used to register custom
  STIX types with the registry
- stix2.parsing, which contains code for creating instances of
  registered stix2 classes from raw dicts.

This is intended to reduce circular import problems, by giving
dependent code the ability to import a module which has exactly
the functionality it needs, without pulling a lot of other stuff
it doesn't need.  Fewer imports means less chance of an import
cycle.
2021-01-08 22:08:33 -05:00
Emmanuelle Vargas-Gonzalez 7ef3a02971 update docstrings environment.py and parsing.py 2020-06-30 22:32:04 -04:00
Chris Lenk 14540c0ea1 Clean up _register_* functions
Made them consistent with _register_observable_extension, by:
- moving validation logic there from _custom_*_builder functions
- using a new function for ensuring properties are dict-like
- using the library default spec version instead of None

Fix #371, fix #372, fix #373.
2020-04-02 14:15:45 -04:00
Chris Lenk 13cddf9d6d Move TypeProperty format checks to __init__
TypeProperty uses a fixed value, so check() was never called. This way
also runs the check at object registration time because the wrapper
creates an instance of TypeProperty and doesn't have to wait for the
object to be instantiated so clean() can be called.
Also fix some tests.
2020-04-02 08:17:34 -04:00
Chris Lenk 03cb225932 Merge branch 'master' into 365-versioned-classes 2020-04-02 06:02:20 -04:00
Chris Lenk c494a2e477 Use TypeProperty.clean() to verify type format 2020-04-01 21:52:04 -04:00
Chris Lenk 50df6f1474 Rename core.py -> parsing.py 2020-03-27 05:53:39 -04:00