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:27 2013 by generateDS.py version 2.9a.
9#
10
11import sys
12
13import cybox.bindings.cybox_core as cybox_core_binding
14from mixbox.binding_utils import *
15
16from stix.bindings import lookup_extension
17import stix.bindings.stix_common as stix_common_binding
18import stix.bindings.data_marking as data_marking_binding
19
20XML_NS = "http://stix.mitre.org/stix-1"
21
22#
23# Data representation classes.
24#
25
26
27
28class STIXType(GeneratedsSuper):
29    """STIXType defines a bundle of information characterized in the
30    Structured Threat Information eXpression (STIX)
31    language.Specifies a globally unique identifier for this STIX
32    Package. Specifies a globally unique identifier of a STIX
33    Package specified elsewhere.Specifies the relevant STIX schema
34    version for this content."""
35    subclass = None
36    superclass = None
37    def __init__(self, idref=None, id=None, timestamp=None, version=None, STIX_Header=None, Observables=None, Indicators=None, TTPs=None, Exploit_Targets=None, Incidents=None, Courses_Of_Action=None, Campaigns=None, Threat_Actors=None, Related_Packages=None, Reports=None):
38        self.idref = _cast(None, idref)
39        self.id = _cast(None, id)
40        self.timestamp = _cast(None, timestamp)
41        self.version = _cast(None, version)
42        self.STIX_Header = STIX_Header
43        self.Observables = Observables
44        self.Indicators = Indicators
45        self.TTPs = TTPs
46        self.Exploit_Targets = Exploit_Targets
47        self.Incidents = Incidents
48        self.Courses_Of_Action = Courses_Of_Action
49        self.Campaigns = Campaigns
50        self.Threat_Actors = Threat_Actors
51        self.Related_Packages = Related_Packages
52        self.Reports = Reports
53        self.nsmap = {}
54    def factory(*args_, **kwargs_):
55        if STIXType.subclass:
56            return STIXType.subclass(*args_, **kwargs_)
57        else:
58            return STIXType(*args_, **kwargs_)
59    factory = staticmethod(factory)
60    def get_STIX_Header(self): return self.STIX_Header
61    def set_STIX_Header(self, STIX_Header): self.STIX_Header = STIX_Header
62    def get_Observables(self): return self.Observables
63    def set_Observables(self, Observables): self.Observables = Observables
64    def get_Indicators(self): return self.Indicators
65    def set_Indicators(self, Indicators): self.Indicators = Indicators
66    def get_TTPs(self): return self.TTPs
67    def set_TTPs(self, TTPs): self.TTPs = TTPs
68    def get_Exploit_Targets(self): return self.Exploit_Targets
69    def set_Exploit_Targets(self, Exploit_Targets): self.Exploit_Targets = Exploit_Targets
70    def get_Incidents(self): return self.Incidents
71    def set_Incidents(self, Incidents): self.Incidents = Incidents
72    def get_Courses_Of_Action(self): return self.Courses_Of_Action
73    def set_Courses_Of_Action(self, Courses_Of_Action): self.Courses_Of_Action = Courses_Of_Action
74    def get_Campaigns(self): return self.Campaigns
75    def set_Campaigns(self, Campaigns): self.Campaigns = Campaigns
76    def get_Threat_Actors(self): return self.Threat_Actors
77    def set_Threat_Actors(self, Threat_Actors): self.Threat_Actors = Threat_Actors
78    def get_Related_Packages(self): return self.Related_Packages
79    def set_Related_Packages(self, value): self.Related_Packages = value
80    def get_Reports(self): return self.Reports
81    def set_Reports(self, value): self.Reports = value
82    def get_idref(self): return self.idref
83    def set_idref(self, idref): self.idref = idref
84    def get_id(self): return self.id
85    def set_id(self, id): self.id = id
86    def get_version(self): return self.version
87    def set_version(self, version): self.version = version
88    def get_timestamp(self): return self.timestamp
89    def set_timestamp(self, timestamp): self.timestamp = timestamp
90    def hasContent_(self):
91        if (
92            self.STIX_Header is not None or
93            self.Observables is not None or
94            self.Indicators is not None or
95            self.TTPs is not None or
96            self.Exploit_Targets is not None or
97            self.Incidents is not None or
98            self.Courses_Of_Action is not None or
99            self.Campaigns is not None or
100            self.Threat_Actors is not None or
101            self.Related_Packages is not None or
102            self.Reports
103            ):
104            return True
105        else:
106            return False
107    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='STIX_Package', namespacedef_='', pretty_print=True):
108        if pretty_print:
109            eol_ = '\n'
110        else:
111            eol_ = ''
112        showIndent(lwrite, level, pretty_print)
113        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
114        already_processed = set()
115        self.exportAttributes(lwrite, level, nsmap, already_processed, namespace_, name_='STIXType')
116        if self.hasContent_():
117            lwrite('>%s' % (eol_, ))
118            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
119            showIndent(lwrite, level, pretty_print)
120            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
121        else:
122            lwrite('/>%s' % (eol_, ))
123    def exportAttributes(self, lwrite, level, nsmap, already_processed, namespace_=XML_NS, name_='STIXType'):
124        if self.idref is not None and 'idref' not in already_processed:
125            already_processed.add('idref')
126            lwrite(' idref=%s' % (quote_attrib(self.idref), ))
127        if self.id is not None and 'id' not in already_processed:
128            already_processed.add('id')
129            lwrite(' id=%s' % (quote_attrib(self.id), ))
130        if self.version is not None and 'version' not in already_processed:
131            already_processed.add('version')
132            lwrite(' version=%s' % (quote_attrib(self.version), ))
133        if self.timestamp is not None and 'timestamp' not in already_processed:
134            already_processed.add('timestamp')
135            lwrite(' timestamp="%s"' % self.gds_format_datetime(self.timestamp, input_name='timestamp'))
136
137    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='STIXType', fromsubclass_=False, pretty_print=True):
138        if pretty_print:
139            eol_ = '\n'
140        else:
141            eol_ = ''
142        if self.STIX_Header is not None:
143            self.STIX_Header.export(lwrite, level, nsmap, namespace_, name_='STIX_Header', pretty_print=pretty_print)
144        if self.Observables is not None:
145            self.Observables.export(lwrite, level, "%s:" % (nsmap[namespace_]), name_='Observables', pretty_print=pretty_print) # no nsmap parameter, so we use this hack to pass the right namespace prefix
146        if self.Indicators is not None:
147            self.Indicators.export(lwrite, level, nsmap, namespace_, name_='Indicators', pretty_print=pretty_print)
148        if self.TTPs is not None:
149            self.TTPs.export(lwrite, level, nsmap, namespace_, name_='TTPs', pretty_print=pretty_print)
150        if self.Exploit_Targets is not None:
151            self.Exploit_Targets.export(lwrite, level, nsmap, namespace_, name_='Exploit_Targets', pretty_print=pretty_print)
152        if self.Incidents is not None:
153            self.Incidents.export(lwrite, level, nsmap, namespace_, name_='Incidents', pretty_print=pretty_print)
154        if self.Courses_Of_Action is not None:
155            self.Courses_Of_Action.export(lwrite, level, nsmap, namespace_, name_='Courses_Of_Action', pretty_print=pretty_print)
156        if self.Campaigns is not None:
157            self.Campaigns.export(lwrite, level, nsmap, namespace_, name_='Campaigns', pretty_print=pretty_print)
158        if self.Threat_Actors is not None:
159            self.Threat_Actors.export(lwrite, level, nsmap, namespace_, name_='Threat_Actors', pretty_print=pretty_print)
160        if self.Reports is not None:
161            self.Reports.export(lwrite, level, nsmap, namespace_, name_='Reports', pretty_print=pretty_print)
162        if self.Related_Packages is not None:
163            self.Related_Packages.export(lwrite, level, nsmap, namespace_, name_='Related_Packages', pretty_print=pretty_print)
164    def build(self, node):
165        self.__sourcenode__ = node
166        already_processed = set()
167        self.nsmap = node.nsmap
168        self.buildAttributes(node, node.attrib, already_processed)
169        for child in node:
170            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
171            self.buildChildren(child, node, nodeName_)
172    def buildAttributes(self, node, attrs, already_processed):
173        value = find_attr_value_('idref', node)
174        if value is not None and 'idref' not in already_processed:
175            already_processed.add('idref')
176            self.idref = value
177        value = find_attr_value_('id', node)
178        if value is not None and 'id' not in already_processed:
179            already_processed.add('id')
180            self.id = value
181        value = find_attr_value_('version', node)
182        if value is not None and 'version' not in already_processed:
183            already_processed.add('version')
184            self.version = value
185        value = find_attr_value_('timestamp', node)
186        if value is not None and 'timestamp' not in already_processed:
187            already_processed.add('timestamp')
188            try:
189                self.timestamp = self.gds_parse_datetime(value, node, 'timestamp')
190            except ValueError as exp:
191                raise ValueError('Bad date-time attribute (timestamp): %s' % exp)
192    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
193        if nodeName_ == 'STIX_Header':
194            obj_ = STIXHeaderType.factory()
195            obj_.build(child_)
196            self.set_STIX_Header(obj_)
197        elif nodeName_ == 'Observables':
198            obj_ = cybox_core_binding.ObservablesType.factory()
199            obj_.build(child_)
200            self.set_Observables(obj_)
201        elif nodeName_ == 'Indicators':
202            obj_ = IndicatorsType.factory()
203            obj_.build(child_)
204            self.set_Indicators(obj_)
205        elif nodeName_ == 'TTPs':
206            obj_ = TTPsType.factory()
207            obj_.build(child_)
208            self.set_TTPs(obj_)
209        elif nodeName_ == 'Exploit_Targets':
210            obj_ = stix_common_binding.ExploitTargetsType.factory()
211            obj_.build(child_)
212            self.set_Exploit_Targets(obj_)
213        elif nodeName_ == 'Incidents':
214            obj_ = IncidentsType.factory()
215            obj_.build(child_)
216            self.set_Incidents(obj_)
217        elif nodeName_ == 'Courses_Of_Action':
218            obj_ = CoursesOfActionType.factory()
219            obj_.build(child_)
220            self.set_Courses_Of_Action(obj_)
221        elif nodeName_ == 'Campaigns':
222            obj_ = CampaignsType.factory()
223            obj_.build(child_)
224            self.set_Campaigns(obj_)
225        elif nodeName_ == 'Threat_Actors':
226            obj_ = ThreatActorsType.factory()
227            obj_.build(child_)
228            self.set_Threat_Actors(obj_)
229        elif nodeName_ == 'Reports':
230            obj_ = ReportsType.factory()
231            obj_.build(child_)
232            self.set_Reports(obj_)
233        elif nodeName_ == 'Related_Packages':
234            obj_ = RelatedPackagesType.factory()
235            obj_.build(child_)
236            self.set_Related_Packages(obj_)
237# end class STIXType
238
239
240class RelatedPackagesType(stix_common_binding.GenericRelationshipListType):
241    subclass = None
242    superclass = stix_common_binding.GenericRelationshipListType
243    def __init__(self, scope='exclusive', Related_Package=None):
244        super(RelatedPackagesType, self).__init__(scope=scope)
245        if Related_Package is None:
246            self.Related_Package = []
247        else:
248            self.Related_Package = Related_Package
249    def factory(*args_, **kwargs_):
250        if RelatedPackagesType.subclass:
251            return RelatedPackagesType.subclass(*args_, **kwargs_)
252        else:
253            return RelatedPackagesType(*args_, **kwargs_)
254    factory = staticmethod(factory)
255    def get_Related_Package(self): return self.Related_Package
256    def set_Related_Package(self, Related_Package): self.Related_Package = Related_Package
257    def add_Related_Package(self, value): self.Related_Package.append(value)
258    def insert_Related_Package(self, index, value): self.Related_Package[index] = value
259    def hasContent_(self):
260        if (
261            self.Related_Package or
262            super(RelatedPackagesType, self).hasContent_()
263            ):
264            return True
265        else:
266            return False
267    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='RelatedPackagesType', namespacedef_='', pretty_print=True):
268        if pretty_print:
269            eol_ = '\n'
270        else:
271            eol_ = ''
272        showIndent(lwrite, level, pretty_print)
273        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
274        already_processed = set()
275        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='RelatedPackagesType')
276        if self.hasContent_():
277            lwrite('>%s' % (eol_, ))
278            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
279            showIndent(lwrite, level, pretty_print)
280            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
281        else:
282            lwrite('/>%s' % (eol_, ))
283    def exportAttributes(self, lwrite, level, already_processed, namespace_='stix:', name_='RelatedPackagesType'):
284        super(RelatedPackagesType, self).exportAttributes(lwrite, level, already_processed, namespace_, name_='RelatedPackagesType')
285    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='RelatedPackagesType', fromsubclass_=False, pretty_print=True):
286        super(RelatedPackagesType, self).exportChildren(lwrite, level, nsmap, namespace_, name_, True, pretty_print=pretty_print)
287        if pretty_print:
288            eol_ = '\n'
289        else:
290            eol_ = ''
291        for Related_Package_ in self.Related_Package:
292            Related_Package_.export(lwrite, level, nsmap, namespace_, name_='Related_Package', pretty_print=pretty_print)
293    def build(self, node):
294        self.__sourcenode__ = node
295        already_processed = set()
296        self.buildAttributes(node, node.attrib, already_processed)
297        for child in node:
298            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
299            self.buildChildren(child, node, nodeName_)
300    def buildAttributes(self, node, attrs, already_processed):
301        super(RelatedPackagesType, self).buildAttributes(node, attrs, already_processed)
302    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
303        if nodeName_ == 'Related_Package':
304            obj_ = RelatedPackageType.factory()
305            obj_.build(child_)
306            self.Related_Package.append(obj_)
307        super(RelatedPackagesType, self).buildChildren(child_, node, nodeName_, True)
308# end class RelatedPackagesType
309
310class RelatedPackageType(stix_common_binding.GenericRelationshipType):
311    """Identifies or characterizes a relationship to a Package."""
312    subclass = None
313    superclass = stix_common_binding.GenericRelationshipType
314    def __init__(self, Confidence=None, Information_Source=None, Relationship=None, Package=None):
315        super(RelatedPackageType, self).__init__(Confidence=Confidence, Information_Source=Information_Source, Relationship=Relationship)
316        self.Package = Package
317    def factory(*args_, **kwargs_):
318        if RelatedPackageType.subclass:
319            return RelatedPackageType.subclass(*args_, **kwargs_)
320        else:
321            return RelatedPackageType(*args_, **kwargs_)
322    factory = staticmethod(factory)
323    def get_Package(self): return self.Package
324    def set_Package(self, Package): self.Package = Package
325    def hasContent_(self):
326        if (
327            self.Package is not None or
328            super(RelatedPackageType, self).hasContent_()
329            ):
330            return True
331        else:
332            return False
333    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='RelatedPackageType', namespacedef_='', pretty_print=True):
334        if pretty_print:
335            eol_ = '\n'
336        else:
337            eol_ = ''
338        showIndent(lwrite, level, pretty_print)
339        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
340        already_processed = set()
341        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='RelatedPackageType')
342        if self.hasContent_():
343            lwrite('>%s' % (eol_, ))
344            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
345            showIndent(lwrite, level, pretty_print)
346            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
347        else:
348            lwrite('/>%s' % (eol_, ))
349    def exportAttributes(self, lwrite, level, already_processed, namespace_='stix:', name_='RelatedPackageType'):
350        super(RelatedPackageType, self).exportAttributes(lwrite, level, already_processed, namespace_, name_='RelatedPackageType')
351    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='RelatedPackageType', fromsubclass_=False, pretty_print=True):
352        super(RelatedPackageType, self).exportChildren(lwrite, level, nsmap, stix_common_binding.XML_NS, name_, True, pretty_print=pretty_print)
353        if pretty_print:
354            eol_ = '\n'
355        else:
356            eol_ = ''
357        if self.Package is not None:
358            self.Package.export(lwrite, level, nsmap, namespace_, name_='Package', pretty_print=pretty_print)
359    def build(self, node):
360        self.__sourcenode__ = node
361        already_processed = set()
362        self.buildAttributes(node, node.attrib, already_processed)
363        for child in node:
364            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
365            self.buildChildren(child, node, nodeName_)
366    def buildAttributes(self, node, attrs, already_processed):
367        super(RelatedPackageType, self).buildAttributes(node, attrs, already_processed)
368    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
369        if nodeName_ == 'Package':
370            obj_ = STIXType.factory()
371            obj_.build(child_)
372            self.set_Package(obj_)
373        super(RelatedPackageType, self).buildChildren(child_, node, nodeName_, True)
374# end class RelatedPackageType
375
376
377class STIXHeaderType(GeneratedsSuper):
378    """The STIXHeaderType provides a structure for characterizing a package
379    of STIX content."""
380    subclass = None
381    superclass = None
382    def __init__(self, Title=None, Package_Intent=None, Description=None, Short_Description=None, Profiles=None, Handling=None, Information_Source=None):
383        self.Title = Title
384        if Package_Intent is None:
385            self.Package_Intent = []
386        else:
387            self.Package_Intent = Package_Intent
388        if Description is None:
389            self.Description = []
390        else:
391            self.Description = Description
392        self.Handling = Handling
393        if Short_Description is None:
394            self.Short_Description = []
395        else:
396            self.Short_Description = Short_Description
397        self.Profiles = Profiles
398        self.Information_Source = Information_Source
399    def factory(*args_, **kwargs_):
400        if STIXHeaderType.subclass:
401            return STIXHeaderType.subclass(*args_, **kwargs_)
402        else:
403            return STIXHeaderType(*args_, **kwargs_)
404    factory = staticmethod(factory)
405    def get_Title(self): return self.Title
406    def set_Title(self, Title): self.Title = Title
407    def get_Package_Intent(self): return self.Package_Intent
408    def set_Package_Intent(self, Package_Intent): self.Package_Intent = Package_Intent
409    def add_Package_Intent(self, value): self.Package_Intent.append(value)
410    def insert_Package_Intent(self, index, value): self.Package_Intent[index] = value
411    def insert_Description(self, index, value): self.Description[index] = value
412    def add_Description(self, Description): self.Description.append(Description)
413    def get_Description(self): return self.Description
414    def set_Description(self, Description): self.Description = Description
415    def insert_Short_Description(self, index, value): self.Short_Description[index] = value
416    def add_Short_Description(self, Short_Description): self.Short_Description.append(Short_Description)
417    def get_Short_Description(self): return self.Short_Description
418    def set_Short_Description(self, Short_Description): self.Short_Description = Short_Description
419    def get_Profiles(self): return self.Profiles
420    def set_Profiles(self, Profiles): self.Profiles = Profiles
421    def get_Handling(self): return self.Handling
422    def set_Handling(self, Handling): self.Handling = Handling
423    def get_Information_Source(self): return self.Information_Source
424    def set_Information_Source(self, Information_Source): self.Information_Source = Information_Source
425    def hasContent_(self):
426        if (
427            self.Title is not None or
428            self.Package_Intent or
429            self.Description or
430            self.Short_Description or
431            self.Profiles is not None or
432            self.Handling is not None or
433            self.Information_Source is not None
434            ):
435            return True
436        else:
437            return False
438    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='STIXHeaderType', namespacedef_='', pretty_print=True):
439        if pretty_print:
440            eol_ = '\n'
441        else:
442            eol_ = ''
443        showIndent(lwrite, level, pretty_print)
444        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
445        already_processed = set()
446        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='STIXHeaderType')
447        if self.hasContent_():
448            lwrite('>%s' % (eol_, ))
449            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
450            showIndent(lwrite, level, pretty_print)
451            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
452        else:
453            lwrite('/>%s' % (eol_, ))
454    def exportAttributes(self, lwrite, level, already_processed, namespace_=XML_NS, name_='STIXHeaderType'):
455        pass
456    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='STIXHeaderType', fromsubclass_=False, pretty_print=True):
457        if pretty_print:
458            eol_ = '\n'
459        else:
460            eol_ = ''
461        if self.Title is not None:
462            showIndent(lwrite, level, pretty_print)
463            lwrite('<%s:Title>%s</%s:Title>%s' % (nsmap[namespace_], quote_xml(self.Title), nsmap[namespace_], eol_))
464        for Package_Intent_ in self.Package_Intent:
465            Package_Intent_.export(lwrite, level, nsmap, namespace_, name_='Package_Intent', pretty_print=pretty_print)
466        for Description in self.Description:
467            Description.export(lwrite, level, nsmap, namespace_, name_='Description', pretty_print=pretty_print)
468        for Short_Description in self.Short_Description:
469            Short_Description.export(lwrite, level, nsmap, namespace_, name_='Short_Description', pretty_print=pretty_print)
470        if self.Profiles is not None:
471            self.Profiles.export(lwrite, level, nsmap, namespace_, name_='Profiles', pretty_print=pretty_print)
472        if self.Handling is not None:
473            self.Handling.export(lwrite, level, nsmap, namespace_, name_='Handling', pretty_print=pretty_print)
474        if self.Information_Source is not None:
475            self.Information_Source.export(lwrite, level, nsmap, namespace_, name_='Information_Source', pretty_print=pretty_print)
476    def build(self, node):
477        self.__sourcenode__ = node
478        already_processed = set()
479        self.buildAttributes(node, node.attrib, already_processed)
480        for child in node:
481            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
482            self.buildChildren(child, node, nodeName_)
483    def buildAttributes(self, node, attrs, already_processed):
484        pass
485    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
486        if nodeName_ == 'Title':
487            Title_ = child_.text
488            Title_ = self.gds_validate_string(Title_, node, 'Title')
489            self.Title = Title_
490        elif nodeName_ == 'Package_Intent':
491            obj_ = stix_common_binding.ControlledVocabularyStringType.factory()
492            obj_.build(child_)
493            self.Package_Intent.append(obj_)
494        elif nodeName_ == 'Description':
495            obj_ = stix_common_binding.StructuredTextType.factory()
496            obj_.build(child_)
497            self.add_Description(obj_)
498        elif nodeName_ == 'Short_Description':
499            obj_ = stix_common_binding.StructuredTextType.factory()
500            obj_.build(child_)
501            self.add_Short_Description(obj_)
502        elif nodeName_ == 'Profiles':
503            obj_ = stix_common_binding.ProfilesType.factory()
504            obj_.build(child_)
505            self.set_Profiles(obj_)
506        elif nodeName_ == 'Handling':
507            obj_ = data_marking_binding.MarkingType.factory()
508            obj_.build(child_)
509            self.set_Handling(obj_)
510        elif nodeName_ == 'Information_Source':
511            obj_ = stix_common_binding.InformationSourceType.factory()
512            obj_.build(child_)
513            self.set_Information_Source(obj_)
514# end class STIXHeaderType
515
516class IndicatorsType(GeneratedsSuper):
517    subclass = None
518    superclass = None
519    def __init__(self, Indicator=None):
520        if Indicator is None:
521            self.Indicator = []
522        else:
523            self.Indicator = Indicator
524    def factory(*args_, **kwargs_):
525        if IndicatorsType.subclass:
526            return IndicatorsType.subclass(*args_, **kwargs_)
527        else:
528            return IndicatorsType(*args_, **kwargs_)
529    factory = staticmethod(factory)
530    def get_Indicator(self): return self.Indicator
531    def set_Indicator(self, Indicator): self.Indicator = Indicator
532    def add_Indicator(self, value): self.Indicator.append(value)
533    def insert_Indicator(self, index, value): self.Indicator[index] = value
534    def hasContent_(self):
535        if (
536            self.Indicator
537            ):
538            return True
539        else:
540            return False
541    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='IndicatorsType', namespacedef_='', pretty_print=True):
542        if pretty_print:
543            eol_ = '\n'
544        else:
545            eol_ = ''
546        showIndent(lwrite, level, pretty_print)
547        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
548        already_processed = set()
549        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='IndicatorsType')
550        if self.hasContent_():
551            lwrite('>%s' % (eol_, ))
552            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
553            showIndent(lwrite, level, pretty_print)
554            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
555        else:
556            lwrite('/>%s' % (eol_, ))
557    def exportAttributes(self, lwrite, level, already_processed, namespace_=XML_NS, name_='IndicatorsType'):
558        pass
559    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='IndicatorsType', fromsubclass_=False, pretty_print=True):
560        if pretty_print:
561            eol_ = '\n'
562        else:
563            eol_ = ''
564        for Indicator_ in self.Indicator:
565            Indicator_.export(lwrite, level, nsmap, namespace_, name_='Indicator', pretty_print=pretty_print)
566    def build(self, node):
567        self.__sourcenode__ = node
568        already_processed = set()
569        self.buildAttributes(node, node.attrib, already_processed)
570        for child in node:
571            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
572            self.buildChildren(child, node, nodeName_)
573    def buildAttributes(self, node, attrs, already_processed):
574        pass
575    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
576        if nodeName_ == 'Indicator':
577            from . import indicator
578            obj_ = lookup_extension(child_, stix_common_binding.IndicatorBaseType).factory()
579            obj_.build(child_)
580            self.Indicator.append(obj_)
581
582# end class IndicatorsType
583
584class TTPsType(GeneratedsSuper):
585    subclass = None
586    superclass = None
587    def __init__(self, TTP=None, Kill_Chains=None):
588        if TTP is None:
589            self.TTP = []
590        else:
591            self.TTP = TTP
592        self.Kill_Chains = Kill_Chains
593    def factory(*args_, **kwargs_):
594        if TTPsType.subclass:
595            return TTPsType.subclass(*args_, **kwargs_)
596        else:
597            return TTPsType(*args_, **kwargs_)
598    factory = staticmethod(factory)
599    def get_TTP(self): return self.TTP
600    def set_TTP(self, TTP): self.TTP = TTP
601    def add_TTP(self, value): self.TTP.append(value)
602    def insert_TTP(self, index, value): self.TTP[index] = value
603    def get_Kill_Chains(self): return self.Kill_Chains
604    def set_Kill_Chains(self, Kill_Chains): self.Kill_Chains = Kill_Chains
605    def hasContent_(self):
606        if (
607            self.TTP or
608            self.Kill_Chains is not None
609            ):
610            return True
611        else:
612            return False
613    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='TTPsType', namespacedef_='', pretty_print=True):
614        if pretty_print:
615            eol_ = '\n'
616        else:
617            eol_ = ''
618        showIndent(lwrite, level, pretty_print)
619        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
620        already_processed = set()
621        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='TTPsType')
622        if self.hasContent_():
623            lwrite('>%s' % (eol_, ))
624            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
625            showIndent(lwrite, level, pretty_print)
626            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
627        else:
628            lwrite('/>%s' % (eol_, ))
629    def exportAttributes(self, lwrite, level, already_processed, namespace_=XML_NS, name_='TTPsType'):
630        pass
631    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='TTPsType', fromsubclass_=False, pretty_print=True):
632        if pretty_print:
633            eol_ = '\n'
634        else:
635            eol_ = ''
636        for TTP_ in self.TTP:
637            TTP_.export(lwrite, level, nsmap, namespace_, name_='TTP', pretty_print=pretty_print)
638        if self.Kill_Chains is not None:
639            self.Kill_Chains.export(lwrite, level, nsmap, namespace_, name_='Kill_Chains', pretty_print=pretty_print)
640    def build(self, node):
641        self.__sourcenode__ = node
642        already_processed = set()
643        self.buildAttributes(node, node.attrib, already_processed)
644        for child in node:
645            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
646            self.buildChildren(child, node, nodeName_)
647    def buildAttributes(self, node, attrs, already_processed):
648        pass
649    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
650        if nodeName_ == 'TTP':
651            from . import ttp
652            obj_ = lookup_extension(child_, stix_common_binding.TTPBaseType).factory()
653            obj_.build(child_)
654            self.TTP.append(obj_)
655
656        elif nodeName_ == 'Kill_Chains':
657            obj_ = stix_common_binding.KillChainsType.factory()
658            obj_.build(child_)
659            self.set_Kill_Chains(obj_)
660# end class TTPsType
661
662class IncidentsType(GeneratedsSuper):
663    subclass = None
664    superclass = None
665    def __init__(self, Incident=None):
666        if Incident is None:
667            self.Incident = []
668        else:
669            self.Incident = Incident
670    def factory(*args_, **kwargs_):
671        if IncidentsType.subclass:
672            return IncidentsType.subclass(*args_, **kwargs_)
673        else:
674            return IncidentsType(*args_, **kwargs_)
675    factory = staticmethod(factory)
676    def get_Incident(self): return self.Incident
677    def set_Incident(self, Incident): self.Incident = Incident
678    def add_Incident(self, value): self.Incident.append(value)
679    def insert_Incident(self, index, value): self.Incident[index] = value
680    def hasContent_(self):
681        if (
682            self.Incident
683            ):
684            return True
685        else:
686            return False
687    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='IncidentsType', namespacedef_='', pretty_print=True):
688        if pretty_print:
689            eol_ = '\n'
690        else:
691            eol_ = ''
692        showIndent(lwrite, level, pretty_print)
693        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
694        already_processed = set()
695        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='IncidentsType')
696        if self.hasContent_():
697            lwrite('>%s' % (eol_, ))
698            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
699            showIndent(lwrite, level, pretty_print)
700            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
701        else:
702            lwrite('/>%s' % (eol_, ))
703    def exportAttributes(self, lwrite, level, already_processed, namespace_=XML_NS, name_='IncidentsType'):
704        pass
705    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='IncidentsType', fromsubclass_=False, pretty_print=True):
706        if pretty_print:
707            eol_ = '\n'
708        else:
709            eol_ = ''
710        for Incident_ in self.Incident:
711            Incident_.export(lwrite, level, nsmap, namespace_, name_='Incident', pretty_print=pretty_print)
712    def build(self, node):
713        self.__sourcenode__ = node
714        already_processed = set()
715        self.buildAttributes(node, node.attrib, already_processed)
716        for child in node:
717            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
718            self.buildChildren(child, node, nodeName_)
719    def buildAttributes(self, node, attrs, already_processed):
720        pass
721    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
722        if nodeName_ == 'Incident':
723            from . import incident
724            obj_ = lookup_extension(child_, stix_common_binding.IncidentBaseType).factory()
725            obj_.build(child_)
726            self.Incident.append(obj_)
727
728# end class IncidentsType
729
730class CoursesOfActionType(GeneratedsSuper):
731    subclass = None
732    superclass = None
733    def __init__(self, Course_Of_Action=None):
734        if Course_Of_Action is None:
735            self.Course_Of_Action = []
736        else:
737            self.Course_Of_Action = Course_Of_Action
738    def factory(*args_, **kwargs_):
739        if CoursesOfActionType.subclass:
740            return CoursesOfActionType.subclass(*args_, **kwargs_)
741        else:
742            return CoursesOfActionType(*args_, **kwargs_)
743    factory = staticmethod(factory)
744    def get_Course_Of_Action(self): return self.Course_Of_Action
745    def set_Course_Of_Action(self, Course_Of_Action): self.Course_Of_Action = Course_Of_Action
746    def add_Course_Of_Action(self, value): self.Course_Of_Action.append(value)
747    def insert_Course_Of_Action(self, index, value): self.Course_Of_Action[index] = value
748    def hasContent_(self):
749        if (
750            self.Course_Of_Action
751            ):
752            return True
753        else:
754            return False
755    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='CoursesOfActionType', namespacedef_='', pretty_print=True):
756        if pretty_print:
757            eol_ = '\n'
758        else:
759            eol_ = ''
760        showIndent(lwrite, level, pretty_print)
761        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
762        already_processed = set()
763        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='CoursesOfActionType')
764        if self.hasContent_():
765            lwrite('>%s' % (eol_, ))
766            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
767            showIndent(lwrite, level, pretty_print)
768            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
769        else:
770            lwrite('/>%s' % (eol_, ))
771    def exportAttributes(self, lwrite, level, already_processed, namespace_=XML_NS, name_='CoursesOfActionType'):
772        pass
773    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='CoursesOfActionType', fromsubclass_=False, pretty_print=True):
774        if pretty_print:
775            eol_ = '\n'
776        else:
777            eol_ = ''
778        for Course_Of_Action_ in self.Course_Of_Action:
779            Course_Of_Action_.export(lwrite, level, nsmap, namespace_, name_='Course_Of_Action', pretty_print=pretty_print)
780    def build(self, node):
781        self.__sourcenode__ = node
782        already_processed = set()
783        self.buildAttributes(node, node.attrib, already_processed)
784        for child in node:
785            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
786            self.buildChildren(child, node, nodeName_)
787    def buildAttributes(self, node, attrs, already_processed):
788        pass
789    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
790        if nodeName_ == 'Course_Of_Action':
791            from . import course_of_action
792            obj_ = lookup_extension(child_, stix_common_binding.CourseOfActionBaseType).factory()
793            obj_.build(child_)
794            self.Course_Of_Action.append(obj_)
795# end class CoursesOfActionType
796
797class CampaignsType(GeneratedsSuper):
798    subclass = None
799    superclass = None
800    def __init__(self, Campaign=None):
801        if Campaign is None:
802            self.Campaign = []
803        else:
804            self.Campaign = Campaign
805    def factory(*args_, **kwargs_):
806        if CampaignsType.subclass:
807            return CampaignsType.subclass(*args_, **kwargs_)
808        else:
809            return CampaignsType(*args_, **kwargs_)
810    factory = staticmethod(factory)
811    def get_Campaign(self): return self.Campaign
812    def set_Campaign(self, Campaign): self.Campaign = Campaign
813    def add_Campaign(self, value): self.Campaign.append(value)
814    def insert_Campaign(self, index, value): self.Campaign[index] = value
815    def hasContent_(self):
816        if (
817            self.Campaign
818            ):
819            return True
820        else:
821            return False
822    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='CampaignsType', namespacedef_='', pretty_print=True):
823        if pretty_print:
824            eol_ = '\n'
825        else:
826            eol_ = ''
827        showIndent(lwrite, level, pretty_print)
828        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
829        already_processed = set()
830        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='CampaignsType')
831        if self.hasContent_():
832            lwrite('>%s' % (eol_, ))
833            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
834            showIndent(lwrite, level, pretty_print)
835            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
836        else:
837            lwrite('/>%s' % (eol_, ))
838    def exportAttributes(self, lwrite, level, already_processed, namespace_=XML_NS, name_='CampaignsType'):
839        pass
840    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='CampaignsType', fromsubclass_=False, pretty_print=True):
841        if pretty_print:
842            eol_ = '\n'
843        else:
844            eol_ = ''
845        for Campaign_ in self.Campaign:
846            Campaign_.export(lwrite, level, nsmap, namespace_, name_='Campaign', pretty_print=pretty_print)
847    def build(self, node):
848        self.__sourcenode__ = node
849        already_processed = set()
850        self.buildAttributes(node, node.attrib, already_processed)
851        for child in node:
852            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
853            self.buildChildren(child, node, nodeName_)
854    def buildAttributes(self, node, attrs, already_processed):
855        pass
856    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
857        if nodeName_ == 'Campaign':
858            from . import campaign
859            obj_ = lookup_extension(child_, stix_common_binding.CampaignBaseType).factory()
860            obj_.build(child_)
861            self.Campaign.append(obj_)
862# end class CampaignsType
863
864class ThreatActorsType(GeneratedsSuper):
865    subclass = None
866    superclass = None
867    def __init__(self, Threat_Actor=None):
868        if Threat_Actor is None:
869            self.Threat_Actor = []
870        else:
871            self.Threat_Actor = Threat_Actor
872    def factory(*args_, **kwargs_):
873        if ThreatActorsType.subclass:
874            return ThreatActorsType.subclass(*args_, **kwargs_)
875        else:
876            return ThreatActorsType(*args_, **kwargs_)
877    factory = staticmethod(factory)
878    def get_Threat_Actor(self): return self.Threat_Actor
879    def set_Threat_Actor(self, Threat_Actor): self.Threat_Actor = Threat_Actor
880    def add_Threat_Actor(self, value): self.Threat_Actor.append(value)
881    def insert_Threat_Actor(self, index, value): self.Threat_Actor[index] = value
882    def hasContent_(self):
883        if (
884            self.Threat_Actor
885            ):
886            return True
887        else:
888            return False
889    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='ThreatActorsType', namespacedef_='', pretty_print=True):
890        if pretty_print:
891            eol_ = '\n'
892        else:
893            eol_ = ''
894        showIndent(lwrite, level, pretty_print)
895        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
896        already_processed = set()
897        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='ThreatActorsType')
898        if self.hasContent_():
899            lwrite('>%s' % (eol_, ))
900            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
901            showIndent(lwrite, level, pretty_print)
902            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
903        else:
904            lwrite('/>%s' % (eol_, ))
905    def exportAttributes(self, lwrite, level, already_processed, namespace_=XML_NS, name_='ThreatActorsType'):
906        pass
907    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='ThreatActorsType', fromsubclass_=False, pretty_print=True):
908        if pretty_print:
909            eol_ = '\n'
910        else:
911            eol_ = ''
912        for Threat_Actor_ in self.Threat_Actor:
913            Threat_Actor_.export(lwrite, level, nsmap, namespace_, name_='Threat_Actor', pretty_print=pretty_print)
914    def build(self, node):
915        self.__sourcenode__ = node
916        already_processed = set()
917        self.buildAttributes(node, node.attrib, already_processed)
918        for child in node:
919            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
920            self.buildChildren(child, node, nodeName_)
921    def buildAttributes(self, node, attrs, already_processed):
922        pass
923    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
924        if nodeName_ == 'Threat_Actor':
925            from . import threat_actor
926            obj_ = lookup_extension(child_, stix_common_binding.ThreatActorBaseType).factory()
927            obj_.build(child_)
928            self.Threat_Actor.append(obj_)
929# end class ThreatActorsType
930
931
932class ReportsType(GeneratedsSuper):
933    subclass = None
934    superclass = None
935    def __init__(self, Report=None):
936        if Report is None:
937            self.Report = []
938        else:
939            self.Report = Report
940    def factory(*args_, **kwargs_):
941        if ReportsType.subclass:
942            return ReportsType.subclass(*args_, **kwargs_)
943        else:
944            return ReportsType(*args_, **kwargs_)
945    factory = staticmethod(factory)
946    def get_Report(self): return self.Report
947    def set_Report(self, Report): self.Report = Report
948    def add_Report(self, value): self.Report.append(value)
949    def insert_Report(self, index, value): self.Report[index] = value
950    def hasContent_(self):
951        if (
952            self.Report
953            ):
954            return True
955        else:
956            return False
957    def export(self, lwrite, level, nsmap, namespace_=XML_NS, name_='ReportsType', namespacedef_='', pretty_print=True):
958        if pretty_print:
959            eol_ = '\n'
960        else:
961            eol_ = ''
962        showIndent(lwrite, level, pretty_print)
963        lwrite('<%s:%s%s' % (nsmap[namespace_], name_, namespacedef_ and ' ' + namespacedef_ or '', ))
964        already_processed = set()
965        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='ReportsType')
966        if self.hasContent_():
967            lwrite('>%s' % (eol_, ))
968            self.exportChildren(lwrite, level + 1, nsmap, XML_NS, name_, pretty_print=pretty_print)
969            showIndent(lwrite, level, pretty_print)
970            lwrite('</%s:%s>%s' % (nsmap[namespace_], name_, eol_))
971        else:
972            lwrite('/>%s' % (eol_, ))
973    def exportAttributes(self, lwrite, level, already_processed, namespace_=XML_NS, name_='ReportsType'):
974        pass
975    def exportChildren(self, lwrite, level, nsmap, namespace_=XML_NS, name_='ReportsType', fromsubclass_=False, pretty_print=True):
976        if pretty_print:
977            eol_ = '\n'
978        else:
979            eol_ = ''
980        for Report_ in self.Report:
981            Report_.export(lwrite, level, nsmap, namespace_, name_='Report', pretty_print=pretty_print)
982
983    def build(self, node):
984        self.__sourcenode__ = node
985        already_processed = set()
986        self.buildAttributes(node, node.attrib, already_processed)
987        for child in node:
988            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
989            self.buildChildren(child, node, nodeName_)
990    def buildAttributes(self, node, attrs, already_processed):
991        pass
992    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
993        if nodeName_ == 'Report':
994            from . import report
995            obj_ = lookup_extension(child_, stix_common_binding.ReportBaseType).factory()
996            obj_.build(child_)
997            self.Report.append(obj_)
998# end class TTPsType
999
1000
1001GDSClassesMapping = {}
1002
1003USAGE_TEXT = """
1004Usage: python <Parser>.py [ -s ] <in_xml_file>
1005"""
1006
1007def usage():
1008    print(USAGE_TEXT)
1009    sys.exit(1)
1010
1011def get_root_tag(node):
1012    tag = Tag_pattern_.match(node.tag).groups()[-1]
1013    rootClass = GDSClassesMapping.get(tag)
1014    if rootClass is None:
1015        rootClass = globals().get(tag)
1016    return tag, rootClass
1017
1018def parse(inFileName, nsmap=None):
1019    if not nsmap:
1020        from stix.utils.nsparser import DEFAULT_STIX_NS_TO_PREFIX
1021        nsmap = DEFAULT_STIX_NS_TO_PREFIX
1022
1023    doc = parsexml_(inFileName)
1024    rootNode = doc.getroot()
1025    rootTag, rootClass = get_root_tag(rootNode)
1026    if rootClass is None:
1027        rootTag = 'STIX_Package'
1028        rootClass = STIXType
1029    rootObj = rootClass.factory()
1030    rootObj.build(rootNode)
1031    # Enable Python to collect the space used by the DOM.
1032    doc = None
1033    # sys.stdout.write('<?xml version="1.0" ?>\n')
1034    # rootObj.export(sys.stdout, 0, nsmap, name_=rootTag,
1035    #     namespacedef_='',
1036    #     pretty_print=True)
1037    return rootObj
1038
1039def parseEtree(inFileName):
1040    doc = parsexml_(inFileName)
1041    rootNode = doc.getroot()
1042    rootTag, rootClass = get_root_tag(rootNode)
1043    if rootClass is None:
1044        rootTag = 'STIX_Package'
1045        rootClass = STIXType
1046    rootObj = rootClass.factory()
1047    rootObj.build(rootNode)
1048    # Enable Python to collect the space used by the DOM.
1049    doc = None
1050    rootElement = rootObj.to_etree(None, name_=rootTag)
1051    content = etree_.tostring(rootElement, pretty_print=True,
1052        xml_declaration=True, encoding="utf-8")
1053    sys.stdout.write(content)
1054    sys.stdout.write('\n')
1055    return rootObj, rootElement
1056
1057def parseString(inString):
1058    from mixbox.vendor.six import StringIO
1059    doc = parsexml_(StringIO(inString))
1060    rootNode = doc.getroot()
1061    rootTag, rootClass = get_root_tag(rootNode)
1062    if rootClass is None:
1063        rootTag = 'STIX_Package'
1064        rootClass = STIXType
1065    rootObj = rootClass.factory()
1066    rootObj.build(rootNode)
1067    # Enable Python to collect the space used by the DOM.
1068    doc = None
1069    # sys.stdout.write('<?xml version="1.0" ?>\n')
1070    # rootObj.export(sys.stdout, 0, name_="STIX_Package",
1071    #     namespacedef_='')
1072    return rootObj
1073
1074def main():
1075    args = sys.argv[1:]
1076    if len(args) == 1:
1077        parse(args[0])
1078    else:
1079        usage()
1080
1081if __name__ == '__main__':
1082    #import pdb; pdb.set_trace()
1083    main()
1084
1085__all__ = [
1086    "STIXType",
1087    "STIXHeaderType",
1088    "IndicatorsType",
1089    "TTPsType",
1090    "IncidentsType",
1091    "CoursesOfActionType",
1092    "CampaignsType",
1093    "ThreatActorsType"
1094    ]
1095