# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ A set of custom types for oslo.config. """ import ast import os import re from django.utils import encoding from django.utils import functional from django.utils.module_loading import import_string from django.utils.translation import pgettext_lazy from oslo_config import types class Maybe(types.ConfigType): """A custom option type for a value that may be None.""" def __init__(self, type_): self.type_ = type_ type_name = getattr(type_, 'type_name', 'unknown value') super().__init__('optional %s' % type_name) def __call__(self, value): if value is None: return None return self.type_(value) def _formatter(self, value): if value is None: return '' return self.type_._formatter(value) class URL(types.ConfigType): """A custom option type for a URL or part of URL.""" CLEAN_SLASH_RE = re.compile(r'(?