React to given (AMQP) message.

    This function is used by :mod:`edeposit.amqp.alephdaemon`. It works as
    highlevel wrapper for whole module.

    Example:
        >>> import aleph

        >>> request = aleph.SearchRequest(
        ...     aleph.ISBNQuery("80-251-0225-4")
        ... )
        >>> request
        SearchRequest(query=ISBNQuery(ISBN='80-251-0225-4', base='nkc'))

        >>> response = aleph.reactToAMQPMessage(request, None)

        >>> response  # formated by hand for purposes of example
        SearchResult(
            records=[
                AlephRecord(
                    base='nkc',
                    library='NKC01',
                    docNumber=1492461,
                    xml='HERE IS WHOLE MARC OAI RECORD',
                    epublication=EPublication(
                        ISBN=['80-251-0225-4'],
                        nazev='Umění programování v UNIXu /',
                        podnazev='',
                        vazba='(bro\xc5\xbe.) :',
                        cena='K\xc4\x8d 590,00',
                        castDil='',
                        nazevCasti='',
                        nakladatelVydavatel='Computer Press,',
                        datumVydani='2004',
                        poradiVydani='1. vyd.',
                        zpracovatelZaznamu='BOA001',
                        format='23 cm',
                        url='',
                        mistoVydani='Brno :',
                        ISBNSouboruPublikaci=[],
                        autori=[
                            Author(
                                firstName='Eric S.',
                                lastName='Raymond',
                                title=''
                            )
                        ],
                        originaly=[
                            'Art of UNIX programming'
                        ],
                        internal_url=''
                    )
                )
            ]
        )

    Args:
        req (Request class): Any of the Request class from
                          :class:`aleph.datastructures.requests`.
        send_back (fn reference): Reference to function for responding. This is
                  useful for progress monitoring for example. Function takes
                  one parameter, which may be response structure/namedtuple, or
                  string or whatever would be normally returned.

    Returns:
        Result class: Result of search in Aleph. \
                      See :mod:`aleph.datastructures.results` submodule.

    Raises:
        ValueError: If bad type of `req` structure is given.

def reactToAMQPMessage(req, send_back):
    """
    React to given (AMQP) message.

    This function is used by :mod:`edeposit.amqp.alephdaemon`. It works as
    highlevel wrapper for whole module.

    Example:
        >>> import aleph

        >>> request = aleph.SearchRequest(
        ...     aleph.ISBNQuery("80-251-0225-4")
        ... )
        >>> request
        SearchRequest(query=ISBNQuery(ISBN='80-251-0225-4', base='nkc'))

        >>> response = aleph.reactToAMQPMessage(request, None)

        >>> response  # formated by hand for purposes of example
        SearchResult(
            records=[
                AlephRecord(
                    base='nkc',
                    library='NKC01',
                    docNumber=1492461,
                    xml='HERE IS WHOLE MARC OAI RECORD',
                    epublication=EPublication(
                        ISBN=['80-251-0225-4'],
                        nazev='Umění programování v UNIXu /',
                        podnazev='',
                        vazba='(bro\xc5\xbe.) :',
                        cena='K\xc4\x8d 590,00',
                        castDil='',
                        nazevCasti='',
                        nakladatelVydavatel='Computer Press,',
                        datumVydani='2004',
                        poradiVydani='1. vyd.',
                        zpracovatelZaznamu='BOA001',
                        format='23 cm',
                        url='',
                        mistoVydani='Brno :',
                        ISBNSouboruPublikaci=[],
                        autori=[
                            Author(
                                firstName='Eric S.',
                                lastName='Raymond',
                                title=''
                            )
                        ],
                        originaly=[
                            'Art of UNIX programming'
                        ],
                        internal_url=''
                    )
                )
            ]
        )

    Args:
        req (Request class): Any of the Request class from
                          :class:`aleph.datastructures.requests`.
        send_back (fn reference): Reference to function for responding. This is
                  useful for progress monitoring for example. Function takes
                  one parameter, which may be response structure/namedtuple, or
                  string or whatever would be normally returned.

    Returns:
        Result class: Result of search in Aleph. \
                      See :mod:`aleph.datastructures.results` submodule.

    Raises:
        ValueError: If bad type of `req` structure is given.
    """
    if not _iiOfAny(req, REQUEST_TYPES):
        raise ValueError(
            "Unknown type of request: '" + str(type(req)) + "'!"
        )

    if _iiOfAny(req, CountRequest) and _iiOfAny(req.query, QUERY_TYPES):
        return req.query.getCountResult()

    elif _iiOfAny(req, SearchRequest) and _iiOfAny(req.query, QUERY_TYPES):
        return req.query.getSearchResult()

    elif _iiOfAny(req, ISBNValidationRequest):
        ISBN = req.ISBN

        if _iiOfAny(ISBN, ISBNQuery):
            ISBN = ISBN.ISBN

        return ISBNValidationResult(isbn_validator.is_valid_isbn(ISBN))

    elif _iiOfAny(req, ExportRequest):
        export.exportEPublication(req.epublication)
        return ExportResult(req.epublication.ISBN)

    raise ValueError(
        "Unknown type of request: '" + str(type(req)) + "' or query: '" +
        str(type(req.query)) + "'!"
    )