Example #1
0
static size_t parse_size(const kora::config_t &value) {
	size_t ret = 0;
	if (value.underlying_object().is_uint()) {
		ret = value.to<size_t>();
	} else if (value.underlying_object().is_string()) {
		ret = parse_size(value.to<std::string>());
	} else {
		throw elliptics::config::config_error(value.path() + " must be specified");
	}

	if (ret == 0) {
		throw elliptics::config::config_error(value.path() + " must be non-zero");
	}
	return ret;
}
Example #2
0
	mm::namespace_state_t::user_settings_ptr_t
	user_settings_factory(const std::string &name, const kora::config_t &config) {
		gil_guard_t gil_guard;

		auto settings = detail::convert(config.underlying_object().as_object(), gil_guard);

		if (ns_filter) {
			try {
				if (!ns_filter(name, settings)) {
					return nullptr;
				}
			} catch (const std::exception &ex) {
				// ns_filter can throw python object that must be destroyed during gil is locked
				// that is during gil_guard is not out of scope.
				throw std::runtime_error(std::string{"ns_filter error: "} + ex.what());
			}
		}

		std::unique_ptr<namespace_state_t::user_settings_t> result{
			new namespace_state_t::user_settings_t{std::move(settings), gil_guard}
		};

		return mm::namespace_state_t::user_settings_ptr_t(std::move(result));
	}