From c0d02fbfcd61668615327bd250e5822446fb5006 Mon Sep 17 00:00:00 2001 From: clenk Date: Fri, 18 Aug 2017 12:36:34 -0400 Subject: [PATCH] [WIP] Touch up marking code --- stix2/exceptions.py | 17 +++++++++++++++-- stix2/markings/__init__.py | 4 +--- stix2/markings/granular_markings.py | 6 +++--- stix2/test/test_granular_markings.py | 13 +++++-------- stix2/test/test_object_markings.py | 4 ++-- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/stix2/exceptions.py b/stix2/exceptions.py index 708233a..864dec8 100644 --- a/stix2/exceptions.py +++ b/stix2/exceptions.py @@ -172,14 +172,27 @@ class InvalidSelectorError(STIXError, ValueError): return msg.format(self.key, self.__class__.__name__) -class DuplicateMarkingError(STIXError, ValueError): +class InvalidMarkingError(STIXError, ValueError): """Marking violation. The marking reference must be a valid identifier.""" + def __init__(self, cls, key): + super(InvalidMarkingError, self).__init__() + self.cls = cls + self.key = key + + def __str__(self): + msg = "Marking '{0}' in '{1}' is not a valid marking reference." + return msg.format(self.key, self.__class__.__name__) + + +class DuplicateMarkingError(STIXError, ValueError): + """Marking violation. The marking reference is a duplicate.""" + def __init__(self, cls, key): super(DuplicateMarkingError, self).__init__() self.cls = cls self.key = key def __str__(self): - msg = "Marking '{0}' in '{1}' is not a valid marking reference." + msg = "Marking '{0}' in '{1}' is a duplicate marking reference." return msg.format(self.key, self.__class__.__name__) diff --git a/stix2/markings/__init__.py b/stix2/markings/__init__.py index 14d21bb..f543f34 100644 --- a/stix2/markings/__init__.py +++ b/stix2/markings/__init__.py @@ -5,9 +5,7 @@ These high level functions will operate on both object level markings and granular markings unless otherwise noted in each of the functions. """ -from stix2.markings import utils -from stix2.markings import granular_markings -from stix2.markings import object_markings +from stix2.markings import granular_markings, object_markings def get_markings(obj, selectors, inherited=False, descendants=False): diff --git a/stix2/markings/granular_markings.py b/stix2/markings/granular_markings.py index 6d69f16..903aae9 100644 --- a/stix2/markings/granular_markings.py +++ b/stix2/markings/granular_markings.py @@ -8,7 +8,7 @@ def get_markings(obj, selectors, inherited=False, descendants=False): Args: obj: A TLO object. - selectors: string or list of selectors strings relative to the TLO in + selectors: string or list of selector strings relative to the TLO in which the field(s) appear(s). inherited: If True, include markings inherited relative to the field(s). descendants: If True, include granular markings applied to any children @@ -47,7 +47,7 @@ def set_markings(obj, selectors, marking): Args: obj: A TLO object. - selectors: string or list of selectors strings relative to the TLO in + selectors: string or list of selector strings relative to the TLO in which the field(s) appear(s). marking: identifier or list of marking identifiers that apply to the field(s) selected by `selectors`. @@ -134,7 +134,7 @@ def add_markings(obj, selectors, marking): def clear_markings(obj, selectors): """ - Removes all granular_marking associated with the selectors. + Removes all granular_markings associated with the selectors. Args: obj: A TLO object. diff --git a/stix2/test/test_granular_markings.py b/stix2/test/test_granular_markings.py index da53ce1..f38c0dd 100644 --- a/stix2/test/test_granular_markings.py +++ b/stix2/test/test_granular_markings.py @@ -1,8 +1,8 @@ -from stix2 import markings - import pytest +from stix2 import markings + """Tests for the Data Markings API.""" @@ -141,8 +141,7 @@ def test_add_marking_bad_selector(data, marking): markings.add_markings(data, marking[0], marking[1]) -GET_MARKINGS_TEST_DATA = \ -{ +GET_MARKINGS_TEST_DATA = { "a": 333, "b": "value", "c": [ @@ -510,8 +509,7 @@ def test_remove_marking_bad_selector(): markings.remove_markings(before, ["title"], ["marking-definition--1", "marking-definition--2"]) -IS_MARKED_TEST_DATA = \ -{ +IS_MARKED_TEST_DATA = { "title": "test title", "description": "test description", "revision": 2, @@ -905,8 +903,7 @@ def test_set_marking_mark_same_property_same_marking(): assert before == after -CLEAR_MARKINGS_TEST_DATA = \ -{ +CLEAR_MARKINGS_TEST_DATA = { "title": "test title", "description": "test description", "revision": 2, diff --git a/stix2/test/test_object_markings.py b/stix2/test/test_object_markings.py index 5205ad7..15f35a4 100644 --- a/stix2/test/test_object_markings.py +++ b/stix2/test/test_object_markings.py @@ -1,8 +1,8 @@ -from stix2 import markings - import pytest +from stix2 import markings + """Tests for the Data Markings API."""