def callback(context, name, ob): # get the callbacks registred by the inner services # and call them from here when the @resource classes are being # scanned by venusian. config = context.config.with_package(info.module) # Storage is mandatory for resources. if not hasattr(config.registry, 'storage'): msg = 'Mandatory storage backend is missing from configuration.' raise pyramid_exceptions.ConfigurationError(msg) services = [ register_service('collection', config.registry.settings), register_service('record', config.registry.settings) ] for service in services: config.add_cornice_service(service)
def callback(context, name, ob): # get the callbacks registred by the inner services # and call them from here when the @resource classes are being # scanned by venusian. config = context.config.with_package(info.module) # Storage is mandatory for resources. if not hasattr(config.registry, 'storage'): msg = 'Mandatory storage backend is missing from configuration.' raise pyramid_exceptions.ConfigurationError(msg) # A service for the list. service = register_service('collection', config.registry.settings) config.add_cornice_service(service) # An optional one for record endpoint. if getattr(viewset, 'record_path') is not None: service = register_service('record', config.registry.settings) config.add_cornice_service(service)
def read_settings(settings, options, prefix=''): """Reads the `settings` dictionnary, and sets defaults using the provided list of tuples in `options`. :param settings: settings to read. :param options: a list of tuples (name, required, default). :param prefix: prefix for the settings keys. :returns: a dictionnary with defaults set. :raises: :exc:`~pyramid:pyramid.exceptions.ConfigurationError` if a required setting is not provided. """ result = {} for name, required, default in options: setting = prefix + name try: result[name] = settings[setting] except KeyError: if required: error_msg = "%s is required" % setting raise pyramid_exceptions.ConfigurationError(error_msg) result[name] = default return result