Skip to content

Commit 4c0dc76

Browse files
author
Bryan Worrell
committed
Merged master into typedfields branch. A lot of stuff is broken still.
2 parents 84befae + 98932a3 commit 4c0dc76

67 files changed

Lines changed: 849 additions & 1357 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/api/utils/idgen.rst

Lines changed: 0 additions & 37 deletions
This file was deleted.

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'sphinx.ext.ifconfig',
1414
'sphinx.ext.intersphinx',
1515
'sphinx.ext.viewcode',
16-
'sphinxcontrib.napoleon',
16+
'sphinx.ext.napoleon',
1717
]
1818

1919
intersphinx_mapping = {

setup.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,22 @@ def get_version():
2525

2626
extras_require = {
2727
'docs': [
28-
'Sphinx==1.2.1',
29-
# TODO: remove when updating to Sphinx 1.3, since napoleon will be
30-
# included as sphinx.ext.napoleon
31-
'sphinxcontrib-napoleon==0.2.4',
32-
'sphinx_rtd_theme==0.1.7',
28+
'Sphinx==1.3.1',
29+
'sphinx_rtd_theme==0.1.8',
3330
],
3431
'test': [
3532
'nose==1.3.0',
3633
'tox==1.6.1',
37-
'maec>=4.1.0.12,<4.1.1.0'
34+
'maec>=4.1.0.13.dev1,<4.1.1.0',
3835
],
3936
}
4037

4138

4239
install_requires = [
4340
'lxml>=2.3',
4441
'python-dateutil',
45-
'cybox>=2.1.0.11,<2.1.1.0'
42+
'cybox>=2.1.0.13.dev0,<2.1.1.0',
43+
'mixbox>=0.0.10',
4644
]
4745

4846

stix/base.py

Lines changed: 127 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
import StringIO
99
from mixbox import fields, entities
1010

11+
from mixbox import idgen
12+
from mixbox.binding_utils import save_encoding
13+
from mixbox.cache import Cached
14+
1115
# internal
12-
from . import bindings, utils
16+
from . import utils
1317

1418
def _override(*args, **kwargs):
1519
raise NotImplementedError()
@@ -289,7 +293,7 @@ def to_xml(self, include_namespaces=True, include_schemalocs=False,
289293
if not pretty:
290294
namespace_def = namespace_def.replace('\n\t', ' ')
291295

292-
with bindings.save_encoding(encoding):
296+
with save_encoding(encoding):
293297
sio = StringIO.StringIO()
294298
obj.export(
295299
sio.write, # output buffer
@@ -785,7 +789,8 @@ def insert(self, idx, value):
785789
value = self._fix_value(value)
786790
self._inner.insert(idx, value)
787791

788-
class BaseCoreComponent(Entity):
792+
793+
class BaseCoreComponent(Cached, Entity):
789794
_ALL_VERSIONS = ()
790795
_ID_PREFIX = None
791796

@@ -810,8 +815,10 @@ def initClassFields(cls):
810815

811816
def __init__(self, id_=None, idref=None, timestamp=None, title=None,
812817
description=None, short_description=None):
818+
813819
super(BaseCoreComponent, self).__init__()
814-
self.id_ = id_ or utils.create_id(self._ID_PREFIX)
820+
821+
self.id_ = id_ or idgen.create_id(self._ID_PREFIX)
815822
self.idref = idref
816823
self.title = title
817824
self.description = description
@@ -833,35 +840,35 @@ def check_version(self, value):
833840
utils.check_version(self._ALL_VERSIONS, value)
834841
self._version = value
835842

836-
"""
837-
@property
838-
def timestamp(self):
839-
""The timestam property declares the time of creation and is
840-
automatically set in ``__init__()``.
841-
842-
This property can accept ``datetime.datetime`` or ``str`` values.
843-
If an ``str`` value is supplied, a best-effort attempt is made to
844-
parse it into an instance of ``datetime.datetime``.
845-
846-
Default Value: A ``datetime.dateime`` instance with a value of the
847-
date/time when ``__init__()`` was called.
848-
849-
Note:
850-
If an ``idref`` is set during ``__init__()``, the value of
851-
``timestamp`` will not automatically generated and instead default
852-
to the ``timestamp`` parameter, which has a default value of
853-
``None``.
854-
855-
Returns:
856-
An instance of ``datetime.datetime``.
857-
858-
""
859-
return self._timestamp
860-
861-
@timestamp.setter
862-
def timestamp(self, value):
863-
self._timestamp = utils.dates.parse_value(value)
864-
"""
843+
#
844+
# @property
845+
# def timestamp(self):
846+
# """The timestam property declares the time of creation and is
847+
# automatically set in ``__init__()``.
848+
#
849+
# This property can accept ``datetime.datetime`` or ``str`` values.
850+
# If an ``str`` value is supplied, a best-effort attempt is made to
851+
# parse it into an instance of ``datetime.datetime``.
852+
#
853+
# Default Value: A ``datetime.dateime`` instance with a value of the
854+
# date/time when ``__init__()`` was called.
855+
#
856+
# Note:
857+
# If an ``idref`` is set during ``__init__()``, the value of
858+
# ``timestamp`` will not automatically generated and instead default
859+
# to the ``timestamp`` parameter, which has a default value of
860+
# ``None``.
861+
#
862+
# Returns:
863+
# An instance of ``datetime.datetime``.
864+
#
865+
# """
866+
# return self._timestamp
867+
#
868+
# @timestamp.setter
869+
# def timestamp(self, value):
870+
# self._timestamp = utils.dates.parse_value(value)
871+
#
865872

866873
@property
867874
def description(self):
@@ -922,89 +929,90 @@ def add_short_description(self, description):
922929
"""
923930
self.short_descriptions.add(description)
924931

925-
"""
926-
@classmethod
927-
def from_obj(cls, obj, return_obj=None):
928-
from stix.common import StructuredTextList, InformationSource
929-
from stix.data_marking import Marking
930-
931-
if not return_obj:
932-
raise ValueError("Must provide a return_obj argument")
933-
934-
if not obj:
935-
raise ValueError("Must provide an obj argument")
936-
937-
return_obj.id_ = obj.id
938-
return_obj.idref = obj.idref
939-
return_obj.timestamp = obj.timestamp
940-
941-
# These may not be found on the input obj if it isn't a full
942-
# type definition (e.g., used as a reference)
943-
return_obj.version = getattr(obj, 'version', None)
944-
return_obj.title = getattr(obj, 'Title', None)
945-
return_obj.descriptions = \
946-
StructuredTextList.from_obj(getattr(obj, 'Description', None))
947-
return_obj.short_descriptions = \
948-
StructuredTextList.from_obj(getattr(obj, 'Short_Description', None))
949-
return_obj.information_source = \
950-
InformationSource.from_obj(getattr(obj, 'Information_Source', None))
951-
return_obj.handling = \
952-
Marking.from_obj(getattr(obj, 'Handling', None))
953-
954-
return return_obj
955-
956-
def to_obj(self, return_obj=None, ns_info=None):
957-
if not return_obj:
958-
raise ValueError("Must provide a return_obj argument")
959-
960-
super(BaseCoreComponent, self).to_obj(
961-
return_obj=return_obj,
962-
ns_info=ns_info
963-
)
964-
965-
return_obj.id = self.id_
966-
return_obj.idref = self.idref
967-
return_obj.version = self.version
968-
return_obj.Title = self.title
969-
970-
if self.timestamp:
971-
return_obj.timestamp = utils.dates.serialize_value(self.timestamp)
972-
if self.descriptions:
973-
return_obj.Description = self.descriptions.to_obj(ns_info=ns_info)
974-
if self.short_descriptions:
975-
return_obj.Short_Description = self.short_descriptions.to_obj(ns_info=ns_info)
976-
if self.information_source:
977-
return_obj.Information_Source = self.information_source.to_obj(ns_info=ns_info)
978-
if self.handling:
979-
return_obj.Handling = self.handling.to_obj(ns_info=ns_info)
980-
981-
return return_obj
982-
983-
@classmethod
984-
def from_dict(cls, d, return_obj=None):
985-
from stix.common import StructuredTextList, InformationSource
986-
from stix.data_marking import Marking
987-
988-
if not return_obj:
989-
raise ValueError("Must provide a return_obj argument")
990-
991-
get = d.get
992-
return_obj.id_ = get('id')
993-
return_obj.idref = get('idref')
994-
return_obj.timestamp = get('timestamp')
995-
return_obj.version = get('version')
996-
return_obj.title = get('title')
997-
return_obj.descriptions = \
998-
StructuredTextList.from_dict(get('description'))
999-
return_obj.short_descriptions = \
1000-
StructuredTextList.from_dict(get('short_description'))
1001-
return_obj.information_source = \
1002-
InformationSource.from_dict(get('information_source'))
1003-
return_obj.handling = \
1004-
Marking.from_dict(get('handling'))
1005-
1006-
return return_obj
1007-
1008-
def to_dict(self):
1009-
return super(BaseCoreComponent, self).to_dict()
1010-
"""
932+
#
933+
# @classmethod
934+
# def from_obj(cls, obj, return_obj=None):
935+
# from stix.common import StructuredTextList, InformationSource
936+
# from stix.data_marking import Marking
937+
#
938+
# if not return_obj:
939+
# raise ValueError("Must provide a return_obj argument")
940+
#
941+
# if not obj:
942+
# raise ValueError("Must provide an obj argument")
943+
#
944+
# return_obj.id_ = obj.id
945+
# return_obj.idref = obj.idref
946+
# return_obj.timestamp = obj.timestamp
947+
#
948+
# # These may not be found on the input obj if it isn't a full
949+
# # type definition (e.g., used as a reference)
950+
# return_obj.version = getattr(obj, 'version', None)
951+
# return_obj.title = getattr(obj, 'Title', None)
952+
# return_obj.descriptions = \
953+
# StructuredTextList.from_obj(getattr(obj, 'Description', None))
954+
# return_obj.short_descriptions = \
955+
# StructuredTextList.from_obj(getattr(obj, 'Short_Description', None))
956+
# return_obj.information_source = \
957+
# InformationSource.from_obj(getattr(obj, 'Information_Source', None))
958+
# return_obj.handling = \
959+
# Marking.from_obj(getattr(obj, 'Handling', None))
960+
#
961+
# return return_obj
962+
#
963+
# def to_obj(self, return_obj=None, ns_info=None):
964+
# if not return_obj:
965+
# raise ValueError("Must provide a return_obj argument")
966+
#
967+
# super(BaseCoreComponent, self).to_obj(
968+
# return_obj=return_obj,
969+
# ns_info=ns_info
970+
# )
971+
#
972+
# return_obj.id = self.id_
973+
# return_obj.idref = self.idref
974+
# return_obj.version = self.version
975+
# return_obj.Title = self.title
976+
#
977+
# if self.timestamp:
978+
# return_obj.timestamp = utils.dates.serialize_value(self.timestamp)
979+
# if self.descriptions:
980+
# return_obj.Description = self.descriptions.to_obj(ns_info=ns_info)
981+
# if self.short_descriptions:
982+
# return_obj.Short_Description = self.short_descriptions.to_obj(ns_info=ns_info)
983+
# if self.information_source:
984+
# return_obj.Information_Source = self.information_source.to_obj(ns_info=ns_info)
985+
# if self.handling:
986+
# return_obj.Handling = self.handling.to_obj(ns_info=ns_info)
987+
#
988+
# return return_obj
989+
#
990+
# @classmethod
991+
# def from_dict(cls, d, return_obj=None):
992+
# from stix.common import StructuredTextList, InformationSource
993+
# from stix.data_marking import Marking
994+
#
995+
# if not return_obj:
996+
# raise ValueError("Must provide a return_obj argument")
997+
#
998+
# get = d.get
999+
# return_obj.id_ = get('id')
1000+
# return_obj.idref = get('idref')
1001+
# return_obj.timestamp = get('timestamp')
1002+
# return_obj.version = get('version')
1003+
# return_obj.title = get('title')
1004+
# return_obj.descriptions = \
1005+
# StructuredTextList.from_dict(get('description'))
1006+
# return_obj.short_descriptions = \
1007+
# StructuredTextList.from_dict(get('short_description'))
1008+
# return_obj.information_source = \
1009+
# InformationSource.from_dict(get('information_source'))
1010+
# return_obj.handling = \
1011+
# Marking.from_dict(get('handling'))
1012+
#
1013+
# return return_obj
1014+
#
1015+
# def to_dict(self):
1016+
# return super(BaseCoreComponent, self).to_dict()
1017+
#
1018+
#

0 commit comments

Comments
 (0)