1# Copyright (c) 2017, The MITRE Corporation. All rights reserved.
2# See LICENSE.txt for complete terms.
3
4#!/usr/bin/env python
5# -*- coding: utf-8 -*-
6
7#
8# Generated Thu Apr 11 15:06:29 2013 by generateDS.py version 2.9a.
9#
10
11import sys
12
13from mixbox.binding_utils import *
14
15from stix.bindings import lookup_extension, register_extension
16import stix.bindings.stix_common as stix_common_binding
17import stix.bindings.data_marking as data_marking_binding
18
19XML_NS = "http://stix.mitre.org/ThreatActor-1"
20
21
22#
23# Data representation classes.
24#
25
26class ObservedTTPsType(stix_common_binding.GenericRelationshipListType):
27    subclass = None
28    superclass = stix_common_binding.GenericRelationshipListType
29    def __init__(self, scope='exclusive', Observed_TTP=None):
30        super(ObservedTTPsType, self).__init__(scope=scope)
31        if Observed_TTP is None:
32            self.Observed_TTP = []
33        else:
34            self.Observed_TTP = Observed_TTP
35    def factory(*args_, **kwargs_):
36        if ObservedTTPsType.subclass:
37            return ObservedTTPsType.subclass(*args_, **kwargs_)
38        else:
39            return ObservedTTPsType(*args_, **kwargs_)
40    factory = staticmethod(factory)
41    def get_Observed_TTP(self): return self.Observed_TTP
42    def set_Observed_TTP(self, Observed_TTP): self.Observed_TTP = Observed_TTP
43    def add_Observed_TTP(self, value): self.Observed_TTP.append(value)
44    def insert_Observed_TTP(self, index, value): self.Observed_TTP[index] = value
45    def hasContent_(self):
46        if (
47            self.Observed_TTP or
48            super(ObservedTTPsType, self).hasContent_()
49            ):
50            return True
51        else:
52            return False
53    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='ObservedTTPsType', namespacedef_='', pretty_print=True):
54        if pretty_print:
55            eol_ = '\n'
56        else:
57            eol_ = ''
58        showIndent(lwrite, level, pretty_print)
59        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
60        already_processed = set()
61        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='ObservedTTPsType')
62        if self.hasContent_():
63            lwrite('>%s' % (eol_, ))
64            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
65            showIndent(lwrite, level, pretty_print)
66            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
67        else:
68            lwrite('/>%s' % (eol_, ))
69    def exportAttributes(self, lwrite, level, already_processed, namespace_='ta:', name_='ObservedTTPsType'):
70        super(ObservedTTPsType, self).exportAttributes(lwrite, level, already_processed, namespace_, name_='ObservedTTPsType')
71    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='ObservedTTPsType', fromsubclass_=False, pretty_print=True):
72        super(ObservedTTPsType, self).exportChildren(lwrite, level, nsmap, namespace_, name_, True, pretty_print=pretty_print)
73        if pretty_print:
74            eol_ = '\n'
75        else:
76            eol_ = ''
77        for Observed_TTP_ in self.Observed_TTP:
78            Observed_TTP_.export(lwrite, level, nsmap, namespace_, name_='Observed_TTP', pretty_print=pretty_print)
79    def build(self, node):
80        self.__sourcenode__ = node
81        already_processed = set()
82        self.buildAttributes(node, node.attrib, already_processed)
83        for child in node:
84            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
85            self.buildChildren(child, node, nodeName_)
86    def buildAttributes(self, node, attrs, already_processed):
87        super(ObservedTTPsType, self).buildAttributes(node, attrs, already_processed)
88    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
89        if nodeName_ == 'Observed_TTP':
90            obj_ = stix_common_binding.RelatedTTPType.factory()
91            obj_.build(child_)
92            self.Observed_TTP.append(obj_)
93        super(ObservedTTPsType, self).buildChildren(child_, node, nodeName_, True)
94# end class ObservedTTPsType
95
96class AssociatedCampaignsType(stix_common_binding.GenericRelationshipListType):
97    subclass = None
98    superclass = stix_common_binding.GenericRelationshipListType
99    def __init__(self, scope='exclusive', Associated_Campaign=None):
100        super(AssociatedCampaignsType, self).__init__(scope=scope)
101        if Associated_Campaign is None:
102            self.Associated_Campaign = []
103        else:
104            self.Associated_Campaign = Associated_Campaign
105    def factory(*args_, **kwargs_):
106        if AssociatedCampaignsType.subclass:
107            return AssociatedCampaignsType.subclass(*args_, **kwargs_)
108        else:
109            return AssociatedCampaignsType(*args_, **kwargs_)
110    factory = staticmethod(factory)
111    def get_Associated_Campaign(self): return self.Associated_Campaign
112    def set_Associated_Campaign(self, Associated_Campaign): self.Associated_Campaign = Associated_Campaign
113    def add_Associated_Campaign(self, value): self.Associated_Campaign.append(value)
114    def insert_Associated_Campaign(self, index, value): self.Associated_Campaign[index] = value
115    def hasContent_(self):
116        if (
117            self.Associated_Campaign or
118            super(AssociatedCampaignsType, self).hasContent_()
119            ):
120            return True
121        else:
122            return False
123    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='AssociatedCampaignsType', namespacedef_='', pretty_print=True):
124        if pretty_print:
125            eol_ = '\n'
126        else:
127            eol_ = ''
128        showIndent(lwrite, level, pretty_print)
129        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
130        already_processed = set()
131        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='AssociatedCampaignsType')
132        if self.hasContent_():
133            lwrite('>%s' % (eol_, ))
134            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
135            showIndent(lwrite, level, pretty_print)
136            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
137        else:
138            lwrite('/>%s' % (eol_, ))
139    def exportAttributes(self, lwrite, level, already_processed, namespace_='ta:', name_='AssociatedCampaignsType'):
140        super(AssociatedCampaignsType, self).exportAttributes(lwrite, level, already_processed, namespace_, name_='AssociatedCampaignsType')
141    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='AssociatedCampaignsType', fromsubclass_=False, pretty_print=True):
142        super(AssociatedCampaignsType, self).exportChildren(lwrite, level, nsmap, namespace_, name_, True, pretty_print=pretty_print)
143        if pretty_print:
144            eol_ = '\n'
145        else:
146            eol_ = ''
147        for Associated_Campaign_ in self.Associated_Campaign:
148            Associated_Campaign_.export(lwrite, level, nsmap, namespace_, name_='Associated_Campaign', pretty_print=pretty_print)
149    def build(self, node):
150        self.__sourcenode__ = node
151        already_processed = set()
152        self.buildAttributes(node, node.attrib, already_processed)
153        for child in node:
154            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
155            self.buildChildren(child, node, nodeName_)
156    def buildAttributes(self, node, attrs, already_processed):
157        super(AssociatedCampaignsType, self).buildAttributes(node, attrs, already_processed)
158    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
159        if nodeName_ == 'Associated_Campaign':
160            obj_ = stix_common_binding.RelatedCampaignType.factory()
161            obj_.build(child_)
162            self.Associated_Campaign.append(obj_)
163        super(AssociatedCampaignsType, self).buildChildren(child_, node, nodeName_, True)
164# end class AssociatedCampaignsType
165
166class AssociatedActorsType(stix_common_binding.GenericRelationshipListType):
167    subclass = None
168    superclass = stix_common_binding.GenericRelationshipListType
169    def __init__(self, scope='exclusive', Associated_Actor=None):
170        super(AssociatedActorsType, self).__init__(scope=scope)
171        if Associated_Actor is None:
172            self.Associated_Actor = []
173        else:
174            self.Associated_Actor = Associated_Actor
175    def factory(*args_, **kwargs_):
176        if AssociatedActorsType.subclass:
177            return AssociatedActorsType.subclass(*args_, **kwargs_)
178        else:
179            return AssociatedActorsType(*args_, **kwargs_)
180    factory = staticmethod(factory)
181    def get_Associated_Actor(self): return self.Associated_Actor
182    def set_Associated_Actor(self, Associated_Actor): self.Associated_Actor = Associated_Actor
183    def add_Associated_Actor(self, value): self.Associated_Actor.append(value)
184    def insert_Associated_Actor(self, index, value): self.Associated_Actor[index] = value
185    def hasContent_(self):
186        if (
187            self.Associated_Actor or
188            super(AssociatedActorsType, self).hasContent_()
189            ):
190            return True
191        else:
192            return False
193    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='AssociatedActorsType', namespacedef_='', pretty_print=True):
194        if pretty_print:
195            eol_ = '\n'
196        else:
197            eol_ = ''
198        showIndent(lwrite, level, pretty_print)
199        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
200        already_processed = set()
201        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='AssociatedActorsType')
202        if self.hasContent_():
203            lwrite('>%s' % (eol_, ))
204            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
205            showIndent(lwrite, level, pretty_print)
206            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
207        else:
208            lwrite('/>%s' % (eol_, ))
209    def exportAttributes(self, lwrite, level, already_processed, namespace_='ta:', name_='AssociatedActorsType'):
210        super(AssociatedActorsType, self).exportAttributes(lwrite, level, already_processed, namespace_, name_='AssociatedActorsType')
211    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='AssociatedActorsType', fromsubclass_=False, pretty_print=True):
212        super(AssociatedActorsType, self).exportChildren(lwrite, level, nsmap, namespace_, name_, True, pretty_print=pretty_print)
213        if pretty_print:
214            eol_ = '\n'
215        else:
216            eol_ = ''
217        for Associated_Actor_ in self.Associated_Actor:
218            Associated_Actor_.export(lwrite, level, nsmap, namespace_, name_='Associated_Actor', pretty_print=pretty_print)
219    def build(self, node):
220        self.__sourcenode__ = node
221        already_processed = set()
222        self.buildAttributes(node, node.attrib, already_processed)
223        for child in node:
224            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
225            self.buildChildren(child, node, nodeName_)
226    def buildAttributes(self, node, attrs, already_processed):
227        super(AssociatedActorsType, self).buildAttributes(node, attrs, already_processed)
228    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
229        if nodeName_ == 'Associated_Actor':
230            obj_ = stix_common_binding.RelatedThreatActorType.factory()
231            obj_.build(child_)
232            self.Associated_Actor.append(obj_)
233        super(AssociatedActorsType, self).buildChildren(child_, node, nodeName_, True)
234# end class AssociatedActorsType
235
236@register_extension
237class ThreatActorType(stix_common_binding.ThreatActorBaseType):
238    """Specifies the relevant STIX-ThreatActor schema version for this
239    content."""
240    subclass = None
241    superclass = stix_common_binding.ThreatActorBaseType
242
243    xmlns          = "http://stix.mitre.org/ThreatActor-1"
244    xmlns_prefix   = "ta"
245    xml_type       = "ThreatActorType"
246    xsi_type       = "%s:%s" % (xmlns_prefix, xml_type)
247
248    def __init__(self, idref=None, id=None, timestamp=None, version=None, Title=None, Description=None, Short_Description=None, Identity=None, Type=None, Motivation=None, Sophistication=None, Intended_Effect=None, Planning_And_Operational_Support=None, Observed_TTPs=None, Associated_Campaigns=None, Associated_Actors=None, Handling=None, Confidence=None, Information_Source=None, Related_Packages=None):
249        super(ThreatActorType, self).__init__(idref=idref, id=id, timestamp=timestamp)
250        self.version = _cast(None, version)
251        self.Title = Title
252        if Description is None:
253            self.Description = []
254        else:
255            self.Description = Description
256        if Short_Description is None:
257            self.Short_Description = []
258        else:
259            self.Short_Description = Short_Description
260        self.Identity = Identity
261        if Type is None:
262            self.Type = []
263        else:
264            self.Type = Type
265        if Motivation is None:
266            self.Motivation = []
267        else:
268            self.Motivation = Motivation
269        if Sophistication is None:
270            self.Sophistication = []
271        else:
272            self.Sophistication = Sophistication
273        if Intended_Effect is None:
274            self.Intended_Effect = []
275        else:
276            self.Intended_Effect = Intended_Effect
277        if Planning_And_Operational_Support is None:
278            self.Planning_And_Operational_Support = []
279        else:
280            self.Planning_And_Operational_Support = Planning_And_Operational_Support
281        self.Observed_TTPs = Observed_TTPs
282        self.Associated_Campaigns = Associated_Campaigns
283        self.Associated_Actors = Associated_Actors
284        self.Handling = Handling
285        self.Confidence = Confidence
286        self.Information_Source = Information_Source
287        self.Related_Packages = Related_Packages
288    def factory(*args_, **kwargs_):
289        if ThreatActorType.subclass:
290            return ThreatActorType.subclass(*args_, **kwargs_)
291        else:
292            return ThreatActorType(*args_, **kwargs_)
293    factory = staticmethod(factory)
294    def get_Title(self): return self.Title
295    def set_Title(self, Title): self.Title = Title
296    def insert_Description(self, index, value): self.Description[index] = value
297    def add_Description(self, Description): self.Description.append(Description)
298    def get_Description(self): return self.Description
299    def set_Description(self, Description): self.Description = Description
300    def insert_Short_Description(self, index, value): self.Short_Description[index] = value
301    def add_Short_Description(self, Short_Description): self.Short_Description.append(Short_Description)
302    def get_Short_Description(self): return self.Short_Description
303    def set_Short_Description(self, Short_Description): self.Short_Description = Short_Description
304    def get_Identity(self): return self.Identity
305    def set_Identity(self, Identity): self.Identity = Identity
306    def get_Type(self): return self.Type
307    def set_Type(self, Type): self.Type = Type
308    def add_Type(self, value): self.Type.append(value)
309    def insert_Type(self, index, value): self.Type[index] = value
310    def get_Motivation(self): return self.Motivation
311    def set_Motivation(self, Motivation): self.Motivation = Motivation
312    def add_Motivation(self, value): self.Motivation.append(value)
313    def insert_Motivation(self, index, value): self.Motivation[index] = value
314    def get_Sophistication(self): return self.Sophistication
315    def set_Sophistication(self, Sophistication): self.Sophistication = Sophistication
316    def add_Sophistication(self, value): self.Sophistication.append(value)
317    def insert_Sophistication(self, index, value): self.Sophistication[index] = value
318    def get_Intended_Effect(self): return self.Intended_Effect
319    def set_Intended_Effect(self, Intended_Effect): self.Intended_Effect = Intended_Effect
320    def add_Intended_Effect(self, value): self.Intended_Effect.append(value)
321    def insert_Intended_Effect(self, index, value): self.Intended_Effect[index] = value
322    def get_Planning_And_Operational_Support(self): return self.Planning_And_Operational_Support
323    def set_Planning_And_Operational_Support(self, Planning_And_Operational_Support): self.Planning_And_Operational_Support = Planning_And_Operational_Support
324    def add_Planning_And_Operational_Support(self, value): self.Planning_And_Operational_Support.append(value)
325    def insert_Planning_And_Operational_Support(self, index, value): self.Planning_And_Operational_Support[index] = value
326    def get_Observed_TTPs(self): return self.Observed_TTPs
327    def set_Observed_TTPs(self, Observed_TTPs): self.Observed_TTPs = Observed_TTPs
328    def get_Associated_Campaigns(self): return self.Associated_Campaigns
329    def set_Associated_Campaigns(self, Associated_Campaigns): self.Associated_Campaigns = Associated_Campaigns
330    def get_Associated_Actors(self): return self.Associated_Actors
331    def set_Associated_Actors(self, Associated_Actors): self.Associated_Actors = Associated_Actors
332    def get_Handling(self): return self.Handling
333    def set_Handling(self, Handling): self.Handling = Handling
334    def get_Confidence(self): return self.Confidence
335    def set_Confidence(self, Confidence): self.Confidence = Confidence
336    def get_Information_Source(self): return self.Information_Source
337    def set_Information_Source(self, Information_Source): self.Information_Source = Information_Source
338    def get_Related_Packages(self): return self.Related_Packages
339    def set_Related_Packages(self, Related_Packages): self.Related_Packages = Related_Packages
340    def get_version(self): return self.version
341    def set_version(self, version): self.version = version
342    def hasContent_(self):
343        if (
344            self.Title is not None or
345            self.Description is not None or
346            self.Short_Description is not None or
347            self.Identity is not None or
348            self.Type or
349            self.Motivation or
350            self.Sophistication or
351            self.Intended_Effect or
352            self.Planning_And_Operational_Support or
353            self.Observed_TTPs is not None or
354            self.Associated_Campaigns is not None or
355            self.Associated_Actors is not None or
356            self.Handling is not None or
357            self.Confidence is not None or
358            self.Information_Source is not None or
359            self.Related_Packages is not None or
360            super(ThreatActorType, self).hasContent_()
361            ):
362            return True
363        else:
364            return False
365    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='Threat_Actor', namespacedef_='', pretty_print=True):
366        if pretty_print:
367            eol_ = '\n'
368        else:
369            eol_ = ''
370        showIndent(lwrite, level, pretty_print)
371        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
372        already_processed = set()
373        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='Threat_Actor')
374        if self.hasContent_():
375            lwrite('>%s' % (eol_, ))
376            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
377            showIndent(lwrite, level, pretty_print)
378            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
379        else:
380            lwrite('/>%s' % (eol_, ))
381    def exportAttributes(self, lwrite, level, already_processed, namespace_='ta:', name_='Threat_Actor'):
382        super(ThreatActorType, self).exportAttributes(lwrite, level, already_processed, namespace_, name_='Threat_Actor')
383        # if 'xmlns' not in already_processed:
384        #     already_processed.add('xmlns')
385        #     xmlns = " xmlns:%s='%s'" % (self.xmlns_prefix, self.xmlns)
386        #     lwrite(xmlns)
387        if 'xsi:type' not in already_processed:
388            already_processed.add('xsi:type')
389            xsi_type = " xsi:type='%s:%s'" % (self.xmlns_prefix, self.xml_type)
390            lwrite(xsi_type)
391        if self.version is not None and 'version' not in already_processed:
392            already_processed.add('version')
393            lwrite(' version=%s' % (quote_attrib(self.version), ))
394    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='ThreatActorType', fromsubclass_=False, pretty_print=True):
395        super(ThreatActorType, self).exportChildren(lwrite, level, nsmap, namespace_, name_, True, pretty_print=pretty_print)
396        if pretty_print:
397            eol_ = '\n'
398        else:
399            eol_ = ''
400        if self.Title is not None:
401            showIndent(lwrite, level, pretty_print)
402            lwrite('<%s:Title>%s</%s:Title>%s' % (nsmap[namespace_], quote_xml(self.Title), nsmap[namespace_], eol_))
403        for Description in self.Description:
404            Description.export(lwrite, level, nsmap, namespace_, name_='Description', pretty_print=pretty_print)
405        for Short_Description in self.Short_Description:
406            Short_Description.export(lwrite, level, nsmap, namespace_, name_='Short_Description', pretty_print=pretty_print)
407        if self.Identity is not None:
408            self.Identity.export(lwrite, level, nsmap, namespace_, name_='Identity', pretty_print=pretty_print)
409        for Type_ in self.Type:
410            Type_.export(lwrite, level, nsmap, namespace_, name_='Type', pretty_print=pretty_print)
411        for Motivation_ in self.Motivation:
412            Motivation_.export(lwrite, level, nsmap, namespace_, name_='Motivation', pretty_print=pretty_print)
413        for Sophistication_ in self.Sophistication:
414            Sophistication_.export(lwrite, level, nsmap, namespace_, name_='Sophistication', pretty_print=pretty_print)
415        for Intended_Effect_ in self.Intended_Effect:
416            Intended_Effect_.export(lwrite, level, nsmap, namespace_, name_='Intended_Effect', pretty_print=pretty_print)
417        for Planning_And_Operational_Support_ in self.Planning_And_Operational_Support:
418            Planning_And_Operational_Support_.export(lwrite, level, nsmap, namespace_, name_='Planning_And_Operational_Support', pretty_print=pretty_print)
419        if self.Observed_TTPs is not None:
420            self.Observed_TTPs.export(lwrite, level, nsmap, namespace_, name_='Observed_TTPs', pretty_print=pretty_print)
421        if self.Associated_Campaigns is not None:
422            self.Associated_Campaigns.export(lwrite, level, nsmap, namespace_, name_='Associated_Campaigns', pretty_print=pretty_print)
423        if self.Associated_Actors is not None:
424            self.Associated_Actors.export(lwrite, level, nsmap, namespace_, name_='Associated_Actors', pretty_print=pretty_print)
425        if self.Handling is not None:
426            self.Handling.export(lwrite, level, nsmap, namespace_, name_='Handling', pretty_print=pretty_print)
427        if self.Confidence is not None:
428            self.Confidence.export(lwrite, level, nsmap, namespace_, name_='Confidence', pretty_print=pretty_print)
429        if self.Information_Source is not None:
430            self.Information_Source.export(lwrite, level, nsmap, namespace_, name_='Information_Source', pretty_print=pretty_print)
431        if self.Related_Packages is not None:
432            self.Related_Packages.export(lwrite, level, nsmap, namespace_, name_='Related_Packages', pretty_print=pretty_print)
433    def build(self, node):
434        self.__sourcenode__ = node
435        already_processed = set()
436        self.buildAttributes(node, node.attrib, already_processed)
437        for child in node:
438            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
439            self.buildChildren(child, node, nodeName_)
440    def buildAttributes(self, node, attrs, already_processed):
441        value = find_attr_value_('version', node)
442        if value is not None and 'version' not in already_processed:
443            already_processed.add('version')
444            self.version = value
445        super(ThreatActorType, self).buildAttributes(node, attrs, already_processed)
446    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
447        if nodeName_ == 'Title':
448            Title_ = child_.text
449            Title_ = self.gds_validate_string(Title_, node, 'Title')
450            self.Title = Title_
451        elif nodeName_ == 'Description':
452            obj_ = stix_common_binding.StructuredTextType.factory()
453            obj_.build(child_)
454            self.add_Description(obj_)
455        elif nodeName_ == 'Short_Description':
456            obj_ = stix_common_binding.StructuredTextType.factory()
457            obj_.build(child_)
458            self.add_Short_Description(obj_)
459        elif nodeName_ == 'Identity':
460            from .extensions.identity import ciq_identity_3_0
461            obj_ = lookup_extension(child_, stix_common_binding.IdentityType).factory()
462            obj_.build(child_)
463            self.set_Identity(obj_)
464        elif nodeName_ == 'Type':
465            obj_ = stix_common_binding.StatementType.factory()
466            obj_.build(child_)
467            self.Type.append(obj_)
468        elif nodeName_ == 'Motivation':
469            obj_ = stix_common_binding.StatementType.factory()
470            obj_.build(child_)
471            self.Motivation.append(obj_)
472        elif nodeName_ == 'Sophistication':
473            obj_ = stix_common_binding.StatementType.factory()
474            obj_.build(child_)
475            self.Sophistication.append(obj_)
476        elif nodeName_ == 'Intended_Effect':
477            obj_ = stix_common_binding.StatementType.factory()
478            obj_.build(child_)
479            self.Intended_Effect.append(obj_)
480        elif nodeName_ == 'Planning_And_Operational_Support':
481            obj_ = stix_common_binding.StatementType.factory()
482            obj_.build(child_)
483            self.Planning_And_Operational_Support.append(obj_)
484        elif nodeName_ == 'Observed_TTPs':
485            obj_ = ObservedTTPsType.factory()
486            obj_.build(child_)
487            self.set_Observed_TTPs(obj_)
488        elif nodeName_ == 'Associated_Campaigns':
489            obj_ = AssociatedCampaignsType.factory()
490            obj_.build(child_)
491            self.set_Associated_Campaigns(obj_)
492        elif nodeName_ == 'Associated_Actors':
493            obj_ = AssociatedActorsType.factory()
494            obj_.build(child_)
495            self.set_Associated_Actors(obj_)
496        elif nodeName_ == 'Handling':
497            obj_ = data_marking_binding.MarkingType.factory()
498            obj_.build(child_)
499            self.set_Handling(obj_)
500        elif nodeName_ == 'Confidence':
501            obj_ = stix_common_binding.ConfidenceType.factory()
502            obj_.build(child_)
503            self.set_Confidence(obj_)
504        elif nodeName_ == 'Information_Source':
505            obj_ = stix_common_binding.InformationSourceType.factory()
506            obj_.build(child_)
507            self.set_Information_Source(obj_)
508        elif nodeName_ == 'Related_Packages':
509            obj_ = stix_common_binding.RelatedPackageRefsType.factory()
510            obj_.build(child_)
511            self.set_Related_Packages(obj_)
512        super(ThreatActorType, self).buildChildren(child_, node, nodeName_, True)
513# end class ThreatActorType
514
515GDSClassesMapping = {}
516
517USAGE_TEXT = """
518Usage: python <Parser>.py [ -s ] <in_xml_file>
519"""
520
521def usage():
522    print(USAGE_TEXT)
523    sys.exit(1)
524
525def get_root_tag(node):
526    tag = Tag_pattern_.match(node.tag).groups()[-1]
527    rootClass = GDSClassesMapping.get(tag)
528    if rootClass is None:
529        rootClass = globals().get(tag)
530    return tag, rootClass
531
532def parse(inFileName):
533    doc = parsexml_(inFileName)
534    rootNode = doc.getroot()
535    rootTag, rootClass = get_root_tag(rootNode)
536    if rootClass is None:
537        rootTag = 'Threat_Actor'
538        rootClass = ThreatActorType
539    rootObj = rootClass.factory()
540    rootObj.build(rootNode)
541    # Enable Python to collect the space used by the DOM.
542    doc = None
543    # sys.stdout.write('<?xml version="1.0" ?>\n')
544    # rootObj.export(sys.stdout, 0, name_=rootTag,
545    #     namespacedef_='',
546    #     pretty_print=True)
547    return rootObj
548
549def parseEtree(inFileName):
550    doc = parsexml_(inFileName)
551    rootNode = doc.getroot()
552    rootTag, rootClass = get_root_tag(rootNode)
553    if rootClass is None:
554        rootTag = 'Threat_Actor'
555        rootClass = ThreatActorType
556    rootObj = rootClass.factory()
557    rootObj.build(rootNode)
558    # Enable Python to collect the space used by the DOM.
559    doc = None
560    rootElement = rootObj.to_etree(None, name_=rootTag)
561    content = etree_.tostring(rootElement, pretty_print=True,
562        xml_declaration=True, encoding="utf-8")
563    sys.stdout.write(content)
564    sys.stdout.write('\n')
565    return rootObj, rootElement
566
567def parseString(inString):
568    from mixbox.vendor.six import StringIO
569    doc = parsexml_(StringIO(inString))
570    rootNode = doc.getroot()
571    rootTag, rootClass = get_root_tag(rootNode)
572    if rootClass is None:
573        rootTag = 'Threat_Actor'
574        rootClass = ThreatActorType
575    rootObj = rootClass.factory()
576    rootObj.build(rootNode)
577    # Enable Python to collect the space used by the DOM.
578    doc = None
579    # sys.stdout.write('<?xml version="1.0" ?>\n')
580    # rootObj.export(sys.stdout, 0, name_="Threat_Actor",
581    #     namespacedef_='')
582    return rootObj
583
584def main():
585    args = sys.argv[1:]
586    if len(args) == 1:
587        parse(args[0])
588    else:
589        usage()
590
591if __name__ == '__main__':
592    #import pdb; pdb.set_trace()
593    main()
594
595__all__ = [
596    "ObservedTTPsType",
597    "AssociatedCampaignsType",
598    "AssociatedActorsType",
599    "ThreatActorType"
600    ]
601