Source code for parameter_info.network_info

# Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
# **InsertLicense** code author="Jan-Martin Kuhnigk"

from parameter_info.indirect_info import raise_InformationSourceKeyError, IndirectParameterInfo, InformationSource


[docs]class MlabNetworkInfoSource( InformationSource ): """ Can query a MeVisLab network for field values. Do not inherit CachedInformationSourceQ since it currently does not support automatic cache invalidation on (field) value change. Also, it is usually not necessary, as field value computation is cheap. """ def __init__(self, context, field_not_found_error_handler=raise_InformationSourceKeyError, **source_query_data): """ :param context: Network context to look for the keys (=field names) in. :param field_not_found_error_handler: Executed on query execution if the field does not exist in the contect. :param source_query_data: Any additional, non field-specific information required to retrieve the information. """ source_query_data["context"] = context super( MlabNetworkInfoSource, self ).__init__( source_key_failure_handler=field_not_found_error_handler, **source_query_data ) @classmethod def _get_from_source(cls, field_name, **source_query_data): information_source_data = source_query_data.pop("context") if not information_source_data.hasField(field_name): raise cls.InformationSourceKeyError( "Invalid key parameter provided to {}.get_from_source(): '{}'"\ " field not found in network!".format( cls.__name__, field_name) ) return information_source_data.field(field_name).value
[docs]def createMlabNetworkInfo(context, field_not_found_error_handler=raise_InformationSourceKeyError): """ Convenience method to create an IndirectParameterInfo (non-cached, as caching does not make sense for field values) from the provided network context wrapped by a MlabNetworkInfoSource object. :param context: Network context to look for the keys (=field names) in. :param field_not_found_error_handler: Executed on query execution if the field does not exist in the contect. """ return IndirectParameterInfo( MlabNetworkInfoSource( context, field_not_found_error_handler=field_not_found_error_handler ) )