#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2014, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

#
# Generated Tue Apr 09 11:15:12 2013 by generateDS.py version 2.9a.
#

import sys
import getopt
import re as re_

import cybox_common
import base64
from datetime import datetime, tzinfo, timedelta

etree_ = None
Verbose_import_ = False
(   XMLParser_import_none, XMLParser_import_lxml,
    XMLParser_import_elementtree
    ) = range(3)
XMLParser_import_library = None
try:
    # lxml
    from lxml import etree as etree_
    XMLParser_import_library = XMLParser_import_lxml
    if Verbose_import_:
        print("running with lxml.etree")
except ImportError:
    try:
        # cElementTree from Python 2.5+
        import xml.etree.cElementTree as etree_
        XMLParser_import_library = XMLParser_import_elementtree
        if Verbose_import_:
            print("running with cElementTree on Python 2.5+")
    except ImportError:
        try:
            # ElementTree from Python 2.5+
            import xml.etree.ElementTree as etree_
            XMLParser_import_library = XMLParser_import_elementtree
            if Verbose_import_:
                print("running with ElementTree on Python 2.5+")
        except ImportError:
            try:
                # normal cElementTree install
                import cElementTree as etree_
                XMLParser_import_library = XMLParser_import_elementtree
                if Verbose_import_:
                    print("running with cElementTree")
            except ImportError:
                try:
                    # normal ElementTree install
                    import elementtree.ElementTree as etree_
                    XMLParser_import_library = XMLParser_import_elementtree
                    if Verbose_import_:
                        print("running with ElementTree")
                except ImportError:
                    raise ImportError(
                        "Failed to import ElementTree from any known place")

def parsexml_(*args, **kwargs):
    if (XMLParser_import_library == XMLParser_import_lxml and
        'parser' not in kwargs):
        # Use the lxml ElementTree compatible parser so that, e.g.,
        #   we ignore comments.
        kwargs['parser'] = etree_.ETCompatXMLParser(huge_tree=True)
    doc = etree_.parse(*args, **kwargs)
    return doc

#
# User methods
#
# Calls to the methods in these classes are generated by generateDS.py.
# You can replace these methods by re-implementing the following class
#   in a module named generatedssuper.py.

try:
    from generatedssuper import GeneratedsSuper
except ImportError, exp:

    class GeneratedsSuper(object):
        tzoff_pattern = re_.compile(r'(\+|-)((0\d|1[0-3]):[0-5]\d|14:00)$')
        class _FixedOffsetTZ(tzinfo):
            def __init__(self, offset, name):
                self.__offset = timedelta(minutes = offset)
                self.__name = name
            def utcoffset(self, dt):
                return self.__offset
            def tzname(self, dt):
                return self.__name
            def dst(self, dt):
                return None
        def gds_format_string(self, input_data, input_name=''):
            return input_data
        def gds_validate_string(self, input_data, node, input_name=''):
            return input_data
        def gds_format_base64(self, input_data, input_name=''):
            return base64.b64encode(input_data)
        def gds_validate_base64(self, input_data, node, input_name=''):
            return input_data
        def gds_format_integer(self, input_data, input_name=''):
            return '%d' % input_data
        def gds_validate_integer(self, input_data, node, input_name=''):
            return input_data
        def gds_format_integer_list(self, input_data, input_name=''):
            return '%s' % input_data
        def gds_validate_integer_list(self, input_data, node, input_name=''):
            values = input_data.split()
            for value in values:
                try:
                    fvalue = float(value)
                except (TypeError, ValueError), exp:
                    raise_parse_error(node, 'Requires sequence of integers')
            return input_data
        def gds_format_float(self, input_data, input_name=''):
            return '%f' % input_data
        def gds_validate_float(self, input_data, node, input_name=''):
            return input_data
        def gds_format_float_list(self, input_data, input_name=''):
            return '%s' % input_data
        def gds_validate_float_list(self, input_data, node, input_name=''):
            values = input_data.split()
            for value in values:
                try:
                    fvalue = float(value)
                except (TypeError, ValueError), exp:
                    raise_parse_error(node, 'Requires sequence of floats')
            return input_data
        def gds_format_double(self, input_data, input_name=''):
            return '%e' % input_data
        def gds_validate_double(self, input_data, node, input_name=''):
            return input_data
        def gds_format_double_list(self, input_data, input_name=''):
            return '%s' % input_data
        def gds_validate_double_list(self, input_data, node, input_name=''):
            values = input_data.split()
            for value in values:
                try:
                    fvalue = float(value)
                except (TypeError, ValueError), exp:
                    raise_parse_error(node, 'Requires sequence of doubles')
            return input_data
        def gds_format_boolean(self, input_data, input_name=''):
            return ('%s' % input_data).lower()
        def gds_validate_boolean(self, input_data, node, input_name=''):
            return input_data
        def gds_format_boolean_list(self, input_data, input_name=''):
            return '%s' % input_data
        def gds_validate_boolean_list(self, input_data, node, input_name=''):
            values = input_data.split()
            for value in values:
                if value not in ('true', '1', 'false', '0', ):
                    raise_parse_error(node,
                        'Requires sequence of booleans '
                        '("true", "1", "false", "0")')
            return input_data
        def gds_validate_datetime(self, input_data, node, input_name=''):
            return input_data
        def gds_format_datetime(self, input_data, input_name=''):
            if isinstance(input_data, basestring):
                return input_data
            if input_data.microsecond == 0:
                _svalue = input_data.strftime('%Y-%m-%dT%H:%M:%S')
            else:
                _svalue = input_data.strftime('%Y-%m-%dT%H:%M:%S.%f')
            if input_data.tzinfo is not None:
                tzoff = input_data.tzinfo.utcoffset(input_data)
                if tzoff is not None:
                    total_seconds = tzoff.seconds + (86400 * tzoff.days)
                    if total_seconds == 0:
                        _svalue += 'Z'
                    else:
                        if total_seconds < 0:
                            _svalue += '-'
                            total_seconds *= -1
                        else:
                            _svalue += '+'
                        hours = total_seconds // 3600
                        minutes = (total_seconds - (hours * 3600)) // 60
                        _svalue += '{0:02d}:{1:02d}'.format(hours, minutes)
            return _svalue
        def gds_parse_datetime(self, input_data, node, input_name=''):
            tz = None
            if input_data[-1] == 'Z':
                tz = GeneratedsSuper._FixedOffsetTZ(0, 'GMT')
                input_data = input_data[:-1]
            else:
                results = GeneratedsSuper.tzoff_pattern.search(input_data)
                if results is not None:
                    tzoff_parts = results.group(2).split(':')
                    tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
                    if results.group(1) == '-':
                        tzoff *= -1
                    tz = GeneratedsSuper._FixedOffsetTZ(
                        tzoff, results.group(0))
                    input_data = input_data[:-6]
            if len(input_data.split('.')) > 1:
                dt = datetime.strptime(
                        input_data, '%Y-%m-%dT%H:%M:%S.%f')
            else:
                dt = datetime.strptime(
                        input_data, '%Y-%m-%dT%H:%M:%S')
            return dt.replace(tzinfo = tz)

        def gds_validate_date(self, input_data, node, input_name=''):
            return input_data
        def gds_format_date(self, input_data, input_name=''):
            if isinstance(input_data, basestring):
                return input_data
            _svalue = input_data.strftime('%Y-%m-%d')
            if input_data.tzinfo is not None:
                tzoff = input_data.tzinfo.utcoffset(input_data)
                if tzoff is not None:
                    total_seconds = tzoff.seconds + (86400 * tzoff.days)
                    if total_seconds == 0:
                        _svalue += 'Z'
                    else:
                        if total_seconds < 0:
                            _svalue += '-'
                            total_seconds *= -1
                        else:
                            _svalue += '+'
                        hours = total_seconds // 3600
                        minutes = (total_seconds - (hours * 3600)) // 60
                        _svalue += '{0:02d}:{1:02d}'.format(hours, minutes)
            return _svalue
        def gds_parse_date(self, input_data, node, input_name=''):
            tz = None
            if input_data[-1] == 'Z':
                tz = GeneratedsSuper._FixedOffsetTZ(0, 'GMT')
                input_data = input_data[:-1]
            else:
                results = GeneratedsSuper.tzoff_pattern.search(input_data)
                if results is not None:
                    tzoff_parts = results.group(2).split(':')
                    tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
                    if results.group(1) == '-':
                        tzoff *= -1
                    tz = GeneratedsSuper._FixedOffsetTZ(
                        tzoff, results.group(0))
                    input_data = input_data[:-6]
            return datetime.strptime(input_data,
                '%Y-%m-%d').replace(tzinfo = tz)
        def gds_str_lower(self, instring):
            return instring.lower()
        def get_path_(self, node):
            path_list = []
            self.get_path_list_(node, path_list)
            path_list.reverse()
            path = '/'.join(path_list)
            return path
        Tag_strip_pattern_ = re_.compile(r'\{.*\}')
        def get_path_list_(self, node, path_list):
            if node is None:
                return
            tag = GeneratedsSuper.Tag_strip_pattern_.sub('', node.tag)
            if tag:
                path_list.append(tag)
            self.get_path_list_(node.getparent(), path_list)
        def get_class_obj_(self, node, default_class=None):
            class_obj1 = default_class
            if 'xsi' in node.nsmap:
                classname = node.get('{%s}type' % node.nsmap['xsi'])
                if classname is not None:
                    names = classname.split(':')
                    if len(names) == 2:
                        classname = names[1]
                    class_obj2 = globals().get(classname)
                    if class_obj2 is not None:
                        class_obj1 = class_obj2
            return class_obj1
        def gds_build_any(self, node, type_name=None):
            return None


#
# If you have installed IPython you can uncomment and use the following.
# IPython is available from http://ipython.scipy.org/.
#

## from IPython.Shell import IPShellEmbed
## args = ''
## ipshell = IPShellEmbed(args,
##     banner = 'Dropping into IPython',
##     exit_msg = 'Leaving Interpreter, back to program.')

# Then use the following line where and when you want to drop into the
# IPython shell:
#    ipshell('<some message> -- Entering ipshell.\nHit Ctrl-D to exit')

#
# Globals
#

ExternalEncoding = 'utf-8'
Tag_pattern_ = re_.compile(r'({.*})?(.*)')
String_cleanup_pat_ = re_.compile(r"[\n\r\s]+")
Namespace_extract_pat_ = re_.compile(r'{(.*)}(.*)')

#
# Support/utility functions.
#

def showIndent(lwrite, level, pretty_print=True):
    if pretty_print:

            lwrite('    ' * level)

def quote_xml(inStr):
    if not inStr:
        return ''
    s1 = (isinstance(inStr, basestring) and inStr or
          '%s' % inStr)
    s1 = s1.replace('&', '&amp;')
    s1 = s1.replace('<', '&lt;')
    s1 = s1.replace('>', '&gt;')
    return unicode(s1).encode(ExternalEncoding)

def quote_attrib(inStr):
    s1 = (isinstance(inStr, basestring) and inStr or
          '%s' % inStr)
    s1 = s1.replace('&', '&amp;')
    s1 = s1.replace('<', '&lt;')
    s1 = s1.replace('>', '&gt;')
    if '"' in s1:
        if "'" in s1:
            s1 = '"%s"' % s1.replace('"', "&quot;")
        else:
            s1 = "'%s'" % s1
    else:
        s1 = '"%s"' % s1
    return unicode(s1).encode(ExternalEncoding)

def quote_python(inStr):
    s1 = inStr
    if s1.find("'") == -1:
        if s1.find('\n') == -1:
            return "'%s'" % s1
        else:
            return "'''%s'''" % s1
    else:
        if s1.find('"') != -1:
            s1 = s1.replace('"', '\\"')
        if s1.find('\n') == -1:
            return '"%s"' % s1
        else:
            return '"""%s"""' % s1

def get_all_text_(node):
    if node.text is not None:
        text = node.text
    else:
        text = ''
    for child in node:
        if child.tail is not None:
            text += child.tail
    return text

def find_attr_value_(attr_name, node):
    attrs = node.attrib
    attr_parts = attr_name.split(':')
    value = None
    if len(attr_parts) == 1:
        value = attrs.get(attr_name)
    elif len(attr_parts) == 2:
        prefix, name = attr_parts
        namespace = node.nsmap.get(prefix)
        if namespace is not None:
            value = attrs.get('{%s}%s' % (namespace, name, ))
    return value


class GDSParseError(Exception):
    pass

def raise_parse_error(node, msg):
    if XMLParser_import_library == XMLParser_import_lxml:
        msg = '%s (element %s/line %d)' % (
            msg, node.tag, node.sourceline, )
    else:
        msg = '%s (element %s)' % (msg, node.tag, )
    raise GDSParseError(msg)


class MixedContainer:
    # Constants for category:
    CategoryNone = 0
    CategoryText = 1
    CategorySimple = 2
    CategoryComplex = 3
    # Constants for content_type:
    TypeNone = 0
    TypeText = 1
    TypeString = 2
    TypeInteger = 3
    TypeFloat = 4
    TypeDecimal = 5
    TypeDouble = 6
    TypeBoolean = 7
    TypeBase64 = 8
    def __init__(self, category, content_type, name, value):
        self.category = category
        self.content_type = content_type
        self.name = name
        self.value = value
    def getCategory(self):
        return self.category
    def getContenttype(self, content_type):
        return self.content_type
    def getValue(self):
        return self.value
    def getName(self):
        return self.name
    def export(self, lwrite, level, name, namespace, pretty_print=True):
        if self.category == MixedContainer.CategoryText:
            # Prevent exporting empty content as empty lines.
            if self.value.strip():
                lwrite(self.value)
        elif self.category == MixedContainer.CategorySimple:
            self.exportSimple(lwrite, level, name)
        else:    # category == MixedContainer.CategoryComplex
            self.value.export(lwrite, level, namespace, name, pretty_print)
    def exportSimple(self, lwrite, level, name):
        if self.content_type == MixedContainer.TypeString:
            lwrite('<%s>%s</%s>' %
                (self.name, self.value, self.name))
        elif self.content_type == MixedContainer.TypeInteger or \
                self.content_type == MixedContainer.TypeBoolean:
            lwrite('<%s>%d</%s>' %
                (self.name, self.value, self.name))
        elif self.content_type == MixedContainer.TypeFloat or \
                self.content_type == MixedContainer.TypeDecimal:
            lwrite('<%s>%f</%s>' %
                (self.name, self.value, self.name))
        elif self.content_type == MixedContainer.TypeDouble:
            lwrite('<%s>%g</%s>' %
                (self.name, self.value, self.name))
        elif self.content_type == MixedContainer.TypeBase64:
            lwrite('<%s>%s</%s>' %
                (self.name, base64.b64encode(self.value), self.name))
    def to_etree(self, element):
        if self.category == MixedContainer.CategoryText:
            # Prevent exporting empty content as empty lines.
            if self.value.strip():
                if len(element) > 0:
                    if element[-1].tail is None:
                        element[-1].tail = self.value
                    else:
                        element[-1].tail += self.value
                else:
                    if element.text is None:
                        element.text = self.value
                    else:
                        element.text += self.value
        elif self.category == MixedContainer.CategorySimple:
            subelement = etree_.SubElement(element, '%s' % self.name)
            subelement.text = self.to_etree_simple()
        else:    # category == MixedContainer.CategoryComplex
            self.value.to_etree(element)
    def to_etree_simple(self):
        if self.content_type == MixedContainer.TypeString:
            text = self.value
        elif (self.content_type == MixedContainer.TypeInteger or
                self.content_type == MixedContainer.TypeBoolean):
            text = '%d' % self.value
        elif (self.content_type == MixedContainer.TypeFloat or
                self.content_type == MixedContainer.TypeDecimal):
            text = '%f' % self.value
        elif self.content_type == MixedContainer.TypeDouble:
            text = '%g' % self.value
        elif self.content_type == MixedContainer.TypeBase64:
            text = '%s' % base64.b64encode(self.value)
        return text
    def exportLiteral(self, lwrite, level, name):
        if self.category == MixedContainer.CategoryText:
            showIndent(lwrite, level)
            lwrite('model_.MixedContainer(%d, %d, "%s", "%s"),\n'
                % (self.category, self.content_type, self.name, self.value))
        elif self.category == MixedContainer.CategorySimple:
            showIndent(lwrite, level)
            lwrite('model_.MixedContainer(%d, %d, "%s", "%s"),\n'
                % (self.category, self.content_type, self.name, self.value))
        else:    # category == MixedContainer.CategoryComplex
            showIndent(lwrite, level)
            lwrite('model_.MixedContainer(%d, %d, "%s",\n' % \
                (self.category, self.content_type, self.name,))
            self.value.exportLiteral(lwrite, level + 1)
            showIndent(lwrite, level)
            lwrite(')\n')


class MemberSpec_(object):
    def __init__(self, name='', data_type='', container=0):
        self.name = name
        self.data_type = data_type
        self.container = container
    def set_name(self, name): self.name = name
    def get_name(self): return self.name
    def set_data_type(self, data_type): self.data_type = data_type
    def get_data_type_chain(self): return self.data_type
    def get_data_type(self):
        if isinstance(self.data_type, list):
            if len(self.data_type) > 0:
                return self.data_type[-1]
            else:
                return 'xs:string'
        else:
            return self.data_type
    def set_container(self, container): self.container = container
    def get_container(self): return self.container

def _cast(typ, value):
    if typ is None or value is None:
        return value
    return typ(value)

#
# Data representation classes.
#

class X509CertificateContentsType(GeneratedsSuper):
    """The X509CertificateContentsType type represents the contents of an X.509
    certificate, including items such as issuer, subject, and
    others."""
    
    subclass = None
    superclass = None
    def __init__(self, Version=None, Serial_Number=None, Signature_Algorithm=None, Issuer=None, Validity=None, Subject=None, Subject_Public_Key=None, Standard_Extensions=None, Non_Standard_Extensions=None):
        self.Version = Version
        self.Serial_Number = Serial_Number
        self.Signature_Algorithm = Signature_Algorithm
        self.Issuer = Issuer
        self.Validity = Validity
        self.Subject = Subject
        self.Subject_Public_Key = Subject_Public_Key
        self.Standard_Extensions = Standard_Extensions
        self.Non_Standard_Extensions = Non_Standard_Extensions
    def factory(*args_, **kwargs_):
        if X509CertificateContentsType.subclass:
            return X509CertificateContentsType.subclass(*args_, **kwargs_)
        else:
            return X509CertificateContentsType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Version(self): return self.Version
    def set_Version(self, Version): self.Version = Version
    def validate_IntegerObjectPropertyType(self, value):
        # Validate type cybox_common.IntegerObjectPropertyType, a restriction on None.
        pass
    def get_Serial_Number(self): return self.Serial_Number
    def set_Serial_Number(self, Serial_Number): self.Serial_Number = Serial_Number
    def validate_StringObjectPropertyType(self, value):
        # Validate type cybox_common.StringObjectPropertyType, a restriction on None.
        pass
    def get_Signature_Algorithm(self): return self.Signature_Algorithm
    def set_Signature_Algorithm(self, Signature_Algorithm): self.Signature_Algorithm = Signature_Algorithm
    def get_Issuer(self): return self.Issuer
    def set_Issuer(self, Issuer): self.Issuer = Issuer
    def get_Validity(self): return self.Validity
    def set_Validity(self, Validity): self.Validity = Validity
    def get_Subject(self): return self.Subject
    def set_Subject(self, Subject): self.Subject = Subject
    def get_Subject_Public_Key(self): return self.Subject_Public_Key
    def set_Subject_Public_Key(self, Subject_Public_Key): self.Subject_Public_Key = Subject_Public_Key
    def get_Standard_Extensions(self): return self.Standard_Extensions
    def set_Standard_Extensions(self, Standard_Extensions): self.Standard_Extensions = Standard_Extensions
    def get_Non_Standard_Extensions(self): return self.Non_Standard_Extensions
    def set_Non_Standard_Extensions(self, Non_Standard_Extensions): self.Non_Standard_Extensions = Non_Standard_Extensions
    def hasContent_(self):
        if (
            self.Version is not None or
            self.Serial_Number is not None or
            self.Signature_Algorithm is not None or
            self.Issuer is not None or
            self.Validity is not None or
            self.Subject is not None or
            self.Subject_Public_Key is not None or
            self.Standard_Extensions is not None or
            self.Non_Standard_Extensions is not None
            ):
            return True
        else:
            return False
    def export(self, lwrite, level, namespace_='X509CertificateObj:', name_='X509CertificateContentsType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        showIndent(lwrite, level, pretty_print)
        lwrite('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='X509CertificateContentsType')
        if self.hasContent_():
            lwrite('>%s' % (eol_, ))
            self.exportChildren(lwrite, level + 1, namespace_, name_, pretty_print=pretty_print)
            showIndent(lwrite, level, pretty_print)
            lwrite('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            lwrite('/>%s' % (eol_, ))
    def exportAttributes(self, lwrite, level, already_processed, namespace_='X509CertificateObj:', name_='X509CertificateContentsType'):
        pass
    def exportChildren(self, lwrite, level, namespace_='X509CertificateObj:', name_='X509CertificateContentsType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Version is not None:
            self.Version.export(lwrite, level, 'X509CertificateObj:', name_='Version', pretty_print=pretty_print)
        if self.Serial_Number is not None:
            self.Serial_Number.export(lwrite, level, 'X509CertificateObj:', name_='Serial_Number', pretty_print=pretty_print)
        if self.Signature_Algorithm is not None:
            self.Signature_Algorithm.export(lwrite, level, 'X509CertificateObj:', name_='Signature_Algorithm', pretty_print=pretty_print)
        if self.Issuer is not None:
            self.Issuer.export(lwrite, level, 'X509CertificateObj:', name_='Issuer', pretty_print=pretty_print)
        if self.Validity is not None:
            self.Validity.export(lwrite, level, 'X509CertificateObj:', name_='Validity', pretty_print=pretty_print)
        if self.Subject is not None:
            self.Subject.export(lwrite, level, 'X509CertificateObj:', name_='Subject', pretty_print=pretty_print)
        if self.Subject_Public_Key is not None:
            self.Subject_Public_Key.export(lwrite, level, 'X509CertificateObj:', name_='Subject_Public_Key', pretty_print=pretty_print)
        if self.Standard_Extensions is not None:
            self.Standard_Extensions.export(lwrite, level, 'X509CertificateObj:', name_='Standard_Extensions', pretty_print=pretty_print)
        if self.Non_Standard_Extensions is not None:
            self.Non_Standard_Extensions.export(lwrite, level, 'X509CertificateObj:', name_='Non_Standard_Extensions', pretty_print=pretty_print)
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Version':
            obj_ = cybox_common.IntegerObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Version(obj_)
        elif nodeName_ == 'Serial_Number':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Serial_Number(obj_)
        elif nodeName_ == 'Signature_Algorithm':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Signature_Algorithm(obj_)
        elif nodeName_ == 'Issuer':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Issuer(obj_)
        elif nodeName_ == 'Validity':
            obj_ = ValidityType.factory()
            obj_.build(child_)
            self.set_Validity(obj_)
        elif nodeName_ == 'Subject':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Subject(obj_)
        elif nodeName_ == 'Subject_Public_Key':
            obj_ = SubjectPublicKeyType.factory()
            obj_.build(child_)
            self.set_Subject_Public_Key(obj_)
        elif nodeName_ == 'Standard_Extensions':
            obj_ = X509V3ExtensionsType.factory()
            obj_.build(child_)
            self.set_Standard_Extensions(obj_)
        elif nodeName_ == 'Non_Standard_Extensions':
            obj_ = X509NonStandardExtensionsType.factory()
            obj_.build(child_)
            self.set_Non_Standard_Extensions(obj_)
# end class X509CertificateContentsType

class X509CertificateSignatureType(GeneratedsSuper):
    """The X509CertificateSignatureType contains the signature and
    signature algorithm of this X.509 certificate."""
    
    subclass = None
    superclass = None
    def __init__(self, Signature_Algorithm=None, Signature=None):
        self.Signature_Algorithm = Signature_Algorithm
        self.Signature = Signature
    def factory(*args_, **kwargs_):
        if X509CertificateSignatureType.subclass:
            return X509CertificateSignatureType.subclass(*args_, **kwargs_)
        else:
            return X509CertificateSignatureType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Signature_Algorithm(self): return self.Signature_Algorithm
    def set_Signature_Algorithm(self, Signature_Algorithm): self.Signature_Algorithm = Signature_Algorithm
    def validate_StringObjectPropertyType(self, value):
        # Validate type cybox_common.StringObjectPropertyType, a restriction on None.
        pass
    def get_Signature(self): return self.Signature
    def set_Signature(self, Signature): self.Signature = Signature
    def hasContent_(self):
        if (
            self.Signature_Algorithm is not None or
            self.Signature is not None
            ):
            return True
        else:
            return False
    def export(self, lwrite, level, namespace_='X509CertificateObj:', name_='X509CertificateSignatureType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        showIndent(lwrite, level, pretty_print)
        lwrite('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='X509CertificateSignatureType')
        if self.hasContent_():
            lwrite('>%s' % (eol_, ))
            self.exportChildren(lwrite, level + 1, namespace_, name_, pretty_print=pretty_print)
            showIndent(lwrite, level, pretty_print)
            lwrite('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            lwrite('/>%s' % (eol_, ))
    def exportAttributes(self, lwrite, level, already_processed, namespace_='X509CertificateObj:', name_='X509CertificateSignatureType'):
        pass
    def exportChildren(self, lwrite, level, namespace_='X509CertificateObj:', name_='X509CertificateSignatureType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Signature_Algorithm is not None:
            self.Signature_Algorithm.export(lwrite, level, 'X509CertificateObj:', name_='Signature_Algorithm', pretty_print=pretty_print)
        if self.Signature is not None:
            self.Signature.export(lwrite, level, 'X509CertificateObj:', name_='Signature', pretty_print=pretty_print)
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Signature_Algorithm':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Signature_Algorithm(obj_)
        elif nodeName_ == 'Signature':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Signature(obj_)
# end class X509CertificateSignatureType

class SubjectPublicKeyType(GeneratedsSuper):
    """The SubjectPublicKeyType is used to carry the public key and
    identify the algorithm with which the key is used."""
    
    subclass = None
    superclass = None
    def __init__(self, Public_Key_Algorithm=None, RSA_Public_Key=None):
        self.Public_Key_Algorithm = Public_Key_Algorithm
        self.RSA_Public_Key = RSA_Public_Key
    def factory(*args_, **kwargs_):
        if SubjectPublicKeyType.subclass:
            return SubjectPublicKeyType.subclass(*args_, **kwargs_)
        else:
            return SubjectPublicKeyType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Public_Key_Algorithm(self): return self.Public_Key_Algorithm
    def set_Public_Key_Algorithm(self, Public_Key_Algorithm): self.Public_Key_Algorithm = Public_Key_Algorithm
    def validate_StringObjectPropertyType(self, value):
        # Validate type cybox_common.StringObjectPropertyType, a restriction on None.
        pass
    def get_RSA_Public_Key(self): return self.RSA_Public_Key
    def set_RSA_Public_Key(self, RSA_Public_Key): self.RSA_Public_Key = RSA_Public_Key
    def hasContent_(self):
        if (
            self.Public_Key_Algorithm is not None or
            self.RSA_Public_Key is not None
            ):
            return True
        else:
            return False
    def export(self, lwrite, level, namespace_='X509CertificateObj:', name_='SubjectPublicKeyType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        showIndent(lwrite, level, pretty_print)
        lwrite('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='SubjectPublicKeyType')
        if self.hasContent_():
            lwrite('>%s' % (eol_, ))
            self.exportChildren(lwrite, level + 1, namespace_, name_, pretty_print=pretty_print)
            showIndent(lwrite, level, pretty_print)
            lwrite('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            lwrite('/>%s' % (eol_, ))
    def exportAttributes(self, lwrite, level, already_processed, namespace_='X509CertificateObj:', name_='SubjectPublicKeyType'):
        pass
    def exportChildren(self, lwrite, level, namespace_='X509CertificateObj:', name_='SubjectPublicKeyType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Public_Key_Algorithm is not None:
            self.Public_Key_Algorithm.export(lwrite, level, 'X509CertificateObj:', name_='Public_Key_Algorithm', pretty_print=pretty_print)
        if self.RSA_Public_Key is not None:
            self.RSA_Public_Key.export(lwrite, level, 'X509CertificateObj:', name_='RSA_Public_Key', pretty_print=pretty_print)
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Public_Key_Algorithm':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Public_Key_Algorithm(obj_)
        elif nodeName_ == 'RSA_Public_Key':
            obj_ = RSAPublicKeyType.factory()
            obj_.build(child_)
            self.set_RSA_Public_Key(obj_)
# end class SubjectPublicKeyType

class ValidityType(GeneratedsSuper):
    """The ValidityType type is the time interval during which the issuer
    warrants that it will maintain information about the status of
    the certificate."""
    
    subclass = None
    superclass = None
    def __init__(self, Not_Before=None, Not_After=None):
        self.Not_Before = Not_Before
        self.Not_After = Not_After
    def factory(*args_, **kwargs_):
        if ValidityType.subclass:
            return ValidityType.subclass(*args_, **kwargs_)
        else:
            return ValidityType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Not_Before(self): return self.Not_Before
    def set_Not_Before(self, Not_Before): self.Not_Before = Not_Before
    def validate_DateTimeObjectPropertyType(self, value):
        # Validate type cybox_common.DateTimeObjectPropertyType, a restriction on None.
        pass
    def get_Not_After(self): return self.Not_After
    def set_Not_After(self, Not_After): self.Not_After = Not_After
    def hasContent_(self):
        if (
            self.Not_Before is not None or
            self.Not_After is not None
            ):
            return True
        else:
            return False
    def export(self, lwrite, level, namespace_='X509CertificateObj:', name_='ValidityType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        showIndent(lwrite, level, pretty_print)
        lwrite('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='ValidityType')
        if self.hasContent_():
            lwrite('>%s' % (eol_, ))
            self.exportChildren(lwrite, level + 1, namespace_, name_, pretty_print=pretty_print)
            showIndent(lwrite, level, pretty_print)
            lwrite('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            lwrite('/>%s' % (eol_, ))
    def exportAttributes(self, lwrite, level, already_processed, namespace_='X509CertificateObj:', name_='ValidityType'):
        pass
    def exportChildren(self, lwrite, level, namespace_='X509CertificateObj:', name_='ValidityType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Not_Before is not None:
            self.Not_Before.export(lwrite, level, 'X509CertificateObj:', name_='Not_Before', pretty_print=pretty_print)
        if self.Not_After is not None:
            self.Not_After.export(lwrite, level, 'X509CertificateObj:', name_='Not_After', pretty_print=pretty_print)
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Not_Before':
            obj_ = cybox_common.DateTimeObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Not_Before(obj_)
        elif nodeName_ == 'Not_After':
            obj_ = cybox_common.DateTimeObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Not_After(obj_)
# end class ValidityType

class RSAPublicKeyType(GeneratedsSuper):
    """The RSAPublicKeyType captures details of RSA public keys."""
    
    subclass = None
    superclass = None
    def __init__(self, Modulus=None, Exponent=None):
        self.Modulus = Modulus
        self.Exponent = Exponent
    def factory(*args_, **kwargs_):
        if RSAPublicKeyType.subclass:
            return RSAPublicKeyType.subclass(*args_, **kwargs_)
        else:
            return RSAPublicKeyType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Modulus(self): return self.Modulus
    def set_Modulus(self, Modulus): self.Modulus = Modulus
    def validate_StringObjectPropertyType(self, value):
        # Validate type cybox_common.StringObjectPropertyType, a restriction on None.
        pass
    def get_Exponent(self): return self.Exponent
    def set_Exponent(self, Exponent): self.Exponent = Exponent
    def validate_IntegerObjectPropertyType(self, value):
        # Validate type cybox_common.IntegerObjectPropertyType, a restriction on None.
        pass
    def hasContent_(self):
        if (
            self.Modulus is not None or
            self.Exponent is not None
            ):
            return True
        else:
            return False
    def export(self, lwrite, level, namespace_='X509CertificateObj:', name_='RSAPublicKeyType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        showIndent(lwrite, level, pretty_print)
        lwrite('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='RSAPublicKeyType')
        if self.hasContent_():
            lwrite('>%s' % (eol_, ))
            self.exportChildren(lwrite, level + 1, namespace_, name_, pretty_print=pretty_print)
            showIndent(lwrite, level, pretty_print)
            lwrite('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            lwrite('/>%s' % (eol_, ))
    def exportAttributes(self, lwrite, level, already_processed, namespace_='X509CertificateObj:', name_='RSAPublicKeyType'):
        pass
    def exportChildren(self, lwrite, level, namespace_='X509CertificateObj:', name_='RSAPublicKeyType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Modulus is not None:
            self.Modulus.export(lwrite, level, 'X509CertificateObj:', name_='Modulus', pretty_print=pretty_print)
        if self.Exponent is not None:
            self.Exponent.export(lwrite, level, 'X509CertificateObj:', name_='Exponent', pretty_print=pretty_print)
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Modulus':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Modulus(obj_)
        elif nodeName_ == 'Exponent':
            obj_ = cybox_common.IntegerObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Exponent(obj_)
# end class RSAPublicKeyType

class X509V3ExtensionsType(GeneratedsSuper):
    """The X509V3ExtensionsType captures the standard X509 V3 Extensions
    that may be used in X509 certificates. Based on RFC 3280,
    "Standard Extensions": http://www.ietf.org/rfc/rfc3280.txt"""
    
    subclass = None
    superclass = None
    def __init__(self, Basic_Constraints=None, Name_Constraints=None, Policy_Constraints=None, Key_Usage=None, Extended_Key_Usage=None, Subject_Key_Identifier=None, Authority_Key_Identifier=None, Subject_Alternative_Name=None, Issuer_Alternative_Name=None, Subject_Directory_Attributes=None, CRL_Distribution_Points=None, Inhibit_Any_Policy=None, Private_Key_Usage_Period=None, Certificate_Policies=None, Policy_Mappings=None):
        self.Basic_Constraints = Basic_Constraints
        self.Name_Constraints = Name_Constraints
        self.Policy_Constraints = Policy_Constraints
        self.Key_Usage = Key_Usage
        self.Extended_Key_Usage = Extended_Key_Usage
        self.Subject_Key_Identifier = Subject_Key_Identifier
        self.Authority_Key_Identifier = Authority_Key_Identifier
        self.Subject_Alternative_Name = Subject_Alternative_Name
        self.Issuer_Alternative_Name = Issuer_Alternative_Name
        self.Subject_Directory_Attributes = Subject_Directory_Attributes
        self.CRL_Distribution_Points = CRL_Distribution_Points
        self.Inhibit_Any_Policy = Inhibit_Any_Policy
        self.Private_Key_Usage_Period = Private_Key_Usage_Period
        self.Certificate_Policies = Certificate_Policies
        self.Policy_Mappings = Policy_Mappings
    def factory(*args_, **kwargs_):
        if X509V3ExtensionsType.subclass:
            return X509V3ExtensionsType.subclass(*args_, **kwargs_)
        else:
            return X509V3ExtensionsType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Basic_Constraints(self): return self.Basic_Constraints
    def set_Basic_Constraints(self, Basic_Constraints): self.Basic_Constraints = Basic_Constraints
    def validate_StringObjectPropertyType(self, value):
        # Validate type cybox_common.StringObjectPropertyType, a restriction on None.
        pass
    def get_Name_Constraints(self): return self.Name_Constraints
    def set_Name_Constraints(self, Name_Constraints): self.Name_Constraints = Name_Constraints
    def get_Policy_Constraints(self): return self.Policy_Constraints
    def set_Policy_Constraints(self, Policy_Constraints): self.Policy_Constraints = Policy_Constraints
    def get_Key_Usage(self): return self.Key_Usage
    def set_Key_Usage(self, Key_Usage): self.Key_Usage = Key_Usage
    def get_Extended_Key_Usage(self): return self.Extended_Key_Usage
    def set_Extended_Key_Usage(self, Extended_Key_Usage): self.Extended_Key_Usage = Extended_Key_Usage
    def get_Subject_Key_Identifier(self): return self.Subject_Key_Identifier
    def set_Subject_Key_Identifier(self, Subject_Key_Identifier): self.Subject_Key_Identifier = Subject_Key_Identifier
    def get_Authority_Key_Identifier(self): return self.Authority_Key_Identifier
    def set_Authority_Key_Identifier(self, Authority_Key_Identifier): self.Authority_Key_Identifier = Authority_Key_Identifier
    def get_Subject_Alternative_Name(self): return self.Subject_Alternative_Name
    def set_Subject_Alternative_Name(self, Subject_Alternative_Name): self.Subject_Alternative_Name = Subject_Alternative_Name
    def get_Issuer_Alternative_Name(self): return self.Issuer_Alternative_Name
    def set_Issuer_Alternative_Name(self, Issuer_Alternative_Name): self.Issuer_Alternative_Name = Issuer_Alternative_Name
    def get_Subject_Directory_Attributes(self): return self.Subject_Directory_Attributes
    def set_Subject_Directory_Attributes(self, Subject_Directory_Attributes): self.Subject_Directory_Attributes = Subject_Directory_Attributes
    def get_CRL_Distribution_Points(self): return self.CRL_Distribution_Points
    def set_CRL_Distribution_Points(self, CRL_Distribution_Points): self.CRL_Distribution_Points = CRL_Distribution_Points
    def get_Inhibit_Any_Policy(self): return self.Inhibit_Any_Policy
    def set_Inhibit_Any_Policy(self, Inhibit_Any_Policy): self.Inhibit_Any_Policy = Inhibit_Any_Policy
    def validate_NonNegativeIntegerObjectPropertyType(self, value):
        # Validate type cybox_common.NonNegativeIntegerObjectPropertyType, a restriction on None.
        pass
    def get_Private_Key_Usage_Period(self): return self.Private_Key_Usage_Period
    def set_Private_Key_Usage_Period(self, Private_Key_Usage_Period): self.Private_Key_Usage_Period = Private_Key_Usage_Period
    def get_Certificate_Policies(self): return self.Certificate_Policies
    def set_Certificate_Policies(self, Certificate_Policies): self.Certificate_Policies = Certificate_Policies
    def get_Policy_Mappings(self): return self.Policy_Mappings
    def set_Policy_Mappings(self, Policy_Mappings): self.Policy_Mappings = Policy_Mappings
    def hasContent_(self):
        if (
            self.Basic_Constraints is not None or
            self.Name_Constraints is not None or
            self.Policy_Constraints is not None or
            self.Key_Usage is not None or
            self.Extended_Key_Usage is not None or
            self.Subject_Key_Identifier is not None or
            self.Authority_Key_Identifier is not None or
            self.Subject_Alternative_Name is not None or
            self.Issuer_Alternative_Name is not None or
            self.Subject_Directory_Attributes is not None or
            self.CRL_Distribution_Points is not None or
            self.Inhibit_Any_Policy is not None or
            self.Private_Key_Usage_Period is not None or
            self.Certificate_Policies is not None or
            self.Policy_Mappings is not None
            ):
            return True
        else:
            return False
    def export(self, lwrite, level, namespace_='X509CertificateObj:', name_='X509V3ExtensionsType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        showIndent(lwrite, level, pretty_print)
        lwrite('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='X509V3ExtensionsType')
        if self.hasContent_():
            lwrite('>%s' % (eol_, ))
            self.exportChildren(lwrite, level + 1, namespace_, name_, pretty_print=pretty_print)
            showIndent(lwrite, level, pretty_print)
            lwrite('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            lwrite('/>%s' % (eol_, ))
    def exportAttributes(self, lwrite, level, already_processed, namespace_='X509CertificateObj:', name_='X509V3ExtensionsType'):
        pass
    def exportChildren(self, lwrite, level, namespace_='X509CertificateObj:', name_='X509V3ExtensionsType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Basic_Constraints is not None:
            self.Basic_Constraints.export(lwrite, level, 'X509CertificateObj:', name_='Basic_Constraints', pretty_print=pretty_print)
        if self.Name_Constraints is not None:
            self.Name_Constraints.export(lwrite, level, 'X509CertificateObj:', name_='Name_Constraints', pretty_print=pretty_print)
        if self.Policy_Constraints is not None:
            self.Policy_Constraints.export(lwrite, level, 'X509CertificateObj:', name_='Policy_Constraints', pretty_print=pretty_print)
        if self.Key_Usage is not None:
            self.Key_Usage.export(lwrite, level, 'X509CertificateObj:', name_='Key_Usage', pretty_print=pretty_print)
        if self.Extended_Key_Usage is not None:
            self.Extended_Key_Usage.export(lwrite, level, 'X509CertificateObj:', name_='Extended_Key_Usage', pretty_print=pretty_print)
        if self.Subject_Key_Identifier is not None:
            self.Subject_Key_Identifier.export(lwrite, level, 'X509CertificateObj:', name_='Subject_Key_Identifier', pretty_print=pretty_print)
        if self.Authority_Key_Identifier is not None:
            self.Authority_Key_Identifier.export(lwrite, level, 'X509CertificateObj:', name_='Authority_Key_Identifier', pretty_print=pretty_print)
        if self.Subject_Alternative_Name is not None:
            self.Subject_Alternative_Name.export(lwrite, level, 'X509CertificateObj:', name_='Subject_Alternative_Name', pretty_print=pretty_print)
        if self.Issuer_Alternative_Name is not None:
            self.Issuer_Alternative_Name.export(lwrite, level, 'X509CertificateObj:', name_='Issuer_Alternative_Name', pretty_print=pretty_print)
        if self.Subject_Directory_Attributes is not None:
            self.Subject_Directory_Attributes.export(lwrite, level, 'X509CertificateObj:', name_='Subject_Directory_Attributes', pretty_print=pretty_print)
        if self.CRL_Distribution_Points is not None:
            self.CRL_Distribution_Points.export(lwrite, level, 'X509CertificateObj:', name_='CRL_Distribution_Points', pretty_print=pretty_print)
        if self.Inhibit_Any_Policy is not None:
            self.Inhibit_Any_Policy.export(lwrite, level, 'X509CertificateObj:', name_='Inhibit_Any_Policy', pretty_print=pretty_print)
        if self.Private_Key_Usage_Period is not None:
            self.Private_Key_Usage_Period.export(lwrite, level, 'X509CertificateObj:', name_='Private_Key_Usage_Period', pretty_print=pretty_print)
        if self.Certificate_Policies is not None:
            self.Certificate_Policies.export(lwrite, level, 'X509CertificateObj:', name_='Certificate_Policies', pretty_print=pretty_print)
        if self.Policy_Mappings is not None:
            self.Policy_Mappings.export(lwrite, level, 'X509CertificateObj:', name_='Policy_Mappings', pretty_print=pretty_print)
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Basic_Constraints':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Basic_Constraints(obj_)
        elif nodeName_ == 'Name_Constraints':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Name_Constraints(obj_)
        elif nodeName_ == 'Policy_Constraints':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Policy_Constraints(obj_)
        elif nodeName_ == 'Key_Usage':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Key_Usage(obj_)
        elif nodeName_ == 'Extended_Key_Usage':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Extended_Key_Usage(obj_)
        elif nodeName_ == 'Subject_Key_Identifier':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Subject_Key_Identifier(obj_)
        elif nodeName_ == 'Authority_Key_Identifier':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Authority_Key_Identifier(obj_)
        elif nodeName_ == 'Subject_Alternative_Name':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Subject_Alternative_Name(obj_)
        elif nodeName_ == 'Issuer_Alternative_Name':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Issuer_Alternative_Name(obj_)
        elif nodeName_ == 'Subject_Directory_Attributes':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Subject_Directory_Attributes(obj_)
        elif nodeName_ == 'CRL_Distribution_Points':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_CRL_Distribution_Points(obj_)
        elif nodeName_ == 'Inhibit_Any_Policy':
            obj_ = cybox_common.NonNegativeIntegerObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Inhibit_Any_Policy(obj_)
        elif nodeName_ == 'Private_Key_Usage_Period':
            obj_ = ValidityType.factory()
            obj_.build(child_)
            self.set_Private_Key_Usage_Period(obj_)
        elif nodeName_ == 'Certificate_Policies':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Certificate_Policies(obj_)
        elif nodeName_ == 'Policy_Mappings':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Policy_Mappings(obj_)
# end class X509V3ExtensionsType

class X509NonStandardExtensionsType(GeneratedsSuper):
    """The NonStandardX509ExtensionsType captures some non-standard or
    deprecated X509 extensions that may be useful. Based on the
    OpenSSL "Deprecated Extensions" documentation: https://www.opens
    sl.org/docs/apps/x509v3_config.html#Deprecated_Extensions. Also
    based on the Alvestrand certificateExtension reference:
    http://www.alvestrand.no/objectid/2.5.29.html"""
    
    subclass = None
    superclass = None
    def __init__(self, Netscape_Comment=None, Netscape_Certificate_Type=None, Old_Authority_Key_Identifier=None, Old_Primary_Key_Attributes=None):
        self.Netscape_Comment = Netscape_Comment
        self.Netscape_Certificate_Type = Netscape_Certificate_Type
        self.Old_Authority_Key_Identifier = Old_Authority_Key_Identifier
        self.Old_Primary_Key_Attributes = Old_Primary_Key_Attributes
    def factory(*args_, **kwargs_):
        if X509NonStandardExtensionsType.subclass:
            return X509NonStandardExtensionsType.subclass(*args_, **kwargs_)
        else:
            return X509NonStandardExtensionsType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Netscape_Comment(self): return self.Netscape_Comment
    def set_Netscape_Comment(self, Netscape_Comment): self.Netscape_Comment = Netscape_Comment
    def validate_StringObjectPropertyType(self, value):
        # Validate type cybox_common.StringObjectPropertyType, a restriction on None.
        pass
    def get_Netscape_Certificate_Type(self): return self.Netscape_Certificate_Type
    def set_Netscape_Certificate_Type(self, Netscape_Certificate_Type): self.Netscape_Certificate_Type = Netscape_Certificate_Type
    def get_Old_Authority_Key_Identifier(self): return self.Old_Authority_Key_Identifier
    def set_Old_Authority_Key_Identifier(self, Old_Authority_Key_Identifier): self.Old_Authority_Key_Identifier = Old_Authority_Key_Identifier
    def get_Old_Primary_Key_Attributes(self): return self.Old_Primary_Key_Attributes
    def set_Old_Primary_Key_Attributes(self, Old_Primary_Key_Attributes): self.Old_Primary_Key_Attributes = Old_Primary_Key_Attributes
    def hasContent_(self):
        if (
            self.Netscape_Comment is not None or
            self.Netscape_Certificate_Type is not None or
            self.Old_Authority_Key_Identifier is not None or
            self.Old_Primary_Key_Attributes is not None
            ):
            return True
        else:
            return False
    def export(self, lwrite, level, namespace_='X509CertificateObj:', name_='X509NonStandardExtensionsType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        showIndent(lwrite, level, pretty_print)
        lwrite('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='X509NonStandardExtensionsType')
        if self.hasContent_():
            lwrite('>%s' % (eol_, ))
            self.exportChildren(lwrite, level + 1, namespace_, name_, pretty_print=pretty_print)
            showIndent(lwrite, level, pretty_print)
            lwrite('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            lwrite('/>%s' % (eol_, ))
    def exportAttributes(self, lwrite, level, already_processed, namespace_='X509CertificateObj:', name_='X509NonStandardExtensionsType'):
        pass
    def exportChildren(self, lwrite, level, namespace_='X509CertificateObj:', name_='X509NonStandardExtensionsType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Netscape_Comment is not None:
            self.Netscape_Comment.export(lwrite, level, 'X509CertificateObj:', name_='Netscape_Comment', pretty_print=pretty_print)
        if self.Netscape_Certificate_Type is not None:
            self.Netscape_Certificate_Type.export(lwrite, level, 'X509CertificateObj:', name_='Netscape_Certificate_Type', pretty_print=pretty_print)
        if self.Old_Authority_Key_Identifier is not None:
            self.Old_Authority_Key_Identifier.export(lwrite, level, 'X509CertificateObj:', name_='Old_Authority_Key_Identifier', pretty_print=pretty_print)
        if self.Old_Primary_Key_Attributes is not None:
            self.Old_Primary_Key_Attributes.export(lwrite, level, 'X509CertificateObj:', name_='Old_Primary_Key_Attributes', pretty_print=pretty_print)
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Netscape_Comment':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Netscape_Comment(obj_)
        elif nodeName_ == 'Netscape_Certificate_Type':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Netscape_Certificate_Type(obj_)
        elif nodeName_ == 'Old_Authority_Key_Identifier':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Old_Authority_Key_Identifier(obj_)
        elif nodeName_ == 'Old_Primary_Key_Attributes':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Old_Primary_Key_Attributes(obj_)
# end class X509NonStandardExtensionsType

class X509CertificateObjectType(cybox_common.ObjectPropertiesType):
    """The X509CertificateObjectType type is intended to characterize X.509
    certificates."""
    
    subclass = None
    superclass = cybox_common.ObjectPropertiesType
    def __init__(self, object_reference=None, Custom_Properties=None, xsi_type=None, Certificate=None, Raw_Certificate=None, Certificate_Signature=None):
        super(X509CertificateObjectType, self).__init__(object_reference, Custom_Properties, xsi_type )
        self.Certificate = Certificate
        self.Raw_Certificate = Raw_Certificate
        self.Certificate_Signature = Certificate_Signature
    def factory(*args_, **kwargs_):
        if X509CertificateObjectType.subclass:
            return X509CertificateObjectType.subclass(*args_, **kwargs_)
        else:
            return X509CertificateObjectType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Certificate(self): return self.Certificate
    def set_Certificate(self, Certificate): self.Certificate = Certificate
    def get_Certificate_Signature(self): return self.Certificate_Signature
    def set_Certificate_Signature(self, Certificate_Signature): self.Certificate_Signature = Certificate_Signature
    def hasContent_(self):
        if (
            self.Certificate is not None or
            self.Raw_Certificate is not None or
            self.Certificate_Signature is not None or
            super(X509CertificateObjectType, self).hasContent_()
            ):
            return True
        else:
            return False
    def export(self, lwrite, level, namespace_='X509CertificateObj:', name_='X509CertificateObjectType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        showIndent(lwrite, level, pretty_print)
        lwrite('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(lwrite, level, already_processed, namespace_, name_='X509CertificateObjectType')
        if self.hasContent_():
            lwrite('>%s' % (eol_, ))
            self.exportChildren(lwrite, level + 1, namespace_, name_, pretty_print=pretty_print)
            showIndent(lwrite, level, pretty_print)
            lwrite('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            lwrite('/>%s' % (eol_, ))
    def exportAttributes(self, lwrite, level, already_processed, namespace_='X509CertificateObj:', name_='X509CertificateObjectType'):
        super(X509CertificateObjectType, self).exportAttributes(lwrite, level, already_processed, namespace_, name_='X509CertificateObjectType')
    def exportChildren(self, lwrite, level, namespace_='X509CertificateObj:', name_='X509CertificateObjectType', fromsubclass_=False, pretty_print=True):
        super(X509CertificateObjectType, self).exportChildren(lwrite, level, 'X509CertificateObj:', name_, True, pretty_print=pretty_print)
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Certificate is not None:
            self.Certificate.export(lwrite, level, 'X509CertificateObj:', name_='Certificate', pretty_print=pretty_print)
        if self.Raw_Certificate is not None:
            self.Raw_Certificate.export(lwrite, level, 'X509CertificateObj:', name_='Raw_Certificate', pretty_print=pretty_print)
        if self.Certificate_Signature is not None:
            self.Certificate_Signature.export(lwrite, level, 'X509CertificateObj:', name_='Certificate_Signature', pretty_print=pretty_print)
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        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(X509CertificateObjectType, self).buildAttributes(node, attrs, already_processed)
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Certificate':
            obj_ = X509CertificateContentsType.factory()
            obj_.build(child_)
            self.set_Certificate(obj_)
        elif nodeName_ == 'Raw_Certificate':
            obj_ = cybox_common.StringObjectPropertyType.factory()
            obj_.build(child_)
            self.set_Raw_Certificate(obj_)
        elif nodeName_ == 'Certificate_Signature':
            obj_ = X509CertificateSignatureType.factory()
            obj_.build(child_)
            self.set_Certificate_Signature(obj_)
        super(X509CertificateObjectType, self).buildChildren(child_, node, nodeName_, True)
# end class X509CertificateObjectType

GDSClassesMapping = {
    'Build_Utility': cybox_common.BuildUtilityType,
    'Errors': cybox_common.ErrorsType,
    'Error': cybox_common.ErrorType,
    'Policy_Mappings': cybox_common.StringObjectPropertyType,
    'Certificate_Issuer': cybox_common.StringObjectPropertyType,
    'Signature_Algorithm': cybox_common.StringObjectPropertyType,
    'Metadata': cybox_common.MetadataType,
    'Hash': cybox_common.HashType,
    'Old_Authority_Key_Identifier': cybox_common.StringObjectPropertyType,
    'Information_Source_Type': cybox_common.ControlledVocabularyStringType,
    'Segment_Hash': cybox_common.HashValueType,
    'Internal_Strings': cybox_common.InternalStringsType,
    'Fuzzy_Hash_Structure': cybox_common.FuzzyHashStructureType,
    'SubDatum': cybox_common.MetadataType,
    'Extended_Key_Usage': cybox_common.StringObjectPropertyType,
    'Digital_Signature': cybox_common.DigitalSignatureInfoType,
    'Code_Snippets': cybox_common.CodeSnippetsType,
    'Value': cybox_common.StringObjectPropertyType,
    'Subject_Directory_Attributes': cybox_common.StringObjectPropertyType,
    'Length': cybox_common.IntegerObjectPropertyType,
    'Inhibit_Any_Policy': cybox_common.NonNegativeIntegerObjectPropertyType,
    'Encoding': cybox_common.ControlledVocabularyStringType,
    'Internationalization_Settings': cybox_common.InternationalizationSettingsType,
    'Image_Offset': cybox_common.IntegerObjectPropertyType,
    'Netscape_Certificate_Type': cybox_common.StringObjectPropertyType,
    'English_Translation': cybox_common.StringObjectPropertyType,
    'Segments': cybox_common.HashSegmentsType,
    'Subject': cybox_common.StringObjectPropertyType,
    'Name_Constraints': cybox_common.StringObjectPropertyType,
    'Functions': cybox_common.FunctionsType,
    'String_Value': cybox_common.StringObjectPropertyType,
    'Build_Utility_Platform_Specification': cybox_common.PlatformSpecificationType,
    'Compiler_Informal_Description': cybox_common.CompilerInformalDescriptionType,
    'System': cybox_common.ObjectPropertiesType,
    'Platform': cybox_common.PlatformSpecificationType,
    'Version': cybox_common.IntegerObjectPropertyType,
    'Usage_Context_Assumptions': cybox_common.UsageContextAssumptionsType,
    'Type': cybox_common.ControlledVocabularyStringType,
    'Not_Before': cybox_common.DateTimeObjectPropertyType,
    'Compilers': cybox_common.CompilersType,
    'Tool_Type': cybox_common.ControlledVocabularyStringType,
    'String': cybox_common.ExtractedStringType,
    'Custom_Properties': cybox_common.CustomPropertiesType,
    'Build_Information': cybox_common.BuildInformationType,
    'Tool_Hashes': cybox_common.HashListType,
    'Serial_Number': cybox_common.StringObjectPropertyType,
    'Certificate_Policies': cybox_common.StringObjectPropertyType,
    'Error_Instances': cybox_common.ErrorInstancesType,
    'Data_Segment': cybox_common.StringObjectPropertyType,
    'Certificate_Subject': cybox_common.StringObjectPropertyType,
    'Signature': cybox_common.StringObjectPropertyType,
    'Property': cybox_common.PropertyType,
    'Strings': cybox_common.ExtractedStringsType,
    'Contributors': cybox_common.PersonnelType,
    'Not_After': cybox_common.DateTimeObjectPropertyType,
    'Reference_Description': cybox_common.StructuredTextType,
    'User_Account_Info': cybox_common.ObjectPropertiesType,
    'Configuration_Settings': cybox_common.ConfigurationSettingsType,
    'Compiler_Platform_Specification': cybox_common.PlatformSpecificationType,
    'Byte_String_Value': cybox_common.HexBinaryObjectPropertyType,
    'Exponent': cybox_common.IntegerObjectPropertyType,
    'Instance': cybox_common.ObjectPropertiesType,
    'Import': cybox_common.StringObjectPropertyType,
    'Identifier': cybox_common.PlatformIdentifierType,
    'Tool_Specific_Data': cybox_common.ToolSpecificDataType,
    'Execution_Environment': cybox_common.ExecutionEnvironmentType,
    'Search_Distance': cybox_common.IntegerObjectPropertyType,
    'Old_Primary_Key_Attributes': cybox_common.StringObjectPropertyType,
    'Dependencies': cybox_common.DependenciesType,
    'Segment_Count': cybox_common.IntegerObjectPropertyType,
    'Offset': cybox_common.IntegerObjectPropertyType,
    'Date': cybox_common.DateRangeType,
    'Hashes': cybox_common.HashListType,
    'Configuration_Setting': cybox_common.ConfigurationSettingType,
    'Language': cybox_common.StringObjectPropertyType,
    'Usage_Context_Assumption': cybox_common.StructuredTextType,
    'Block_Hash': cybox_common.FuzzyHashBlockType,
    'Dependency': cybox_common.DependencyType,
    'Time': cybox_common.TimeType,
    'Public_Key_Algorithm': cybox_common.StringObjectPropertyType,
    'Trigger_Point': cybox_common.HexBinaryObjectPropertyType,
    'Environment_Variable': cybox_common.EnvironmentVariableType,
    'Byte_Run': cybox_common.ByteRunType,
    'Libraries': cybox_common.LibrariesType,
    'File_System_Offset': cybox_common.IntegerObjectPropertyType,
    'Tool_Configuration': cybox_common.ToolConfigurationType,
    'Imports': cybox_common.ImportsType,
    'Code_Snippet': cybox_common.ObjectPropertiesType,
    'Library': cybox_common.LibraryType,
    'CRL_Distribution_Points': cybox_common.StringObjectPropertyType,
    'References': cybox_common.ToolReferencesType,
    'Netscape_Comment': cybox_common.StringObjectPropertyType,
    'Issuer': cybox_common.StringObjectPropertyType,
    'Block_Hash_Value': cybox_common.HashValueType,
    'Issuer_Alternative_Name': cybox_common.StringObjectPropertyType,
    'Basic_Constraints': cybox_common.StringObjectPropertyType,
    'Subject_Key_Identifier': cybox_common.StringObjectPropertyType,
    'Key_Usage': cybox_common.StringObjectPropertyType,
    'Modulus': cybox_common.StringObjectPropertyType,
    'Function': cybox_common.StringObjectPropertyType,
    'Description': cybox_common.StructuredTextType,
    'Build_Configuration': cybox_common.BuildConfigurationType,
    'Subject_Alternative_Name': cybox_common.StringObjectPropertyType,
    'Address': cybox_common.HexBinaryObjectPropertyType,
    'Search_Within': cybox_common.IntegerObjectPropertyType,
    'Segment': cybox_common.HashSegmentType,
    'Compiler': cybox_common.CompilerType,
    'Name': cybox_common.StringObjectPropertyType,
    'Signature_Description': cybox_common.StringObjectPropertyType,
    'Block_Size': cybox_common.IntegerObjectPropertyType,
    'Simple_Hash_Value': cybox_common.SimpleHashValueType,
    'Authority_Key_Identifier': cybox_common.StringObjectPropertyType,
    'Fuzzy_Hash_Value': cybox_common.FuzzyHashValueType,
    'Data_Size': cybox_common.DataSizeType,
    'Dependency_Description': cybox_common.StructuredTextType,
    'Policy_Constraints': cybox_common.StringObjectPropertyType,
    'Contributor': cybox_common.ContributorType,
    'Tools': cybox_common.ToolsInformationType,
    'Tool': cybox_common.ToolInformationType,
}

USAGE_TEXT = """
Usage: python <Parser>.py [ -s ] <in_xml_file>
"""

def usage():
    print USAGE_TEXT
    sys.exit(1)

def get_root_tag(node):
    tag = Tag_pattern_.match(node.tag).groups()[-1]
    rootClass = GDSClassesMapping.get(tag)
    if rootClass is None:
        rootClass = globals().get(tag)
    return tag, rootClass

def parse(inFileName):
    doc = parsexml_(inFileName)
    rootNode = doc.getroot()
    rootTag, rootClass = get_root_tag(rootNode)
    if rootClass is None:
        rootTag = 'X509_Certificate'
        rootClass = X509CertificateObjectType
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    # Enable Python to collect the space used by the DOM.
    doc = None
#    sys.stdout.write('<?xml version="1.0" ?>\n')
#    rootObj.export(sys.stdout.write, 0, name_=rootTag,
#        namespacedef_='',
#        pretty_print=True)
    return rootObj

def parseEtree(inFileName):
    doc = parsexml_(inFileName)
    rootNode = doc.getroot()
    rootTag, rootClass = get_root_tag(rootNode)
    if rootClass is None:
        rootTag = 'X509_Certificate'
        rootClass = X509CertificateObjectType
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    # Enable Python to collect the space used by the DOM.
    doc = None
    rootElement = rootObj.to_etree(None, name_=rootTag)
    content = etree_.tostring(rootElement, pretty_print=True,
        xml_declaration=True, encoding="utf-8")
    sys.stdout.write(content)
    sys.stdout.write('\n')
    return rootObj, rootElement

def parseString(inString):
    from StringIO import StringIO
    doc = parsexml_(StringIO(inString))
    rootNode = doc.getroot()
    rootTag, rootClass = get_root_tag(rootNode)
    if rootClass is None:
        rootTag = 'X509_Certificate'
        rootClass = X509CertificateObjectType
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    # Enable Python to collect the space used by the DOM.
    doc = None
#    sys.stdout.write('<?xml version="1.0" ?>\n')
#    rootObj.export(sys.stdout.write, 0, name_="X509_Certificate",
#        namespacedef_='')
    return rootObj

def main():
    args = sys.argv[1:]
    if len(args) == 1:
        parse(args[0])
    else:
        usage()

if __name__ == '__main__':
    #import pdb; pdb.set_trace()
    main()

__all__ = [
    "X509CertificateObjectType",
    "X509CertificateContentsType",
    "X509CertificateSignatureType",
    "SubjectPublicKeyType",
    "ValidityType",
    "RSAPublicKeyType",
    "X509V3ExtensionsType",
    "X509NonStandardExtensionsType"
    ]
