# 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 unittest
import warnings
import inspect
import libtaxii as t
import libtaxii.messages_10 as tm10
import six
import sys
from dateutil.tz import tzutc
from lxml import etree
from libtaxii.validation import SchemaValidator
from libtaxii.constants import *

    if block_from_xml != block_from_dict:
        print('\t Failure of test #3 - running equals w/ debug:')
        block_from_xml.__eq__(block_from_dict, True)
        raise Exception('Test #3 failed - block_from_xml != block_from_dict')
    if block_from_json != block_from_dict:
        print('\t Failure of test #3 - running equals w/ debug:')
        block_from_json.__eq__(block_from_dict, True)
        raise Exception('Test #3 failed - block_from_json != block_from_dict')

    print('***** All tests completed!')


class DiscoveryRequestTests(unittest.TestCase):

    def test_discovery_request(self):
        discovery_request1 = tm10.DiscoveryRequest(
            message_id=tm10.generate_message_id(),  # Required
            # Extended headers are optional for every message type, but only demonstrated here
            extended_headers={'ext_header1': 'value1', 'ext_header2': 'value2'})  # Optional.

        round_trip_message(discovery_request1)


class DiscoveryResponseTests(unittest.TestCase):

    def test_discovery_response(self):
        service_instance1 = tm10.ServiceInstance(
            service_type=SVC_INBOX,  # Required
            services_version=VID_TAXII_SERVICES_10,  # Required

# 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_10_test.py
import datetime
import unittest
import warnings
import inspect
import libtaxii as t
import libtaxii.messages_10 as tm10
import six
import sys
from dateutil.tz import tzutc
from lxml import etree
from libtaxii.validation import SchemaValidator
from libtaxii.constants import *


    if block_from_xml != block_from_dict:
        print('\t Failure of test #3 - running equals w/ debug:')
        block_from_xml.__eq__(block_from_dict, True)
        raise Exception('Test #3 failed - block_from_xml != block_from_dict')
    if block_from_json != block_from_dict:
        print('\t Failure of test #3 - running equals w/ debug:')
        block_from_json.__eq__(block_from_dict, True)
        raise Exception('Test #3 failed - block_from_json != block_from_dict')

    print('***** All tests completed!')


class DiscoveryRequestTests(unittest.TestCase):

    def test_discovery_request(self):
        discovery_request1 = tm10.DiscoveryRequest(
            message_id=tm10.generate_message_id(),  # Required
            # Extended headers are optional for every message type, but only demonstrated here
            extended_headers={'ext_header1': 'value1', 'ext_header2': 'value2'})  # Optional.

        round_trip_message(discovery_request1)


class DiscoveryResponseTests(unittest.TestCase):

    def test_discovery_response(self):
        service_instance1 = tm10.ServiceInstance(
            service_type=SVC_INBOX,  # Required
            services_version=VID_TAXII_SERVICES_10,  # Required

            protocol_binding=VID_TAXII_HTTP_10,  # Required