From 1cd92a47fc3e88be2481349371cbb11687496572 Mon Sep 17 00:00:00 2001 From: Greg Back Date: Fri, 13 Sep 2013 15:30:27 -0400 Subject: [PATCH 01/15] Bump version to 2.0.0.1 --- cybox/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cybox/__init__.py b/cybox/__init__.py index 646abf99..9cb04ed1 100644 --- a/cybox/__init__.py +++ b/cybox/__init__.py @@ -1,7 +1,7 @@ # Copyright (c) 2013, The MITRE Corporation. All rights reserved. # See LICENSE.txt for complete terms. -__version__ = "2.0.0" +__version__ = "2.0.0.1" import collections import inspect From 3467a1d133f18eb9f59e0ecb2d663a62873e22d8 Mon Sep 17 00:00:00 2001 From: bworrell Date: Thu, 19 Sep 2013 12:46:11 -0400 Subject: [PATCH 02/15] Aligned ObservabledType with CybOX v2.0.1 by adding cybox_update_version attribute support --- cybox/bindings/cybox_core.py | 64 ++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/cybox/bindings/cybox_core.py b/cybox/bindings/cybox_core.py index 21012dad..1df8abe5 100644 --- a/cybox/bindings/cybox_core.py +++ b/cybox/bindings/cybox_core.py @@ -824,21 +824,19 @@ def _cast(typ, value): class ObservablesType(GeneratedsSuper): """The ObservablesType is a type representing a collection of cyber - observables.The major_version field specifies the major version - of the CybOX language utlized for this set of Observables.The - minor_version field specifies the minor version of the CybOX - language utlized for this set of Observables.""" - member_data_items_ = { - 'cybox_minor_version': MemberSpec_('cybox_minor_version', 'xs:string', 0), - 'cybox_major_version': MemberSpec_('cybox_major_version', 'xs:string', 0), - 'Observable_Package_Source': MemberSpec_('Observable_Package_Source', 'cybox_common.MeasureSourceType', 0), - 'Observable': MemberSpec_('Observable', 'ObservableType', 1), - 'Pools': MemberSpec_('Pools', 'PoolsType', 0), - } + observables.The cybox_major_version field specifies the major + version of the CybOX language utilized for this set of + Observables.The cybox_minor_version field specifies the minor + version of the CybOX language utilized for this set of + Observables.The cybox_update_version field specifies the update + version of the CybOX language utilized for this set of + Observables. This field MUST be used when using an update + version of CybOX.""" subclass = None superclass = None - def __init__(self, cybox_minor_version=None, cybox_major_version=None, Observable_Package_Source=None, Observable=None, Pools=None): + def __init__(self, cybox_major_version="2", cybox_minor_version="0", cybox_update_version="1", Observable_Package_Source=None, Observable=None, Pools=None): self.cybox_minor_version = _cast(None, cybox_minor_version) + self.cybox_update_version = _cast(None, cybox_update_version) self.cybox_major_version = _cast(None, cybox_major_version) self.Observable_Package_Source = Observable_Package_Source if Observable is None: @@ -862,6 +860,8 @@ def get_Pools(self): return self.Pools def set_Pools(self, Pools): self.Pools = Pools def get_cybox_minor_version(self): return self.cybox_minor_version def set_cybox_minor_version(self, cybox_minor_version): self.cybox_minor_version = cybox_minor_version + def get_cybox_update_version(self): return self.cybox_update_version + def set_cybox_update_version(self, cybox_update_version): self.cybox_update_version = cybox_update_version def get_cybox_major_version(self): return self.cybox_major_version def set_cybox_major_version(self, cybox_major_version): self.cybox_major_version = cybox_major_version def hasContent_(self): @@ -873,7 +873,7 @@ def hasContent_(self): return True else: return False - def export(self, outfile, level, namespace_='cybox:', name_='Observables', namespacedef_='', pretty_print=True): + def export(self, outfile, level, namespace_='cybox:', name_='ObservablesType', namespacedef_='', pretty_print=True): if pretty_print: eol_ = '\n' else: @@ -881,7 +881,7 @@ def export(self, outfile, level, namespace_='cybox:', name_='Observables', names showIndent(outfile, level, pretty_print) outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespace_, name_='Observables') + self.exportAttributes(outfile, level, already_processed, namespace_, name_='ObservablesType') if self.hasContent_(): outfile.write('>%s' % (eol_, )) self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print) @@ -889,25 +889,28 @@ def export(self, outfile, level, namespace_='cybox:', name_='Observables', names outfile.write('%s' % (namespace_, name_, eol_)) else: outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespace_='cybox:', name_='Observables'): - if self.cybox_major_version is not None and 'cybox_major_version' not in already_processed: - already_processed.add('cybox_major_version') - outfile.write(' cybox_major_version=%s' % (self.gds_format_string(quote_attrib(self.cybox_major_version).encode(ExternalEncoding), input_name='cybox_major_version'), )) + def exportAttributes(self, outfile, level, already_processed, namespace_='cybox:', name_='ObservablesType'): if self.cybox_minor_version is not None and 'cybox_minor_version' not in already_processed: already_processed.add('cybox_minor_version') outfile.write(' cybox_minor_version=%s' % (self.gds_format_string(quote_attrib(self.cybox_minor_version).encode(ExternalEncoding), input_name='cybox_minor_version'), )) - def exportChildren(self, outfile, level, namespace_='cybox:', name_='Observables', fromsubclass_=False, pretty_print=True): + if self.cybox_update_version is not None and 'cybox_update_version' not in already_processed: + already_processed.add('cybox_update_version') + outfile.write(' cybox_update_version=%s' % (self.gds_format_string(quote_attrib(self.cybox_update_version).encode(ExternalEncoding), input_name='cybox_update_version'), )) + if self.cybox_major_version is not None and 'cybox_major_version' not in already_processed: + already_processed.add('cybox_major_version') + outfile.write(' cybox_major_version=%s' % (self.gds_format_string(quote_attrib(self.cybox_major_version).encode(ExternalEncoding), input_name='cybox_major_version'), )) + def exportChildren(self, outfile, level, namespace_='cybox:', name_='ObservablesType', fromsubclass_=False, pretty_print=True): if pretty_print: eol_ = '\n' else: eol_ = '' if self.Observable_Package_Source is not None: - self.Observable_Package_Source.export(outfile, level, 'cybox:', name_='Observable_Package_Source', pretty_print=pretty_print) + self.Observable_Package_Source.export(outfile, level, "cybox:", name_='Observable_Package_Source', pretty_print=pretty_print) for Observable_ in self.Observable: - Observable_.export(outfile, level, 'cybox:', name_='Observable', pretty_print=pretty_print) + Observable_.export(outfile, level, "cybox:", name_='Observable', pretty_print=pretty_print) if self.Pools is not None: - self.Pools.export(outfile, level, 'cybox:', name_='Pools', pretty_print=pretty_print) - def exportLiteral(self, outfile, level, name_='Observables'): + self.Pools.export(outfile, level, "cybox:", name_='Pools', pretty_print=pretty_print) + def exportLiteral(self, outfile, level, name_='ObservablesType'): level += 1 already_processed = set() self.exportLiteralAttributes(outfile, level, already_processed, name_) @@ -918,19 +921,26 @@ def exportLiteralAttributes(self, outfile, level, already_processed, name_): already_processed.add('cybox_minor_version') showIndent(outfile, level) outfile.write('cybox_minor_version = "%s",\n' % (self.cybox_minor_version,)) + if self.cybox_update_version is not None and 'cybox_update_version' not in already_processed: + already_processed.add('cybox_update_version') + showIndent(outfile, level) + outfile.write('cybox_update_version = "%s",\n' % (self.cybox_update_version,)) if self.cybox_major_version is not None and 'cybox_major_version' not in already_processed: already_processed.add('cybox_major_version') showIndent(outfile, level) outfile.write('cybox_major_version = "%s",\n' % (self.cybox_major_version,)) def exportLiteralChildren(self, outfile, level, name_): if self.Observable_Package_Source is not None: - outfile.write('Observable_Package_Source=model_.cybox_common.MeasureSourceType(\n') + showIndent(outfile, level) + outfile.write('Observable_Package_Source=model_.MeasureSourceType(\n') self.Observable_Package_Source.exportLiteral(outfile, level, name_='Observable_Package_Source') + showIndent(outfile, level) outfile.write('),\n') showIndent(outfile, level) outfile.write('Observable=[\n') level += 1 for Observable_ in self.Observable: + showIndent(outfile, level) outfile.write('model_.Observable(\n') Observable_.exportLiteral(outfile, level) showIndent(outfile, level) @@ -939,8 +949,10 @@ def exportLiteralChildren(self, outfile, level, name_): showIndent(outfile, level) outfile.write('],\n') if self.Pools is not None: + showIndent(outfile, level) outfile.write('Pools=model_.PoolsType(\n') self.Pools.exportLiteral(outfile, level, name_='Pools') + showIndent(outfile, level) outfile.write('),\n') def build(self, node): already_processed = set() @@ -953,6 +965,10 @@ def buildAttributes(self, node, attrs, already_processed): if value is not None and 'cybox_minor_version' not in already_processed: already_processed.add('cybox_minor_version') self.cybox_minor_version = value + value = find_attr_value_('cybox_update_version', node) + if value is not None and 'cybox_update_version' not in already_processed: + already_processed.add('cybox_update_version') + self.cybox_update_version = value value = find_attr_value_('cybox_major_version', node) if value is not None and 'cybox_major_version' not in already_processed: already_processed.add('cybox_major_version') From c955b1f013643fda500ee9b79e5f1953afb96055 Mon Sep 17 00:00:00 2001 From: bworrell Date: Thu, 19 Sep 2013 12:47:16 -0400 Subject: [PATCH 03/15] Aligned LinkObject with CybOX v2.0.1 by changing the URL_Label to extend StringObjectPropertyType --- cybox/bindings/link_object.py | 103 +++++++++++++++++++++++++++++----- 1 file changed, 88 insertions(+), 15 deletions(-) diff --git a/cybox/bindings/link_object.py b/cybox/bindings/link_object.py index 44b12c4d..af95fe7e 100644 --- a/cybox/bindings/link_object.py +++ b/cybox/bindings/link_object.py @@ -13,6 +13,7 @@ import re as re_ import uri_object +import cybox.bindings.cybox_common as cybox_common import base64 from datetime import datetime, tzinfo, timedelta @@ -516,13 +517,79 @@ def _cast(typ, value): # Data representation classes. # +class URLLabelType(cybox_common.StringObjectPropertyType): + member_data_items_ = {} + subclass = None + superclass = None + def __init__(self, obfuscation_algorithm_ref=None, refanging_transform_type=None, has_changed=None, pattern_type=None, datatype='string', refanging_transform=None, bit_mask=None, appears_random=None, trend=None, defanging_algorithm_ref=None, is_obfuscated=None, regex_syntax=None, apply_condition='ANY', idref=None, is_defanged=None, id=None, condition=None, valueOf_=None, extensiontype_=None): + super(URLLabelType, self).__init__(obfuscation_algorithm_ref, refanging_transform_type, has_changed, pattern_type, datatype, refanging_transform, bit_mask, appears_random, trend, defanging_algorithm_ref, is_obfuscated, regex_syntax, apply_condition, idref, is_defanged, id, condition, valueOf_, extensiontype_) + pass + def factory(*args_, **kwargs_): + if URLLabelType.subclass: + return URLLabelType.subclass(*args_, **kwargs_) + else: + return URLLabelType(*args_, **kwargs_) + factory = staticmethod(factory) + def hasContent_(self): + if ( + super(URLLabelType, self).hasContent_() + ): + return True + else: + return False + def export(self, outfile, level, namespace_='LinkObj:', name_='URL_Label', namespacedef_='', pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespace_, name_='URLLabelType') + if self.hasContent_(): + outfile.write('>') + outfile.write(unicode(self.valueOf_).encode(ExternalEncoding)) + self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print) + outfile.write('%s' % (namespace_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespace_='LinkObj:', name_='URLLabelType'): + super(URLLabelType, self).exportAttributes(outfile, level, already_processed, namespace_, name_='URLLabelType') + def exportChildren(self, outfile, level, namespace_='LinkObj:', name_='URLLabelType', fromsubclass_=False, pretty_print=True): + super(URLLabelType, self).exportChildren(outfile, level, 'LinkObj:', name_, True, pretty_print=pretty_print) + pass + def exportLiteral(self, outfile, level, name_='URLLabelType'): + level += 1 + already_processed = set() + self.exportLiteralAttributes(outfile, level, already_processed, name_) + if self.hasContent_(): + self.exportLiteralChildren(outfile, level, name_) + def exportLiteralAttributes(self, outfile, level, already_processed, name_): + super(URLLabelType, self).exportLiteralAttributes(outfile, level, already_processed, name_) + def exportLiteralChildren(self, outfile, level, name_): + super(URLLabelType, self).exportLiteralChildren(outfile, level, name_) + pass + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + self.valueOf_ = get_all_text_(node) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + def buildAttributes(self, node, attrs, already_processed): + super(URLLabelType, self).buildAttributes(node, attrs, already_processed) + pass + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + super(URLLabelType, self).buildChildren(child_, node, nodeName_, True) + pass +# End URLLabelType + class LinkObjectType(uri_object.URIObjectType): - member_data_items_ = { - 'URL_Label': MemberSpec_('URL_Label', 'xs:string', 0), - } + """The Link Object is intended to characterize links, such as those on + a webpage or in an e-mail message.""" subclass = None superclass = uri_object.URIObjectType - def __init__(self, object_reference=None, Custom_Properties=None, xsi_type=None, type_=None, Value=None, URL_Label=None): + def __init__(self, object_reference=None, Custom_Properties=None, type_=None, Value=None, URL_Label=None): super(LinkObjectType, self).__init__(object_reference, Custom_Properties, type_, Value, ) self.URL_Label = URL_Label def factory(*args_, **kwargs_): @@ -533,6 +600,9 @@ def factory(*args_, **kwargs_): factory = staticmethod(factory) def get_URL_Label(self): return self.URL_Label def set_URL_Label(self, URL_Label): self.URL_Label = URL_Label + def validate_StringObjectPropertyType(self, value): + # Validate type StringObjectPropertyType, a restriction on None. + pass def hasContent_(self): if ( self.URL_Label is not None or @@ -547,18 +617,18 @@ def export(self, outfile, level, namespace_='LinkObj:', name_='LinkObjectType', else: eol_ = '' showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + outfile.write('<%s%s%s' % ('LinkObj:', name_, namespacedef_ and ' ' + namespacedef_ or '', )) already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespace_, name_='LinkObjectType') + self.exportAttributes(outfile, level, already_processed, 'LinkObj:', name_='LinkObjectType') if self.hasContent_(): outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print) + self.exportChildren(outfile, level + 1, 'LinkObj:', name_, pretty_print=pretty_print) showIndent(outfile, level, pretty_print) - outfile.write('%s' % (namespace_, name_, eol_)) + outfile.write('%s' % ('LinkObj:', name_, eol_)) else: outfile.write('/>%s' % (eol_, )) def exportAttributes(self, outfile, level, already_processed, namespace_='LinkObj:', name_='LinkObjectType'): - super(LinkObjectType, self).exportAttributes(outfile, level, already_processed, namespace_, name_='LinkObjectType') + super(LinkObjectType, self).exportAttributes(outfile, level, already_processed, 'LinkObj:', name_='LinkObjectType') def exportChildren(self, outfile, level, namespace_='LinkObj:', name_='LinkObjectType', fromsubclass_=False, pretty_print=True): super(LinkObjectType, self).exportChildren(outfile, level, 'LinkObj:', name_, True, pretty_print=pretty_print) if pretty_print: @@ -566,8 +636,7 @@ def exportChildren(self, outfile, level, namespace_='LinkObj:', name_='LinkObjec else: eol_ = '' if self.URL_Label is not None: - showIndent(outfile, level, pretty_print) - outfile.write('<%sURL_Label>%s%s' % ('LinkObj:', self.gds_format_string(quote_xml(self.URL_Label).encode(ExternalEncoding), input_name='URL_Label'), 'LinkObj:', eol_)) + self.URL_Label.export(outfile, level, 'LinkObj:', name_='URL_Label', pretty_print=pretty_print) def exportLiteral(self, outfile, level, name_='LinkObjectType'): level += 1 already_processed = set() @@ -580,7 +649,10 @@ def exportLiteralChildren(self, outfile, level, name_): super(LinkObjectType, self).exportLiteralChildren(outfile, level, name_) if self.URL_Label is not None: showIndent(outfile, level) - outfile.write('URL_Label=%s,\n' % quote_python(self.URL_Label).encode(ExternalEncoding)) + outfile.write('URL_Label=model_.StringObjectPropertyType(\n') + self.URL_Label.exportLiteral(outfile, level, name_='URL_Label') + showIndent(outfile, level) + outfile.write('),\n') def build(self, node): already_processed = set() self.buildAttributes(node, node.attrib, already_processed) @@ -591,10 +663,11 @@ def buildAttributes(self, node, attrs, already_processed): super(LinkObjectType, self).buildAttributes(node, attrs, already_processed) def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): if nodeName_ == 'URL_Label': - URL_Label_ = child_.text - URL_Label_ = self.gds_validate_string(URL_Label_, node, 'URL_Label') - self.URL_Label = URL_Label_ + obj_ = URLLabelType.factory() + obj_.build(child_) + self.set_URL_Label(obj_) super(LinkObjectType, self).buildChildren(child_, node, nodeName_, True) + # end class LinkObjectType GDSClassesMapping = { From 73a8b290ee76d5bce2763c27f55ecbefccf0d17e Mon Sep 17 00:00:00 2001 From: bworrell Date: Fri, 20 Sep 2013 09:14:05 -0400 Subject: [PATCH 04/15] removed outdated docstrings from binding classes --- cybox/bindings/cybox_common.py | 340 ++------------------------------- 1 file changed, 17 insertions(+), 323 deletions(-) diff --git a/cybox/bindings/cybox_common.py b/cybox/bindings/cybox_common.py index 6452bf66..9837c5a5 100644 --- a/cybox/bindings/cybox_common.py +++ b/cybox/bindings/cybox_common.py @@ -4243,18 +4243,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class CustomPropertiesType class BaseObjectPropertyType(GeneratedsSuper): - """The BaseObjectPropertyType is a type representing a common typing - foundation for the specification of a single Object - Property.Properties that use this type can express multiple - values by providing them using a comma separated list. As such, - a comma is a reserved character in all uses of this type. Commas - in values should be expressed as , (that is, - ampersand-"comma"-semicolon). Such expressions should be - converted back to a comma before displaying to users or handing - off values to tools for processing. Note that whitespace is - preserved and so, when specifying a list of values, do not - include a space following a comma in a list unless the first - character of the next list item should, in fact, be a space.""" + member_data_items_ = { 'obfuscation_algorithm_ref': MemberSpec_('obfuscation_algorithm_ref', 'xs:anyURI', 0), 'refanging_transform_type': MemberSpec_('refanging_transform_type', 'xs:string', 0), @@ -4614,23 +4603,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class BaseObjectPropertyType class IntegerObjectPropertyType(BaseObjectPropertyType): - """The IntegerObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type Int. This - type will be assigned to any property of a CybOX object that - should contain content of type Integer and enables the use of - relevant metadata for the property.Properties that use this type - can express multiple values by providing them using a comma - separated list. As such, a comma is a reserved character in all - uses of this type. Commas in values should be expressed as - , (that is, ampersand-"comma"-semicolon). Such expressions - should be converted back to a comma before displaying to users - or handing off values to tools for processing. Note that - whitespace is preserved and so, when specifying a list of - values, do not include a space following a comma in a list - unless the first character of the next list item should, in - fact, be a space.This attribute is optional and specifies the - expected type for the value of the specified property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['IntegerObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -4718,23 +4691,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class IntegerObjectPropertyType class StringObjectPropertyType(BaseObjectPropertyType): - """The StringObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type String. This - type will be assigned to any property of a CybOX object that - should contain content of type String and enables the use of - relevant metadata for the property.Properties that use this type - can express multiple values by providing them using a comma - separated list. As such, a comma is a reserved character in all - uses of this type. Commas in values should be expressed as - , (that is, ampersand-"comma"-semicolon). Such expressions - should be converted back to a comma before displaying to users - or handing off values to tools for processing. Note that - whitespace is preserved and so, when specifying a list of - values, do not include a space following a comma in a list - unless the first character of the next list item should, in - fact, be a space.This attribute is optional and specifies the - expected type for the value of the specified property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['StringObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -4833,23 +4790,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class StringObjectPropertyType class NameObjectPropertyType(BaseObjectPropertyType): - """The NameObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type Name. This - type will be assigned to any property of a CybOX object that - should contain content of type Name and enables the use of - relevant metadata for the property.Properties that use this type - can express multiple values by providing them using a comma - separated list. As such, a comma is a reserved character in all - uses of this type. Commas in values should be expressed as - , (that is, ampersand-"comma"-semicolon). Such expressions - should be converted back to a comma before displaying to users - or handing off values to tools for processing. Note that - whitespace is preserved and so, when specifying a list of - values, do not include a space following a comma in a list - unless the first character of the next list item should, in - fact, be a space.This attribute is optional and specifies the - expected type for the value of the specified property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['NameObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -4937,23 +4878,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class NameObjectPropertyType class DateObjectPropertyType(BaseObjectPropertyType): - """The DateObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type Date. This - type will be assigned to any property of a CybOX object that - should contain content of type Date and enables the use of - relevant metadata for the property.Properties that use this type - can express multiple values by providing them using a comma - separated list. As such, a comma is a reserved character in all - uses of this type. Commas in values should be expressed as - , (that is, ampersand-"comma"-semicolon). Such expressions - should be converted back to a comma before displaying to users - or handing off values to tools for processing. Note that - whitespace is preserved and so, when specifying a list of - values, do not include a space following a comma in a list - unless the first character of the next list item should, in - fact, be a space.This attribute is optional and specifies the - expected type for the value of the specified property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['DateObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -5041,23 +4966,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class DateObjectPropertyType class DateTimeObjectPropertyType(BaseObjectPropertyType): - """The DateTimeObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type DateTime. - This type will be assigned to any property of a CybOX object - that should contain content of type DateTime and enables the use - of relevant metadata for the property.Properties that use this - type can express multiple values by providing them using a comma - separated list. As such, a comma is a reserved character in all - uses of this type. Commas in values should be expressed as - , (that is, ampersand-"comma"-semicolon). Such expressions - should be converted back to a comma before displaying to users - or handing off values to tools for processing. Note that - whitespace is preserved and so, when specifying a list of - values, do not include a space following a comma in a list - unless the first character of the next list item should, in - fact, be a space.This attribute is optional and specifies the - expected type for the value of the specified property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['DateTimeObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -5145,23 +5054,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class DateTimeObjectPropertyType class FloatObjectPropertyType(BaseObjectPropertyType): - """The FloatObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type Float. This - type will be assigned to any property of a CybOX object that - should contain content of type Float and enables the use of - relevant metadata for the property.Properties that use this type - can express multiple values by providing them using a comma - separated list. As such, a comma is a reserved character in all - uses of this type. Commas in values should be expressed as - , (that is, ampersand-"comma"-semicolon). Such expressions - should be converted back to a comma before displaying to users - or handing off values to tools for processing. Note that - whitespace is preserved and so, when specifying a list of - values, do not include a space following a comma in a list - unless the first character of the next list item should, in - fact, be a space.This attribute is optional and specifies the - expected type for the value of the specified property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['FloatObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -5251,23 +5144,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class FloatObjectPropertyType class DoubleObjectPropertyType(BaseObjectPropertyType): - """The DoubleObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type Double. This - type will be assigned to any property of a CybOX object that - should contain content of type Double and enables the use of - relevant metadata for the property.Properties that use this type - can express multiple values by providing them using a comma - separated list. As such, a comma is a reserved character in all - uses of this type. Commas in values should be expressed as - , (that is, ampersand-"comma"-semicolon). Such expressions - should be converted back to a comma before displaying to users - or handing off values to tools for processing. Note that - whitespace is preserved and so, when specifying a list of - values, do not include a space following a comma in a list - unless the first character of the next list item should, in - fact, be a space.This attribute is optional and specifies the - expected type for the value of the specified property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['DoubleObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -5357,24 +5234,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class DoubleObjectPropertyType class UnsignedLongObjectPropertyType(BaseObjectPropertyType): - """The UnsignedLongObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type UnsignedLong. - This type will be assigned to any property of a CybOX object - that should contain content of type UnsignedLong and enables the - use of relevant metadata for the property.Properties that use - this type can express multiple values by providing them using a - comma separated list. As such, a comma is a reserved character - in all uses of this type. Commas in values should be expressed - as , (that is, ampersand-"comma"-semicolon). Such - expressions should be converted back to a comma before - displaying to users or handing off values to tools for - processing. Note that whitespace is preserved and so, when - specifying a list of values, do not include a space following a - comma in a list unless the first character of the next list item - should, in fact, be a space.This attribute is optional and - specifies the expected type for the value of the specified - property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['UnsignedLongObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -5462,24 +5322,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class UnsignedLongObjectPropertyType class UnsignedIntegerObjectPropertyType(BaseObjectPropertyType): - """The UnsignedIntegerObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type UnsignedInt. - This type will be assigned to any property of a CybOX object - that should contain content of type UnsignedInteger and enables - the use of relevant metadata for the property.Properties that - use this type can express multiple values by providing them - using a comma separated list. As such, a comma is a reserved - character in all uses of this type. Commas in values should be - expressed as , (that is, ampersand-"comma"-semicolon). - Such expressions should be converted back to a comma before - displaying to users or handing off values to tools for - processing. Note that whitespace is preserved and so, when - specifying a list of values, do not include a space following a - comma in a list unless the first character of the next list item - should, in fact, be a space.This attribute is optional and - specifies the expected type for the value of the specified - property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['UnsignedIntegerObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -5567,24 +5410,6 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class UnsignedIntegerObjectPropertyType class PositiveIntegerObjectPropertyType(BaseObjectPropertyType): - """The PositiveIntegerObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type - PositveInteger. This type will be assigned to any property of a - CybOX object that should contain content of type PositiveInteger - and enables the use of relevant metadata for the - property.Properties that use this type can express multiple - values by providing them using a comma separated list. As such, - a comma is a reserved character in all uses of this type. Commas - in values should be expressed as , (that is, - ampersand-"comma"-semicolon). Such expressions should be - converted back to a comma before displaying to users or handing - off values to tools for processing. Note that whitespace is - preserved and so, when specifying a list of values, do not - include a space following a comma in a list unless the first - character of the next list item should, in fact, be a space.This - attribute is optional and specifies the expected type for the - value of the specified property.""" member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['PositiveIntegerObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -5672,24 +5497,6 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class PositiveIntegerObjectPropertyType class HexBinaryObjectPropertyType(BaseObjectPropertyType): - """The HexBinaryObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type HexBinary. - This type will be assigned to any property of a CybOX object - that should contain content of type HexBinary and enables the - use of relevant metadata for the property.Properties that use - this type can express multiple values by providing them using a - comma separated list. As such, a comma is a reserved character - in all uses of this type. Commas in values should be expressed - as , (that is, ampersand-"comma"-semicolon). Such - expressions should be converted back to a comma before - displaying to users or handing off values to tools for - processing. Note that whitespace is preserved and so, when - specifying a list of values, do not include a space following a - comma in a list unless the first character of the next list item - should, in fact, be a space.This attribute is optional and - specifies the expected type for the value of the specified - property.""" member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['HexBinaryObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -5788,23 +5595,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class HexBinaryObjectPropertyType class LongObjectPropertyType(BaseObjectPropertyType): - """The LongObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type Long. This - type will be assigned to any property of a CybOX object that - should contain content of type Long and enables the use of - relevant metadata for the property.Properties that use this type - can express multiple values by providing them using a comma - separated list. As such, a comma is a reserved character in all - uses of this type. Commas in values should be expressed as - , (that is, ampersand-"comma"-semicolon). Such expressions - should be converted back to a comma before displaying to users - or handing off values to tools for processing. Note that - whitespace is preserved and so, when specifying a list of - values, do not include a space following a comma in a list - unless the first character of the next list item should, in - fact, be a space.This attribute is optional and specifies the - expected type for the value of the specified property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['LongObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -5892,24 +5683,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class LongObjectPropertyType class NonNegativeIntegerObjectPropertyType(BaseObjectPropertyType): - """The NonNegativeIntegerObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type - nonNegativeInteger. This type will be assigned to any property - of a CybOX object that should contain content of type - NonNegativeInteger and enables the use of relevant metadata for - the property.Properties that use this type can express multiple - values by providing them using a comma separated list. As such, - a comma is a reserved character in all uses of this type. Commas - in values should be expressed as , (that is, - ampersand-"comma"-semicolon). Such expressions should be - converted back to a comma before displaying to users or handing - off values to tools for processing. Note that whitespace is - preserved and so, when specifying a list of values, do not - include a space following a comma in a list unless the first - character of the next list item should, in fact, be a space.This - attribute is optional and specifies the expected type for the - value of the specified property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['NonNegativeIntegerObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -5997,23 +5771,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class NonNegativeIntegerObjectPropertyType class AnyURIObjectPropertyType(BaseObjectPropertyType): - """The AnyURIObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type anyURI. This - type will be assigned to any property of a CybOX object that - should contain content of type AnyURI and enables the use of - relevant metadata for the property.Properties that use this type - can express multiple values by providing them using a comma - separated list. As such, a comma is a reserved character in all - uses of this type. Commas in values should be expressed as - , (that is, ampersand-"comma"-semicolon). Such expressions - should be converted back to a comma before displaying to users - or handing off values to tools for processing. Note that - whitespace is preserved and so, when specifying a list of - values, do not include a space following a comma in a list - unless the first character of the next list item should, in - fact, be a space.This attribute is optional and specifies the - expected type for the value of the specified property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['AnyURIObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -6101,23 +5859,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class AnyURIObjectPropertyType class DurationObjectPropertyType(BaseObjectPropertyType): - """The DurationObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type duration. - This type will be assigned to any property of a CybOX object - that should contain content of type Duration and enables the use - of relevant metadata for the property.Properties that use this - type can express multiple values by providing them using a comma - separated list. As such, a comma is a reserved character in all - uses of this type. Commas in values should be expressed as - , (that is, ampersand-"comma"-semicolon). Such expressions - should be converted back to a comma before displaying to users - or handing off values to tools for processing. Note that - whitespace is preserved and so, when specifying a list of - values, do not include a space following a comma in a list - unless the first character of the next list item should, in - fact, be a space.This attribute is optional and specifies the - expected type for the value of the specified property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['DurationObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -6205,23 +5947,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class DurationObjectPropertyType class TimeObjectPropertyType(BaseObjectPropertyType): - """The TimeObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type time. This - type will be assigned to any property of a CybOX object that - should contain content of type Time and enables the use of - relevant metadata for the property.Properties that use this type - can express multiple values by providing them using a comma - separated list. As such, a comma is a reserved character in all - uses of this type. Commas in values should be expressed as - , (that is, ampersand-"comma"-semicolon). Such expressions - should be converted back to a comma before displaying to users - or handing off values to tools for processing. Note that - whitespace is preserved and so, when specifying a list of - values, do not include a space following a comma in a list - unless the first character of the next list item should, in - fact, be a space.This attribute is optional and specifies the - expected type for the value of the specified property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['TimeObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -6309,24 +6035,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class TimeObjectPropertyType class Base64BinaryObjectPropertyType(BaseObjectPropertyType): - """The Base64BinaryObjectPropertyType is a type (extended from - BaseObjectPropertyType) representing the specification of a - single Object property whose core value is of type base64Binary. - This type will be assigned to any property of a CybOX object - that should contain content of type Base64Binary and enables the - use of relevant metadata for the property.Properties that use - this type can express multiple values by providing them using a - comma separated list. As such, a comma is a reserved character - in all uses of this type. Commas in values should be expressed - as , (that is, ampersand-"comma"-semicolon). Such - expressions should be converted back to a comma before - displaying to users or handing off values to tools for - processing. Note that whitespace is preserved and so, when - specifying a list of values, do not include a space following a - comma in a list unless the first character of the next list item - should, in fact, be a space.This attribute is optional and - specifies the expected type for the value of the specified - property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['Base64BinaryObjectPropertyType', 'BaseObjectPropertyType'], 0), @@ -9992,22 +9701,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): # end class ControlledVocabularyStringType class SIDType(BaseObjectPropertyType): - """SIDType specifies Windows Security ID (SID) types via a union of the - SIDTypeEnum type and the atomic xs:string type. Its base type is - the CybOX Core BaseObjectPropertyType, for permitting complex - (i.e. regular-expression based) specifications.Properties that - use this type can express multiple values by providing them - using a comma separated list. As such, a comma is a reserved - character in all uses of this type. Commas in values should be - expressed as , (that is, ampersand-"comma"-semicolon). - Such expressions should be converted back to a comma before - displaying to users or handing off values to tools for - processing. Note that whitespace is preserved and so, when - specifying a list of values, do not include a space following a - comma in a list unless the first character of the next list item - should, in fact, be a space.This attribute is optional and - specifies the expected type for the value of the specified - property.""" + member_data_items_ = { 'datatype': MemberSpec_('datatype', 'cyboxCommon:DatatypeEnum', 0), 'valueOf_': MemberSpec_('valueOf_', ['SIDType', 'BaseObjectPropertyType'], 0), From 0c8a3e7d210e074fd88bf9b6d73f781edf069bc0 Mon Sep 17 00:00:00 2001 From: bworrell Date: Fri, 20 Sep 2013 09:15:08 -0400 Subject: [PATCH 05/15] Updated property list handling code and unit tests --- cybox/test/utils_test.py | 16 +++++----------- cybox/utils/__init__.py | 30 +++++++++++++----------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/cybox/test/utils_test.py b/cybox/test/utils_test.py index 2ae85dd7..6ab6bda7 100644 --- a/cybox/test/utils_test.py +++ b/cybox/test/utils_test.py @@ -106,16 +106,11 @@ def test_missing_class(self): class NormalizationTest(unittest.TestCase): def test_encode_decode_lists(self): - a = "A long, long, time ago" - b = "A long, long, time ago" - c = ["A long", "long", "time ago"] - d = "A long,long,time ago" + a = "A long##comma##long##comma##time ago" + b = ["A long", "long", "time ago"] - self.assertEqual(cybox.utils.normalize_to_xml(a), - cybox.utils.wrap_cdata(b)) - self.assertEqual(cybox.utils.normalize_to_xml(c), d) - self.assertEqual(cybox.utils.denormalize_from_xml(a), c) - self.assertEqual(cybox.utils.denormalize_from_xml(b), a) + self.assertEqual(cybox.utils.denormalize_from_xml(a), b) + self.assertEqual(cybox.utils.normalize_to_xml(b), a) def test_email_address(self): escaped = "<jsmith@example.com>" @@ -123,8 +118,7 @@ def test_email_address(self): self._test_escape_unescape(escaped, unescaped) def test_subject(self): - escaped = cybox.utils.wrap_cdata( - "Oh, the perils of <script> & <frame>") + escaped = "Oh, the perils of <script> & <frame>" unescaped = "Oh, the perils of