[WIP] Touch up marking code

stix2.1
clenk 2017-08-18 12:36:34 -04:00
parent 14b922ba92
commit c0d02fbfcd
5 changed files with 26 additions and 18 deletions

View File

@ -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__)

View File

@ -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):

View File

@ -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.

View File

@ -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,

View File

@ -1,8 +1,8 @@
from stix2 import markings
import pytest
from stix2 import markings
"""Tests for the Data Markings API."""