<commit_before>"""STIX 2.0 Relationship Objects."""

from .base import _STIXBase
from .common import COMMON_PROPERTIES
from .properties import (IDProperty, IntegerProperty, ListProperty,
                         ReferenceProperty, StringProperty, TimestampProperty,
                         TypeProperty)


class Relationship(_STIXBase):

    _type = 'relationship'
    _properties = COMMON_PROPERTIES.copy()
    _properties.update({
        'id': IDProperty(_type),
        'type': TypeProperty(_type),
        'relationship_type': StringProperty(required=True),
        'description': StringProperty(),
        'source_ref': ReferenceProperty(required=True),
        'target_ref': ReferenceProperty(required=True),
    })

    # Explicitly define the first three kwargs to make readable Relationship declarations.
    def __init__(self, source_ref=None, relationship_type=None, target_ref=None,
                 **kwargs):
        # TODO:
        # - description

        # Allow (source_ref, relationship_type, target_ref) as positional args.
        if source_ref and not kwargs.get('source_ref'):
            kwargs['source_ref'] = source_ref
        if relationship_type and not kwargs.get('relationship_type'):
            kwargs['relationship_type'] = relationship_type
        if target_ref and not kwargs.get('target_ref'):
            kwargs['target_ref'] = target_ref

        super(Relationship, self).__init__(**kwargs)


class Sighting(_STIXBase):
    _type = 'sighting'
    _properties = COMMON_PROPERTIES.copy()
    _properties.update({
        'id': IDProperty(_type),
        'type': TypeProperty(_type),
        'first_seen': TimestampProperty(),
        'last_seen': TimestampProperty(),
        'count': IntegerProperty(),
        'sighting_of_ref': ReferenceProperty(required=True),
        'observed_data_refs': ListProperty(ReferenceProperty(type="observed-data")),
        'where_sighted_refs': ListProperty(ReferenceProperty(type="identity")),
        'summary': StringProperty(),
    })

    # Explicitly define the first kwargs to make readable Sighting declarations.
    def __init__(self, sighting_of_ref=None, **kwargs):
        # TODO:
        # - description

        # Allow sighting_of_ref as a positional arg.
        if sighting_of_ref and not kwargs.get('sighting_of_ref'):
            kwargs['sighting_of_ref'] = sighting_of_ref

        super(Sighting, self).__init__(**kwargs)<commit_msg>Change SROs to OrderedDict approach. Removed COMMON_PROPERTIES.<commit_after>"""STIX 2.0 Relationship Objects."""

from collections import OrderedDict

from .base import _STIXBase
from .other import ExternalReference, GranularMarking
from .properties import (BooleanProperty, IDProperty, IntegerProperty, ListProperty,
                         ReferenceProperty, StringProperty, TimestampProperty,
                         TypeProperty)
from .utils import NOW


class Relationship(_STIXBase):

    _type = 'relationship'
    _properties = OrderedDict()
    _properties.update([
        ('type', TypeProperty(_type)),
        ('id', IDProperty(_type)),
        ('created_by_ref', ReferenceProperty(type="identity")),
        ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')),
        ('modified', TimestampProperty(default=lambda: NOW, precision='millisecond')),
        ('relationship_type', StringProperty(required=True)),
        ('description', StringProperty()),
        ('source_ref', ReferenceProperty(required=True)),
        ('target_ref', ReferenceProperty(required=True)),
        ('revoked', BooleanProperty()),
        ('labels', ListProperty(StringProperty)),
        ('external_references', ListProperty(ExternalReference)),
        ('object_marking_refs', ListProperty(ReferenceProperty(type="marking-definition"))),
        ('granular_markings', ListProperty(GranularMarking)),
    ])

    # Explicitly define the first three kwargs to make readable Relationship declarations.
    def __init__(self, source_ref=None, relationship_type=None,
                 target_ref=None, **kwargs):
        # Allow (source_ref, relationship_type, target_ref) as positional args.
        if source_ref and not kwargs.get('source_ref'):
            kwargs['source_ref'] = source_ref
        if relationship_type and not kwargs.get('relationship_type'):
            kwargs['relationship_type'] = relationship_type
        if target_ref and not kwargs.get('target_ref'):
            kwargs['target_ref'] = target_ref

        super(Relationship, self).__init__(**kwargs)


class Sighting(_STIXBase):
    _type = 'sighting'
    _properties = OrderedDict()
    _properties.update([
        ('id', IDProperty(_type)),
        ('type', TypeProperty(_type)),
        ('created_by_ref', ReferenceProperty(type="identity")),
        ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')),
        ('modified', TimestampProperty(default=lambda: NOW, precision='millisecond')),
        ('first_seen', TimestampProperty()),
        ('last_seen', TimestampProperty()),
        ('count', IntegerProperty()),
        ('sighting_of_ref', ReferenceProperty(required=True)),
        ('observed_data_refs', ListProperty(ReferenceProperty(type="observed-data"))),
        ('where_sighted_refs', ListProperty(ReferenceProperty(type="identity"))),
        ('summary', BooleanProperty()),
        ('revoked', BooleanProperty()),
        ('labels', ListProperty(StringProperty)),
        ('external_references', ListProperty(ExternalReference)),
        ('object_marking_refs', ListProperty(ReferenceProperty(type="marking-definition"))),
        ('granular_markings', ListProperty(GranularMarking)),
    ])

    # Explicitly define the first kwargs to make readable Sighting declarations.
    def __init__(self, sighting_of_ref=None, **kwargs):
        # Allow sighting_of_ref as a positional arg.
        if sighting_of_ref and not kwargs.get('sighting_of_ref'):
            kwargs['sighting_of_ref'] = sighting_of_ref

        super(Sighting, self).__init__(**kwargs)
{'fraction_non_alphanumeric': 0.11765682044473946, 'fraction_numerical': 0.0006637902422834385, 'mean_word_length': 3.6397228637413397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3042762', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1562, 'n_words': 343}