# Path: inspire_schemas/errors.py
# class SchemaKeyNotFound(InspireSchemasException):
#     """Exception raised on missing schema key."""
# 
#     def __init__(self, data):
#         """Exception raised on missing schema key.
# 
#         :param data: data dict that was checked.
#         """
#         message = 'Unable to find "$schema" key in "{}".'.format(data)
#         super(SchemaKeyNotFound, self).__init__(message)
# 
# class SchemaNotFound(InspireSchemasException):
#     """Exception raised on missing schema."""
# 
#     def __init__(self, schema):
#         """Exception raised on missing schema.
# 
#         :param schema: the schema that was requested.
#         """
#         message = 'Unable to find schema "{}"'.format(
#             schema)
#         super(SchemaNotFound, self).__init__(message)
# 
# class SchemaUIDConflict(InspireSchemasException):
#     """Exception raised when a UID is not matching provided schema."""
# 
#     def __init__(self, schema, uid):
#         """Exception raised when a UID is not matching provided schema.
# 
#         Args:
#             schema (string): given schema
#             uid (string): UID which conflicts the schema
#         """
#         message = 'UID "{}" is not of the schema "{}".'.format(uid, schema)
#         super(SchemaUIDConflict, self).__init__(message)
# 
# class UnknownUIDSchema(InspireSchemasException):
#     """Exception raised when a schema of a UID is unknown."""
# 
#     def __init__(self, uid):
#         """Exception raised when a schema of a UID is unknown.
# 
#         Args:
#             uid (string): given UID
#         """
#         message = 'Schema of UID "{}" is unrecognized.'.format(uid)
#         super(UnknownUIDSchema, self).__init__(message)


import copy
import json
import os
import re
import idutils
import rfc3987
import six
from collections import defaultdict
from functools import partial, wraps
from bleach.linkifier import LinkifyFilter
from bleach.sanitizer import Cleaner
from idutils import is_orcid
from inspire_utils.date import PartialDate
from isbn import ISBN
from jsonschema import Draft4Validator, RefResolver, draft4_format_checker
from jsonschema import validate as jsonschema_validate
from pkg_resources import resource_filename
from pytz import UnknownTimeZoneError, timezone
from six.moves.urllib.parse import urlsplit
from unidecode import unidecode
from .errors import (SchemaKeyNotFound, SchemaNotFound, SchemaUIDConflict,
                     UnknownUIDSchema)
    return schema_data


inspire_format_checker = draft4_format_checker
inspire_format_checker.checks('date', raises=ValueError)(PartialDate.loads)
inspire_format_checker.checks('uri-reference', raises=ValueError)(
    partial(rfc3987.parse, rule='URI_reference')
)
inspire_format_checker.checks('orcid')(is_orcid)
inspire_format_checker.checks('timezone', raises=UnknownTimeZoneError)(timezone)


def _load_schema_for_record(data, schema=None):
    """Load the schema from a given record.

    Args:
        data (dict): record data.
        schema (Union[dict, str]): schema to validate against.

    Returns:
        dict: the loaded schema.

    Raises:
        SchemaNotFound: if the given schema was not found.
        SchemaKeyNotFound: if ``schema`` is ``None`` and no ``$schema`` key was
            found in ``data``.
        jsonschema.SchemaError: if the schema is invalid.
    """
    if schema is None:
        if '$schema' not in data:

# Path: inspire_schemas/errors.py
# class SchemaKeyNotFound(InspireSchemasException):
#     """Exception raised on missing schema key."""
# 
#     def __init__(self, data):
#         """Exception raised on missing schema key.
# 
#         :param data: data dict that was checked.
#         """
#         message = 'Unable to find "$schema" key in "{}".'.format(data)
#         super(SchemaKeyNotFound, self).__init__(message)
# 
# class SchemaNotFound(InspireSchemasException):
#     """Exception raised on missing schema."""
# 
#     def __init__(self, schema):
#         """Exception raised on missing schema.
# 
#         :param schema: the schema that was requested.
#         """
#         message = 'Unable to find schema "{}"'.format(
#             schema)
#         super(SchemaNotFound, self).__init__(message)
# 
# class SchemaUIDConflict(InspireSchemasException):
#     """Exception raised when a UID is not matching provided schema."""
# 
#     def __init__(self, schema, uid):
#         """Exception raised when a UID is not matching provided schema.
# 
#         Args:
#             schema (string): given schema
#             uid (string): UID which conflicts the schema
#         """
#         message = 'UID "{}" is not of the schema "{}".'.format(uid, schema)
#         super(SchemaUIDConflict, self).__init__(message)
# 
# class UnknownUIDSchema(InspireSchemasException):
#     """Exception raised when a schema of a UID is unknown."""
# 
#     def __init__(self, uid):
#         """Exception raised when a schema of a UID is unknown.
# 
#         Args:
#             uid (string): given UID
#         """
#         message = 'Schema of UID "{}" is unrecognized.'.format(uid)
#         super(UnknownUIDSchema, self).__init__(message)


# Path: inspire_schemas/utils.py
import copy
import json
import os
import re
import idutils
import rfc3987
import six
from collections import defaultdict
from functools import partial, wraps
from bleach.linkifier import LinkifyFilter
from bleach.sanitizer import Cleaner
from idutils import is_orcid
from inspire_utils.date import PartialDate
from isbn import ISBN
from jsonschema import Draft4Validator, RefResolver, draft4_format_checker
from jsonschema import validate as jsonschema_validate
from pkg_resources import resource_filename
from pytz import UnknownTimeZoneError, timezone
from six.moves.urllib.parse import urlsplit
from unidecode import unidecode
from .errors import (SchemaKeyNotFound, SchemaNotFound, SchemaUIDConflict,
                     UnknownUIDSchema)

    return schema_data


inspire_format_checker = draft4_format_checker
inspire_format_checker.checks('date', raises=ValueError)(PartialDate.loads)
inspire_format_checker.checks('uri-reference', raises=ValueError)(
    partial(rfc3987.parse, rule='URI_reference')
)
inspire_format_checker.checks('orcid')(is_orcid)
inspire_format_checker.checks('timezone', raises=UnknownTimeZoneError)(timezone)


def _load_schema_for_record(data, schema=None):
    """Load the schema from a given record.

    Args:
        data (dict): record data.
        schema (Union[dict, str]): schema to validate against.

    Returns:
        dict: the loaded schema.

    Raises:
        SchemaNotFound: if the given schema was not found.
        SchemaKeyNotFound: if ``schema`` is ``None`` and no ``$schema`` key was
            found in ``data``.
        jsonschema.SchemaError: if the schema is invalid.
    """
    if schema is None:
        if '$schema' not in data:

            raise SchemaKeyNotFound(data=data)