# 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 template.format(match.group('uid'))

    if idutils.is_orcid(uid) and schema in (None, 'ORCID'):
        return idutils.normalize_orcid(uid), 'ORCID'

    if schema and schema not in _RE_AUTHORS_UID:
        # Schema explicitly specified, but this function can't handle it
        raise UnknownUIDSchema(uid)

    if schema:
        normalized_uid = _get_uid_normalized_in_schema(uid, schema)
        if normalized_uid:
            return normalized_uid, schema
        else:
            raise SchemaUIDConflict(schema, uid)

    match_schema, normalized_uid = None, None
    for candidate_schema in _RE_AUTHORS_UID:
        candidate_uid = _get_uid_normalized_in_schema(uid, candidate_schema)
        if candidate_uid:
            if match_schema:
                # Valid against more than one candidate schema, ambiguous
                raise UnknownUIDSchema(uid)
            match_schema = candidate_schema
            normalized_uid = candidate_uid

    if match_schema:
        return normalized_uid, match_schema

    # No guessess have been found

# 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 template.format(match.group('uid'))

    if idutils.is_orcid(uid) and schema in (None, 'ORCID'):
        return idutils.normalize_orcid(uid), 'ORCID'

    if schema and schema not in _RE_AUTHORS_UID:
        # Schema explicitly specified, but this function can't handle it
        raise UnknownUIDSchema(uid)

    if schema:
        normalized_uid = _get_uid_normalized_in_schema(uid, schema)
        if normalized_uid:
            return normalized_uid, schema
        else:
            raise SchemaUIDConflict(schema, uid)

    match_schema, normalized_uid = None, None
    for candidate_schema in _RE_AUTHORS_UID:
        candidate_uid = _get_uid_normalized_in_schema(uid, candidate_schema)
        if candidate_uid:
            if match_schema:
                # Valid against more than one candidate schema, ambiguous
                raise UnknownUIDSchema(uid)
            match_schema = candidate_schema
            normalized_uid = candidate_uid

    if match_schema:
        return normalized_uid, match_schema

    # No guessess have been found

    raise UnknownUIDSchema(uid)