# Path: libtaxii/common.py
# def parse(s, allow_file=True, allow_url=False):
#     """
#     Uses the default parser to parse a string or file-like object
# 
#     :param s: The XML String or File-like object to parse.
#     :param allow_file: Allow `s` to be a file path.
#     :param allow_url: Allow `s` to be a URL.
#     :return: an etree._Element
#     """
#     # Do a simple validation that the given string (or URL)
#     # has no protocol specified. Anything without parseable protocol
#     # will be interpreted by lxml as string instead or path of external URL.
#     if not allow_url and isinstance(s, six.string_types):
#         parsed = urlparse(s)
#         if parsed.scheme:
#             raise ValueError('external URLs are not allowed')
# 
#     parser = get_xml_parser()
# 
#     # parse from string if no external paths allowed
#     if not allow_file and not allow_url:
#         return etree.fromstring(s, parser)
# 
#     # try to parse from file or string if files are allowed
#     try:
#         return etree.parse(s, parser).getroot()
#     except IOError:
#         return etree.XML(s, parser)
# 
# def parse_datetime_string(datetime_string):
#     """Parse a string into a :py:class:`datetime.datetime`.
# 
#     libtaxii users should not need to use this function directly.
#     """
#     if not datetime_string:
#         return None
#     return dateutil.parser.parse(datetime_string)


import collections
import re
import datetime
import os
import six
from lxml import etree
from .common import (parse, parse_datetime_string)

    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:

# Path: libtaxii/common.py
# def parse(s, allow_file=True, allow_url=False):
#     """
#     Uses the default parser to parse a string or file-like object
# 
#     :param s: The XML String or File-like object to parse.
#     :param allow_file: Allow `s` to be a file path.
#     :param allow_url: Allow `s` to be a URL.
#     :return: an etree._Element
#     """
#     # Do a simple validation that the given string (or URL)
#     # has no protocol specified. Anything without parseable protocol
#     # will be interpreted by lxml as string instead or path of external URL.
#     if not allow_url and isinstance(s, six.string_types):
#         parsed = urlparse(s)
#         if parsed.scheme:
#             raise ValueError('external URLs are not allowed')
# 
#     parser = get_xml_parser()
# 
#     # parse from string if no external paths allowed
#     if not allow_file and not allow_url:
#         return etree.fromstring(s, parser)
# 
#     # try to parse from file or string if files are allowed
#     try:
#         return etree.parse(s, parser).getroot()
#     except IOError:
#         return etree.XML(s, parser)
# 
# def parse_datetime_string(datetime_string):
#     """Parse a string into a :py:class:`datetime.datetime`.
# 
#     libtaxii users should not need to use this function directly.
#     """
#     if not datetime_string:
#         return None
#     return dateutil.parser.parse(datetime_string)


# Path: libtaxii/validation.py
import collections
import re
import datetime
import os
import six
from lxml import etree
from .common import (parse, parse_datetime_string)


    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)