def get_penalty_model(specification):
    """Retrieve a PenaltyModel from one of the available factories.

    Args:
        specification (:class:`.Specification`): The specification
            for the desired PenaltyModel.

    Returns:
        :class:`.PenaltyModel`/None: A PenaltyModel as returned by
        the highest priority factory, or None if no factory could
        produce it.

    Raises:
        :exc:`ImpossiblePenaltyModel`: If the specification
            describes a penalty model that cannot be built by any
            factory.

    """

    # Iterate through the available factories until one gives a penalty model
    for factory in iter_factories():
        try:
            pm = factory(specification)
        except ImpossiblePenaltyModel as e:
            # information about impossible models should be propagated
            raise e
        except FactoryException:
            # any other type of factory exception, continue through the list
            continue

        # if penalty model was found, broadcast to all of the caches. This could be done
        # asynchronously
        for cache in iter_caches():
            cache(pm)

        return pm

    return None
def get_penalty_model ( specification ) : for factory in iter_factories ( ) : try : pm = factory ( specification ) except ImpossiblePenaltyModel as e : raise e except FactoryException : continue for cache in iter_caches ( ) : cache ( pm ) return pm return None
Retrieve a PenaltyModel from one of the available factories.

    Args:
        specification (:class:`.Specification`): The specification
            for the desired PenaltyModel.

    Returns:
        :class:`.PenaltyModel`/None: A PenaltyModel as returned by
        the highest priority factory, or None if no factory could
        produce it.

    Raises:
        :exc:`ImpossiblePenaltyModel`: If the specification
            describes a penalty model that cannot be built by any
            factory.