# Path: libtaxii/validation.py
# class SchemaValidator(object):
#     """
#     A helper class for TAXII Schema Validation.
# 
#     Example:
#         See validate_etree(...) for an example how to use this class
#     """
# 
#     # Create class-level variables equal to module-level variables for
#     # backwards-compatibility
#     TAXII_10_SCHEMA = TAXII_10_SCHEMA
#     TAXII_11_SCHEMA = TAXII_11_SCHEMA
# 
#     def __init__(self, schema_file):
#         """
#         Args:
#             schema_file (str) - The file location of the schema to
#                                 validate against. Use the TAXII_11_SCHEMA
#                                 and TAXII_10_SCHEMA constants to validate
#                                 against TAXII 1.1 / 1.0. This schema file
#                                 will be used when validate_file/string/etree
#                                 is used.
#         """
#         schema_doc = parse(schema_file, allow_file=True)
#         self.xml_schema = etree.XMLSchema(schema_doc)
# 
#     def validate_file(self, file_location):
#         """
#         A wrapper for validate_etree. Parses file_location,
#         turns it into an etree, then calls validate_etree( ... )
#         """
# 
#         with open(file_location, 'r') as f:
#             etree_xml = parse(f, allow_file=True)
# 
#         return self.validate_etree(etree_xml)
# 
#     def validate_string(self, xml_string):
#         """
#         A wrapper for validate_etree. Parses xml_string,
#         turns it into an etree, then calls validate_etree( ... )
#         """
#         etree_xml = parse(xml_string, allow_file=False)
#         return self.validate_etree(etree_xml)
# 
#     def validate_etree(self, etree_xml):
#         """Validate an LXML etree with the specified schema_file.
# 
#         Args:
#             etree_xml (etree): The XML to validate.
#             schema_file (str): The schema file to validate against
# 
#         Returns:
#             A SchemaValidationResult object
# 
#         Raises:
#             lxml.etree.XMLSyntaxError: When the XML to be validated is not well formed
# 
#         Example:
#             .. code-block:: python
# 
#                 from libtaxii import messages_11
#                 from libtaxii.validation import SchemaValidator, TAXII_11_SCHEMA
#                 from lxml.etree import XMLSyntaxError
# 
#                 sv = SchemaValidator(TAXII_11_SCHEMA)
# 
#                 try:
#                    result = sv.validate_etree(some_etree)
#                    # Note that validate_string() and validate_file() can also be used
#                 except XMLSyntaxError:
#                     # Handle this exception, which occurs when
#                     # some_xml_string is not valid XML (e.g., 'foo')
# 
#                 if not result.valid:
#                     for error in result.error_log:
#                         print error
#                     sys.exit(1)
# 
#                 # At this point, the XML is schema valid
#                 do_something(some_xml_string)
#         """
#         valid = self.xml_schema.validate(etree_xml)
#         return SchemaValidationResult(valid, self.xml_schema.error_log)


import datetime
import io
import sys
import unittest
import warnings
import inspect
import libtaxii as t
import libtaxii.messages_11 as tm11
import libtaxii.taxii_default_query as tdq
import six
import sys
from dateutil.tz import tzutc
from lxml import etree
from libtaxii.validation import SchemaValidator
from libtaxii.constants import *
from libtaxii.common import *
            collection_name='collection2',  # Required
            subscription_id='id1')  # Optional for ACT_STATUS
        # subscription_parameters, delivery_parameters prohibited if action != SUBSCRIBE

        round_trip_message(subs_req8)

    def test_subs_req9(self):
        # https://github.com/TAXIIProject/libtaxii/pull/237
        subscription = """{"content_bindings": [{"binding_id": "urn:stix.mitre.org:xml:1.2"}], "query": null, "response_type": "FULL"}"""
        subscription_dict = json.loads(subscription)
        subscription_parameters9 = tm11.SubscriptionParameters(**subscription_dict)  # Use all the defaults
        subs_req9 = tm11.ManageCollectionSubscriptionRequest(
            message_id='SubsReq09',  # Required
            action=ACT_SUBSCRIBE,  # Required
            collection_name='collection2',  # Required
            # subscription_id = None, #Prohibited for action = SUBSCRIBE
            subscription_parameters=subscription_parameters9)  # optional - absence means there are not any subscription parameters
        # delivery_parameters = None)#Optional - absence means push messaging not requested

        round_trip_message(subs_req9)


class ManageCollectionSubscriptionResponseTests(unittest.TestCase):

    def setUp(self):
        poll_instance1 = tm11.PollInstance(
            poll_protocol=VID_TAXII_HTTPS_10,
            poll_address='https://example.com/poll1/',
            poll_message_bindings=[VID_TAXII_XML_11])


# Path: libtaxii/validation.py
# class SchemaValidator(object):
#     """
#     A helper class for TAXII Schema Validation.
# 
#     Example:
#         See validate_etree(...) for an example how to use this class
#     """
# 
#     # Create class-level variables equal to module-level variables for
#     # backwards-compatibility
#     TAXII_10_SCHEMA = TAXII_10_SCHEMA
#     TAXII_11_SCHEMA = TAXII_11_SCHEMA
# 
#     def __init__(self, schema_file):
#         """
#         Args:
#             schema_file (str) - The file location of the schema to
#                                 validate against. Use the TAXII_11_SCHEMA
#                                 and TAXII_10_SCHEMA constants to validate
#                                 against TAXII 1.1 / 1.0. This schema file
#                                 will be used when validate_file/string/etree
#                                 is used.
#         """
#         schema_doc = parse(schema_file, allow_file=True)
#         self.xml_schema = etree.XMLSchema(schema_doc)
# 
#     def validate_file(self, file_location):
#         """
#         A wrapper for validate_etree. Parses file_location,
#         turns it into an etree, then calls validate_etree( ... )
#         """
# 
#         with open(file_location, 'r') as f:
#             etree_xml = parse(f, allow_file=True)
# 
#         return self.validate_etree(etree_xml)
# 
#     def validate_string(self, xml_string):
#         """
#         A wrapper for validate_etree. Parses xml_string,
#         turns it into an etree, then calls validate_etree( ... )
#         """
#         etree_xml = parse(xml_string, allow_file=False)
#         return self.validate_etree(etree_xml)
# 
#     def validate_etree(self, etree_xml):
#         """Validate an LXML etree with the specified schema_file.
# 
#         Args:
#             etree_xml (etree): The XML to validate.
#             schema_file (str): The schema file to validate against
# 
#         Returns:
#             A SchemaValidationResult object
# 
#         Raises:
#             lxml.etree.XMLSyntaxError: When the XML to be validated is not well formed
# 
#         Example:
#             .. code-block:: python
# 
#                 from libtaxii import messages_11
#                 from libtaxii.validation import SchemaValidator, TAXII_11_SCHEMA
#                 from lxml.etree import XMLSyntaxError
# 
#                 sv = SchemaValidator(TAXII_11_SCHEMA)
# 
#                 try:
#                    result = sv.validate_etree(some_etree)
#                    # Note that validate_string() and validate_file() can also be used
#                 except XMLSyntaxError:
#                     # Handle this exception, which occurs when
#                     # some_xml_string is not valid XML (e.g., 'foo')
# 
#                 if not result.valid:
#                     for error in result.error_log:
#                         print error
#                     sys.exit(1)
# 
#                 # At this point, the XML is schema valid
#                 do_something(some_xml_string)
#         """
#         valid = self.xml_schema.validate(etree_xml)
#         return SchemaValidationResult(valid, self.xml_schema.error_log)


# Path: libtaxii/test/messages_11_test.py
import datetime
import io
import sys
import unittest
import warnings
import inspect
import libtaxii as t
import libtaxii.messages_11 as tm11
import libtaxii.taxii_default_query as tdq
import six
import sys
from dateutil.tz import tzutc
from lxml import etree
from libtaxii.validation import SchemaValidator
from libtaxii.constants import *
from libtaxii.common import *

            collection_name='collection2',  # Required
            subscription_id='id1')  # Optional for ACT_STATUS
        # subscription_parameters, delivery_parameters prohibited if action != SUBSCRIBE

        round_trip_message(subs_req8)

    def test_subs_req9(self):
        # https://github.com/TAXIIProject/libtaxii/pull/237
        subscription = """{"content_bindings": [{"binding_id": "urn:stix.mitre.org:xml:1.2"}], "query": null, "response_type": "FULL"}"""
        subscription_dict = json.loads(subscription)
        subscription_parameters9 = tm11.SubscriptionParameters(**subscription_dict)  # Use all the defaults
        subs_req9 = tm11.ManageCollectionSubscriptionRequest(
            message_id='SubsReq09',  # Required
            action=ACT_SUBSCRIBE,  # Required
            collection_name='collection2',  # Required
            # subscription_id = None, #Prohibited for action = SUBSCRIBE
            subscription_parameters=subscription_parameters9)  # optional - absence means there are not any subscription parameters
        # delivery_parameters = None)#Optional - absence means push messaging not requested

        round_trip_message(subs_req9)


class ManageCollectionSubscriptionResponseTests(unittest.TestCase):

    def setUp(self):
        poll_instance1 = tm11.PollInstance(
            poll_protocol=VID_TAXII_HTTPS_10,
            poll_address='https://example.com/poll1/',
            poll_message_bindings=[VID_TAXII_XML_11])


        poll_instance2 = tm11.PollInstance(