
    ce                       d Z ddlZddlZddlmZ ddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZ	 ddlZddlmZ ddlmZ ddlmc mZ ddlmZ ddlZ ej0                  e      ZdZ G d d	ej8                        Z ej<                  d
ddg      Z G d de       Z! G d de!      Z" G d de!      Z# G d de!e$      Z% G d de!      Z& G d de!      Z' G d de!      Z( G d de!      Z) G d de!      Z* G d d e!      Z+ G d! d"e!      Z, G d# d$e!      Z- G d% d&e!e.      Z/ G d' d(e/      Z0 G d) d*e!e.      Z1d+ Z2did,Z3djd-Z4d. Z5dkd/Z6dld0Z7d1 Z8 e9ejt                  jw                  d2            Z<dmd3Z=d4 Z>d5 Z?d6 Z@ej                   G d7 d8             ZB G d9 d:      ZC G d; d<eB      ZD G d= d>eB      ZE G d? d@eB      ZF G dA dBeB      ZG G dC dDeB      ZH G dE dFeB      ZI G dG dHeB      ZJ G dI dJeB      ZK G dK dLeB      ZL G dM dNeB      ZM G dO dPeB      ZN G dQ dReB      ZO G dS dTeB      ZP G dU dVeP      ZQ G dW dXeB      ZR G dY dZeB      ZS G d[ d\eB      ZT G d] d^      ZU G d_ d`ej                        ZV G da dbej                        ZX G dc ddej                        ZZ G de dfej                        Z\ G dg dhej                        Z^ e^       Z_y# e$ r dZY w xY w)nzPrimary module in oslo_config.
    N)abc)	iniparser)sources)typesz?The name of the driver that can load this configuration source.c                   *    e Zd ZdZdZdZdZdZdZd Z	y)		Locations)   F)   F)   F)   T)   T)   Tc                      || _         || _        y N)numis_user_controlled)selfr   r   s      1/usr/lib/python3/dist-packages/oslo_config/cfg.py__init__zLocations.__init__A   s    "4    N)
__name__
__module____qualname__opt_defaultset_defaultset_overrideusercommand_lineenvironmentr    r   r   r   r   9   s%    KKLDLK5r   r   LocationInfolocationdetailc                       e Zd ZdZddZd Zy)ErrorzBase class for cfg exceptions.Nc                     || _         y r   msg)r   r(   s     r   r   zError.__init__L   s	    r   c                     | j                   S r   r'   r   s    r   __str__zError.__str__O   s    xxr   r   r   r   r   __doc__r   r+   r    r   r   r%   r%   I   s    (r   r%   c                       e Zd ZdZd Zy)NotInitializedErrorz(Raised if parser is not initialized yet.c                      y)Nz.call expression on parser has not been invokedr    r*   s    r   r+   zNotInitializedError.__str__V   s    ?r   Nr   r   r   r-   r+   r    r   r   r/   r/   S   s    2@r   r/   c                       e Zd ZdZd Zy)ArgsAlreadyParsedErrorz0Raised if a CLI opt is registered after parsing.c                 F    d}| j                   r|d| j                   z   z  }|S )Nzarguments already parsed: r'   )r   rets     r   r+   zArgsAlreadyParsedError.__str__]   s%    (884$((?"C
r   Nr1   r    r   r   r3   r3   Z   s
    :r   r3   c                       e Zd ZdZddZd Zy)NoSuchOptErrorz3Raised if an opt which doesn't exist is referenced.Nc                      || _         || _        y r   opt_namegroupr   r;   r<   s      r   r   zNoSuchOptError.__init__g        
r   c                 p    | j                   dn| j                   j                  }d| j                  d|dS )NDEFAULTzno such option  in group []r<   namer;   r   
group_names     r   r+   zNoSuchOptError.__str__k   s)    "&**"4Y$**//
48MM:NNr   r   r,   r    r   r   r8   r8   d   s    =Or   r8   c                       e Zd ZdZd Zd Zy)NoSuchGroupErrorz4Raised if a group which doesn't exist is referenced.c                     || _         y r   rF   rE   s     r   r   zNoSuchGroupError.__init__s   	    $r   c                      d| j                   z  S )Nzno such group [%s]rJ   r*   s    r   r+   zNoSuchGroupError.__str__v   s    #doo55r   Nr,   r    r   r   rH   rH   p   s    >%6r   rH   c                       e Zd ZdZd Zd Zy)DuplicateOptErrorz:Raised if multiple opts with the same name are registered.c                     || _         y r   r;   )r   r;   s     r   r   zDuplicateOptError.__init__}   s	     r   c                      d| j                   z  S )Nzduplicate option: %srP   r*   s    r   r+   zDuplicateOptError.__str__   s    %55r   Nr,   r    r   r   rN   rN   z   s    D!6r   rN   c                       e Zd ZdZddZd Zy)RequiredOptErrorzERaised if an option is required but no value is supplied by the user.Nc                      || _         || _        y r   r:   r=   s      r   r   zRequiredOptError.__init__   r>   r   c                 p    | j                   dn| j                   j                  }d| j                  d|dS )Nr@   zvalue required for option rA   rB   rC   rE   s     r   r+   zRequiredOptError.__str__   s0    "&**"4Y$**//
?C}}?IK 	Kr   r   r,   r    r   r   rS   rS      s    OKr   rS   c                       e Zd ZdZd Zy)TemplateSubstitutionErrorzBRaised if an error occurs substituting a variable in an opt value.c                      d| j                   z  S )Nztemplate substitution error: %sr'   r*   s    r   r+   z!TemplateSubstitutionError.__str__   s    0488;;r   Nr1   r    r   r   rW   rW      s
    L<r   rW   c                       e Zd ZdZd Zd Zy)ConfigFilesNotFoundErrorz1Raised if one or more config files are not found.c                     || _         y r   config_filesr   r]   s     r   r   z!ConfigFilesNotFoundError.__init__   
    (r   c                 >    ddj                  | j                        z  S )Nz$Failed to find some config files: %s,joinr]   r*   s    r   r+   z ConfigFilesNotFoundError.__str__   !    6**+, 	-r   Nr,   r    r   r   rZ   rZ      s    ;)-r   rZ   c                       e Zd ZdZd Zd Zy) ConfigFilesPermissionDeniedErrorz4Raised if one or more config files are not readable.c                     || _         y r   r\   r^   s     r   r   z)ConfigFilesPermissionDeniedError.__init__   r_   r   c                 >    ddj                  | j                        z  S )Nz$Failed to open some config files: %sra   rb   r*   s    r   r+   z(ConfigFilesPermissionDeniedError.__str__   rd   r   Nr,   r    r   r   rf   rf      s    >)-r   rf   c                       e Zd ZdZd Zd Zy)ConfigDirNotFoundErrorz0Raised if the requested config-dir is not found.c                     || _         y r   
config_dir)r   rm   s     r   r   zConfigDirNotFoundError.__init__   rK   r   c                      d| j                   z  S )Nz(Failed to read config file directory: %srl   r*   s    r   r+   zConfigDirNotFoundError.__str__   s    :T__LMr   Nr,   r    r   r   rj   rj      s    :%Nr   rj   c                       e Zd ZdZd Zd Zy)ConfigFileParseErrorz2Raised if there is an error parsing a config file.c                      || _         || _        y r   config_filer(   )r   rs   r(   s      r   r   zConfigFileParseError.__init__   s    &r   c                 :    d| j                   d| j                  S )NzFailed to parse r5   rr   r*   s    r   r+   zConfigFileParseError.__str__   s    +/+;+;TXXFFr   Nr,   r    r   r   rp   rp      s    <Gr   rp   c                       e Zd ZdZy)ConfigSourceValueErrorz<Raised if a config source value does not match its opt type.Nr   r   r   r-   r    r   r   rv   rv      s    Fr   rv   c                       e Zd ZdZy)ConfigFileValueErrorz:Raised if a config file value does not match its opt type.Nrw   r    r   r   ry   ry      s    Dr   ry   c                       e Zd ZdZy)DefaultValueErrorz:Raised if a default config type does not fit the opt type.Nrw   r    r   r   r{   r{      s    Dr   r{   c                 z    t         j                  j                  t         j                  j                  |             S )z3Apply tilde expansion and absolutization to a path.)ospathabspath
expanduser)ps    r   _fixpathr      s$    77??277--a011r   c           
         t         j                  j                  d      }t         j                  j                  d      }| r,t        t         j                  j                  dd| z               ndt        d      | r t         j                  j                  d|       ndd|r#| r!t         j                  j                  |d|       nd|r#| r!t         j                  j                  |d|       ndg}|D cg c]  }|s|	 c}S c c}w )a  Return a list of directories where config files may be located.

    :param project: an optional project name

    If a project is specified, following directories are returned::

      ~/.${project}/
      ~/
      /etc/${project}/
      /etc/

    If a project is specified and installed from a snap package, following
    directories are also returned:

      ${SNAP_COMMON}/etc/${project}
      ${SNAP}/etc/${project}

    Otherwise, if project is not specified, these directories are returned:

      ~/
      /etc/
    SNAPSNAP_COMMON~.Nz/etcetc)r}   environgetr   r~   rc   )projectsnapsnap_ccfg_dirsxs        r   _get_config_dirsr      s    . ::>>&!DZZ^^M*F 7>c3=124)0VW%d067VUG,.2wT5'*DH  %!1A%%%s   .C=6C=c                     | D ]I  }t         j                  j                  |||      }t         j                  j                  |      sG|c S  y)a  Search a list of directories for a given filename or directory name.

    Iterator over the supplied directories, returning the first file
    found with the supplied name and extension.

    :param dirs: a list of directories
    :param basename: the filename or directory name, for example 'glance-api'
    :param extension: the file extension, for example '.conf'
    :returns: the path to a matching file or directory, or None
    N)r}   r~   rc   exists)dirsbasename	extensiondr~   s        r   _search_dirsr      sA      ww||A9=>77>>$Kr   c                     |Ft         j                  j                  t        j                  d         }|j                  d      r|d d }t        |       fd| |fD        }|D cg c]  }|s|	 c}S c c}w )Nr   .pyc              3   <   K   | ]  }|rt        |        y wr   )r   ).0r   r   r   s     r   	<genexpr>z%_find_config_files.<locals>.<genexpr>  s$      3 !1i8 3s   )r}   r~   r   sysargvendswithr   )r   progr   r]   r   r   s     `  @r   _find_config_filesr     sp    |ww,==9D(H3%t_3L $)!qA)))s   (A70A7c                     t        | ||      S )a  Return a list of default configuration files.

    :param project: an optional project name
    :param prog: the program name, defaulting to the basename of
        sys.argv[0], without extension .py
    :param extension: the type of the config file

    We default to two config files: [${project}.conf, ${prog}.conf]

    And we look for those config files in the following directories::

      ~/.${project}/
      ~/
      /etc/${project}/
      /etc/
      ${SNAP_COMMON}/etc/${project}
      ${SNAP}/etc/${project}

    We return an absolute path for (at most) one of each the default config
    files, for the topmost directory it exists in.

    For example, if project=foo, prog=bar and /etc/foo/foo.conf, /etc/bar.conf
    and ~/.foo/bar.conf all exist, then we return ['/etc/foo/foo.conf',
    '~/.foo/bar.conf']

    If no project name is supplied, we only look for ${prog}.conf.
    r   r   r   r   s      r   find_config_filesr     s    8 gtY77r   c                     t        | ||      S )a  Return a list of default configuration dirs.

    :param project: an optional project name
    :param prog: the program name, defaulting to the basename of
        sys.argv[0], without extension .py
    :param extension: the type of the config directory. Defaults to '.conf.d'

    We default to two config dirs: [${project}.conf.d/, ${prog}.conf.d/].
    If no project name is supplied, we only look for ${prog.conf.d/}.

    And we look for those config dirs in the following directories::

      ~/.${project}/
      ~/
      /etc/${project}/
      /etc/
      ${SNAP_COMMON}/etc/${project}
      ${SNAP}/etc/${project}

    We return an absolute path for each of the two config dirs,
    in the first place we find it (iff we find it).

    For example, if project=foo, prog=bar and /etc/foo/foo.conf.d/,
    /etc/bar.conf.d/ and ~/.foo/bar.conf.d/ all exist, then we return
    ['/etc/foo/foo.conf.d/', '~/.foo/bar.conf.d/']
    r   r   s      r   find_config_dirsr   8  s    6 gtY77r   c                 v    |j                   | v r+| |j                      d   |k7  rt        |j                        yy)a  Check whether an opt with the same name is already registered.

    The same opt may be registered multiple times, with only the first
    registration having any effect. However, it is an error to attempt
    to register a different opt with the same name.

    :param opts: the set of opts already registered
    :param opt: the opt to be registered
    :returns: True if the opt was previously registered, False otherwise
    :raises: DuplicateOptError if a naming conflict is detected
    optTF)destrN   rD   )optsr   s     r   _is_opt_registeredr   V  s:     xx4>% C'#CHH--r   OSLO_CONFIG_SHOW_CODE_LOCATIONSc                 x    t         syt        j                         d| dz    }	 ||    }	 |d   ~~S # ~w xY w# ~w xY w)zReturn a string describing where this is being called from.

    :param n: Number of steps up the stack to look. Defaults to ``2``.
    :type n: int
    :returns: str
    Nr	   )_show_caller_detailsinspectstack)nsframes      r   _get_caller_detailr   n  sM      QA!	8  s   6 0 6 36 9c                     | D ]L  }|j                   |v s||j                      |_        t        t        j                  t                     |_        N y r   )r   defaultr!   r   r   r   _set_location)r   kwargsr   s      r   set_defaultsr     sK     C88v *CK ,Y-B-B-?-A!CCCr   c                 0    | dk(  r| S | j                         S Nr@   )lowerrJ   s    r   _normalize_group_namer     s    Yr   c                 x    t         rddl m} |j                  t        | |       yt        j	                  | |       y)a  Report use of a deprecated option

    Uses versionutils from oslo.log if it is available.  If not, logs
    a simple warning message.

    :param format_str: The message to use for the report
    :param format_dict: A dict containing keys for any parameters in format_str
    r   )versionutilsN)oslo_logr   report_deprecated_featureLOGwarning)
format_strformat_dictr   s      r   _report_deprecationr     s1     
 	*..sJ/:	< 	J,r   c                       e Zd ZdZdZ	 	 	 	 	 	 	 ddZd Zd Zd Zd Z	d	 Z
ej                  Zd
 ZddZ	 ddZd Zd Zd ZddZd Zy)Opta  Base class for all configuration options.

    The only required parameter is the option's name. However, it is
    common to also supply a default and help string for all options.

    :param name: the option's name
    :param type: the option's type. Must be a callable object that takes string
                 and returns converted and validated value
    :param dest: the name of the corresponding :class:`.ConfigOpts` property
    :param short: a single character CLI option name
    :param default: the default value of the option
    :param positional: True if the option is a positional CLI argument
    :param metavar: the option argument to show in --help
    :param help: an explanation of how the option is used
    :param secret: true if the value should be obfuscated in log output
    :param required: true if a value must be supplied for this option
    :param deprecated_name: deprecated name option.  Acts like an alias
    :param deprecated_group: the group containing a deprecated alias
    :param deprecated_opts: list of :class:`.DeprecatedOpt`
    :param sample_default: a default string for sample config files
    :param deprecated_for_removal: indicates whether this opt is planned for
                                   removal in a future release
    :param deprecated_reason: indicates why this opt is planned for removal in
                              a future release. Silently ignored if
                              deprecated_for_removal is False
    :param deprecated_since: indicates which release this opt was deprecated
                             in. Accepts any string, though valid version
                             strings are encouraged. Silently ignored if
                             deprecated_for_removal is False
    :param mutable: True if this option may be reloaded
    :param advanced: a bool True/False value if this option has advanced usage
                             and is not normally used by the majority of users

    An Opt object has no public methods, but has a number of public properties:

    .. py:attribute:: name

        the name of the option, which may include hyphens

    .. py:attribute:: type

        a callable object that takes string and returns converted and
        validated value.  Default types are available from
        :class:`oslo_config.types`

    .. py:attribute:: dest

        the (hyphen-less) :class:`.ConfigOpts` property which contains the
        option value

    .. py:attribute:: short

        a single character CLI option name

    .. py:attribute:: default

        the default value of the option

    .. py:attribute:: sample_default

        a sample default value string to include in sample config files

    .. py:attribute:: positional

        True if the option is a positional CLI argument

    .. py:attribute:: metavar

        the name shown as the argument to a CLI option in --help output

    .. py:attribute:: help

        a string explaining how the option's value is used

    .. py:attribute:: advanced

        in sample files, a bool value indicating the option is advanced

    .. versionchanged:: 1.2
       Added *deprecated_opts* parameter.

    .. versionchanged:: 1.4
       Added *sample_default* parameter.

    .. versionchanged:: 1.9
       Added *deprecated_for_removal* parameter.

    .. versionchanged:: 2.7
       An exception is now raised if the default value has the wrong type.

    .. versionchanged:: 3.2
       Added *deprecated_reason* parameter.

    .. versionchanged:: 3.5
       Added *mutable* parameter.

    .. versionchanged:: 3.12
       Added *deprecated_since* parameter.

    .. versionchanged:: 3.15
       Added *advanced* parameter and attribute.
    FNc           	      \   |j                  d      rt        d|d      || _        |t        j                         }t        |      st        d      || _        |
|rdnd}
|"| j                  j                  dd      | _	        n|| _	        || _
        || _        || _        || _        || _        || _        |	| _        |
| _        || _        || _        || _        d| _        | j,                  t.        u rd}nd	}t1        t2        j4                  t7        |            | _        t;        j<                  |      xs g | _        | j>                  D ][  }d|j                  v s| j>                  jA                  tC        |j                  j                  dd      |jD                  
             ] ||b| j>                  jA                  tC        ||
             |r:d|v r6| j>                  jA                  tC        |j                  dd      |
             | jG                          || _$        || _%        y )N_zillegal name z with prefix _ztype must be callableTF-r
   r   r<   )&
startswith
ValueErrorrD   r   Stringcallable	TypeErrortypereplacer   shortr   sample_default
positionalmetavarhelpsecretrequireddeprecated_for_removaldeprecated_reasondeprecated_since_logged_deprecation	__class__r   r!   r   r   r   r   copydeepcopydeprecated_optsappendDeprecatedOptr<   _check_defaultmutableadvanced)r   rD   r   r   r   r   r   r   r   r   r   deprecated_namedeprecated_groupr   r   r   r   r   r   r   stack_depthos                         r   r   zOpt.__init__  s    ??3FGG	<<<>D~344	 )tuH<		))#s3DIDI
,$	 &<#!2 0#( >>S KK)!!{+

  $}}_=C%% 	$Aaff}$$++MFFNN3,''-# $	$
 &*:*F  ''o<L)N O3/#9$$++M#++C5*-, - 	 r   c                     t        | j                  t              r0| j                  j                  dd      j                  dd      }d|v S y)z/Check if default is a reference to another var.\$ $$$F)
isinstancer   strr   )r   tmpls     r   _default_is_refzOpt._default_is_refX  s@    dllC(<<''r2::4DD$;r   c                     | j                   .| j                         s	 | j                  | j                          y y y # t        $ r& t	        d| j                   | j                  dz        w xY w)NzCError processing default value %(default)s for Opt type of %(opt)s.)r   r   )r   r   r   	Exceptionr{   r*   s    r   r   zOpt._check_default_  ss    LL$,,.>		$,,' / %  >' )O6:ll26))+=)= > >>s	   < /A+c                 <    t        t        |             }d|v r|d= |S )Nr   )dictvars)r   vs     r   _vars_for_cmpzOpt._vars_for_cmpj  s)    
 d a/"r   c                 D    | j                         |j                         k7  S r   r   r   anothers     r   __ne__z
Opt.__ne__z      !!#w'<'<'>>>r   c                 D    | j                         |j                         k(  S r   r   r   s     r   __eq__z
Opt.__eq__}  r  r   c                    || j                   fg}|| j                  f}| j                  D ]D  }|j                  |j                  }}|s|s |j	                  |r|n||r|n| j                   f       F |j                  || j                  | j                  |      \  }}	| j                  ra| j                  sUd| _	        |xs d}
| j                  rdj                  | j                        }nd}d}| j                   |
|d}t        ||       ||	fS )zRetrieves the option value from a _Namespace object.

        :param namespace: a _Namespace object
        :param group_name: a group name
        )multir   current_nameTr@   z ({})r   zOption "%(option)s" from group "%(group)s" is deprecated for removal%(reason)s.  Its value may be silently ignored in the future.)optionr<   reason)r   rD   r   r<   r   
_get_valuer  r   r   r   r   formatr   )r   	namespacerF   namesr  r   dnamedgroupvaluelocpretty_grouppretty_reasonr   r   s                 r   _get_from_namespacezOpt._get_from_namespace  s    dii()"DII.'' 	>CHHcii6EfJ',e$))= >	> ))\ * C
s
 &&t/G/G'+D$%2L%% 't/E/E F "?J &*YY$0%24K  
K8s|r   c           
         | j                  ||      }| j                  |      }| j                  d|r|j                  nd      }g }| j                  D ]<  }| j                  |j                  |j                        }|,|j                  |       > | j                  ||| j                  | j                  ||| j                  |       y)a}  Makes the option available in the command line interface.

        This is the method ConfigOpts uses to add the opt to the CLI interface
        as appropriate for the opt type. Some opt types may extend this method,
        others may just extend the helper methods it uses.

        :param parser: the CLI option parser
        :param group: an optional OptGroup object
        r   N)_get_argparse_container_get_argparse_kwargs_get_argparse_prefixrD   r   _get_deprecated_cli_namer<   r   _add_to_argparser   r   	r   parserr<   	containerr   prefixdeprecated_namesr   r   s	            r   _add_to_clizOpt._add_to_cli  s     00?	**51**2UuzzM'' 	9C";;CHH<?IIGO* ''8		9
 	fiDJJ$f"oo/?	Ar   c	                     fd}	r$|j                  dd      }|j                  dd      } |	d      |z   |z   g}
|r|
j                   |	d      |z          |D ]  }|
j                   |	d      |z            |j                  |g|
i | y)a  Add an option to an argparse parser or group.

        :param container: an argparse._ArgumentGroup object
        :param name: the opt name
        :param short: the short opt name
        :param kwargs: the keyword arguments for add_argument()
        :param prefix: an optional prefix to prepend to the opt name
        :param positional: whether the option is a positional CLI argument
        :param deprecated_names: list of deprecated option names
        c                     s| S dS )Nr   r    )argr   s    r   hyphenz$Opt._add_to_argparse.<locals>.hyphen  s    (30b0r   r   r   z--N)r   r   add_parser_argument)r   r  r  rD   r   r   r  r   r   r%  argsr   s          `    r   r  zOpt._add_to_argparse  s    	1 ^^C-F<<S)Dtv%,-KKse+,/ 	8OKKt67	8 	#""9>t>v>r   c                 ,    ||j                  |      S |S )zReturns an argparse._ArgumentGroup.

        :param parser: an argparse.ArgumentParser
        :param group: an (optional) OptGroup object
        :returns: an argparse._ArgumentGroup if group is given, else parser
        )_get_argparse_group)r   r  r<   s      r   r  zOpt._get_argparse_container  s      ,,V44Mr   c                     | j                   s&| j                  }||j                  dz   |z   }||d<   n| j                  sd|d<   |j	                  d| j
                  | j                  d       |S )aP  Build a dict of keyword arguments for argparse's add_argument().

        Most opt types extend this method to customize the behaviour of the
        options added to argparse.

        :param group: an optional group
        :param \*\*kwargs: optional keyword arguments to add to
        :returns: a dict of keyword arguments
        Nr   r   ?nargsr   r   r   )r   r   rD   r   updater   r   )r   r<   r   r   s       r   r  zOpt._get_argparse_kwargs  sn     99D zzC'$.!F6N!F7O$"&,,#yy, 	- r   c                     ||dz   |z   S |S )a  Build a prefix for the CLI option name, if required.

        CLI options in a group are prefixed with the group's name in order
        to avoid conflicts between similarly named options in different
        groups.

        :param prefix: an existing prefix to append to (for example 'no' or '')
        :param group_name: an optional group name
        :returns: a CLI option prefix including the group name, if appropriate
        r   r    )r   r  rF   s      r   r  zOpt._get_argparse_prefix  s     !#f,,Mr   c                 `    |dk(  rd}||y|| j                   }| j                  ||      |z   S )a&  Build a CLi arg name for deprecated options.

        Either a deprecated name or a deprecated group or both or
        neither can be supplied:

          dname, dgroup -> dgroup + '-' + dname
          dname         -> dname
          dgroup        -> dgroup + '-' + self.name
          neither        -> None

        :param dname: a deprecated name, which can be None
        :param dgroup: a deprecated group, which can be None
        :param prefix: an prefix to append to (for example 'no' or '')
        :returns: a CLI argument name
        r@   N)rD   r  )r   r  r  r  s       r   r  zOpt._get_deprecated_cli_name  sC      YF=V^=IIE((85@@r   c                 0    t        |       t        |      k  S r   )hashr   s     r   __lt__z
Opt.__lt__(  s    DzDM))r   )NNNNFNNFNNNNNFNNFFr   )r   FNr   )r   r   r   r-   r  r   r   r   r   r  r  object__hash__r  r!  r  r  r  r  r  r3  r    r   r   r   r     s    eL E9=DH(,8<6:AE@EA!F	> ?? H"HA0 HL?<
, A6*r   r   c                   *    e Zd ZdZddZd Zd Zd Zy)r   a*  Represents a Deprecated option.

    Here's how you can use it::

        oldopts = [cfg.DeprecatedOpt('oldopt1', group='group1'),
                   cfg.DeprecatedOpt('oldopt2', group='group2')]
        cfg.CONF.register_group(cfg.OptGroup('group1'))
        cfg.CONF.register_opt(cfg.StrOpt('newopt', deprecated_opts=oldopts),
                              group='group1')

    For options which have a single value (like in the example above),
    if the new option is present ("[group1]/newopt" above), it will override
    any deprecated options present ("[group1]/oldopt1" and "[group2]/oldopt2"
    above).

    If no group is specified for a DeprecatedOpt option (i.e. the group is
    None), lookup will happen within the same group the new option is in.
    For example, if no group was specified for the second option 'oldopt2' in
    oldopts list::

        oldopts = [cfg.DeprecatedOpt('oldopt1', group='group1'),
                   cfg.DeprecatedOpt('oldopt2')]
        cfg.CONF.register_group(cfg.OptGroup('group1'))
        cfg.CONF.register_opt(cfg.StrOpt('newopt', deprecated_opts=oldopts),
                              group='group1')

    then lookup for that option will happen in group 'group1'.

    If the new option is not present and multiple deprecated options are
    present, the option corresponding to the first element of deprecated_opts
    will be chosen.

    Multi-value options will return all new and deprecated
    options. So if we have a multi-value option "[group1]/opt1" whose
    deprecated option is "[group2]/opt2", and the conf file has both these
    options specified like so::

        [group1]
        opt1=val10,val11

        [group2]
        opt2=val21,val22

    Then the value of "[group1]/opt1" will be ['val10', 'val11', 'val21',
    'val22'].

    .. versionadded:: 1.2
    Nc                      || _         || _        y)zConstructs an DeprecatedOpt object.

        :param name: the name of the option
        :param group: the group of the option
        NrD   r<   )r   rD   r<   s      r   r   zDeprecatedOpt.__init___  s     	
r   c                 2    | j                   | j                  fS r   r9  r*   s    r   __keyzDeprecatedOpt.__keyh  s    		4::&&r   c                 D    | j                         |j                         k(  S r   )_DeprecatedOpt__key)r   others     r   r  zDeprecatedOpt.__eq__k  s    zz|u{{},,r   c                 4    t        | j                               S r   )r2  r=  r*   s    r   r6  zDeprecatedOpt.__hash__n  s    DJJL!!r   r   )r   r   r   r-   r   r=  r  r6  r    r   r   r   r   ,  s    /b'-"r   r   c                   8     e Zd ZdZ	 	 d fd	Zd Z fdZ xZS )StrOpta  Option with String type

    Option with ``type`` :class:`oslo_config.types.String`

    :param name: the option's name
    :param choices: Optional sequence of either valid values or tuples of valid
        values with descriptions.
    :param quotes: If True and string is enclosed with single or double
                   quotes, will strip those quotes.
    :param regex: Optional regular expression (string or compiled
                  regex) that the value must match on an unanchored
                  search.
    :param ignore_case: If True case differences (uppercase vs. lowercase)
                        between 'choices' or 'regex' will be ignored.
    :param max_length: If positive integer, the value must be less than or
                       equal to this parameter.
    :param \*\*kwargs: arbitrary keyword arguments passed to :class:`Opt`

    .. versionchanged:: 2.7
       Added *quotes* parameter

    .. versionchanged:: 2.7
       Added *regex* parameter

    .. versionchanged:: 2.7
       Added *ignore_case* parameter

    .. versionchanged:: 2.7
       Added *max_length* parameter

    .. versionchanged:: 5.2
       The *choices* parameter will now accept a sequence of tuples, where each
       tuple is of form (*choice*, *description*)
    c                 b    t        t        | 
  |fdt        j                  |||||      i| y )Nr   )choicesquotesregexignore_case
max_length)superrA  r   r   r   )	r   rD   rC  rD  rE  rF  rG  r   r   s	           r   r   zStrOpt.__init__  s?    fd$T 	/*/,,1806/45@4>+@	/ (.	/r   c                 *    |y|dk(  ryt        |      S )Nz<None>r   z'')r   )r   choices     r   _get_choice_textzStrOpt._get_choice_text  s    >r\6{r   c                 F   t         t        |   |      }t        | j                  dd      rpdj                  | j                  j                  D cg c]  }| j                  |       c}      }|d   d|d<   |d   j                  d       |dxx   d|z  z  cc<   |S c c}w )AExtends the base argparse keyword dict for the config dir option.rC  Nz, r   r   
z
 Allowed values: %s
)	rH  rA  r  getattrr   rc   rC  rK  rstrip)r   r<   r   rJ  choices_textr   s        r   r  zStrOpt._get_argparse_kwargs  s    vt9%@499i.9948II4E4E&G*0 '+&;&;F&C &G HLf~%!#v6N!!$'6N7,FFN&Gs   B)NNNFN)r   r   r   r-   r   rK  r  __classcell__r   s   @r   rA  rA  r  s%    !F 37;?	/ r   rA  c                   @     e Zd ZdZ fdZd fd	Zd Zd fd	Z xZS )BoolOpta1  Boolean options.

    Bool opts are set to True or False on the command line using --optname or
    --nooptname respectively.

    In config files, boolean values are cast with Boolean type.

    :param name: the option's name
    :param \*\*kwargs: arbitrary keyword arguments passed to :class:`Opt`
    c                 t    d|v rt        d      t        t        |   |fdt	        j
                         i| y )Nr   z%positional boolean args not supportedr   )r   rH  rU  r   r   Booleanr   rD   r   r   s      r   r   zBoolOpt.__init__  s6    6!DEEgt%dKKFKr   c                 R    t         t        |   ||       | j                  ||       y)z<Extends the base class method to add the --nooptname option.N)rH  rU  r!  _add_inverse_to_argparse)r   r  r<   r   s      r   r!  zBoolOpt._add_to_cli  s$    gt(7%%fe4r   c           
         | j                  ||      }| j                  |d      }| j                  d|r|j                  nd      }g }| j                  D ]>  }| j                  |j                  |j                  d      }|.|j                  |       @ d| j                  z   |d<   | j                  ||| j                  d||| j                  |       y)z0Add the --nooptname option to the option parser.store_false)actionnoN)r  zThe inverse of --r   )
r  r  r  rD   r   r  r<   r   r  r   r  s	            r   rZ  z BoolOpt._add_inverse_to_argparse  s    00?	**5*G**4u$O'' 	9C";;CHH<?IICG < IO * ''8	9 -tyy8vfiD&$doo7G	Ir   c                 V    t        t        | 
  |fi |}d|v r|d= d|v r|d= ||d<   |S )z;Extends the base argparse keyword dict for boolean options.r   r   r]  )rH  rU  r  )r   r<   r]  r   r   s       r   r  zBoolOpt._get_argparse_kwargs  sM     w:5KFK Vv y!!xr   r   )
store_true)	r   r   r   r-   r   r!  rZ  r  rR  rS  s   @r   rU  rU    s#    	L
5
I  r   rU  c                   $     e Zd ZdZd fd	Z xZS )IntOpta+  Option with Integer type

    Option with ``type`` :class:`oslo_config.types.Integer`

    :param name: the option's name
    :param min: minimum value the integer can take
    :param max: maximum value the integer can take
    :param choices: Optional sequence of either valid values or tuples of valid
        values with descriptions.
    :param \*\*kwargs: arbitrary keyword arguments passed to :class:`Opt`

    .. versionchanged:: 1.15

       Added *min* and *max* parameters.


    .. versionchanged:: 9.3.0

       Added *choices* parameter.
    c           	      ^    t        t        | 
  |fdt        j                  |||      i| y )Nr   )minmaxrC  )rH  rb  r   r   Integer)r   rD   rd  re  rC  r   r   s         r   r   zIntOpt.__init__  s8    fd$T 	/*/---0-018+:	/
 (.	/r   NNNr   r   r   r-   r   rR  rS  s   @r   rb  rb    s    */ /r   rb  c                   $     e Zd ZdZd fd	Z xZS )FloatOptan  Option with Float type

    Option with ``type`` :class:`oslo_config.types.Float`

    :param name: the option's name
    :param min: minimum value the float can take
    :param max: maximum value the float can take
    :param \*\*kwargs: arbitrary keyword arguments passed to :class:`Opt`

    .. versionchanged:: 3.14

       Added *min* and *max* parameters.
    c                 Z    t        t        | 
  |fdt        j                  ||      i| y Nr   )rH  rj  r   r   Float)r   rD   rd  re  r   r   s        r   r   zFloatOpt.__init__!  s.    h&t 	1%++c32G 	1)/	1r   NNrh  rS  s   @r   rj  rj    s    1 1r   rj  c                   $     e Zd ZdZd fd	Z xZS )ListOpta  Option with List(String) type

    Option with ``type`` :class:`oslo_config.types.List`

    :param name: the option's name
    :param item_type: type of items (see :class:`oslo_config.types`)
    :param bounds: if True the value should be inside "[" and "]" pair
    :param \*\*kwargs: arbitrary keyword arguments passed to :class:`Opt`

    .. versionchanged:: 2.5
       Added *item_type* and *bounds* parameters.
    c                 \    t        t        | 
  |fdt        j                  ||      i| y )Nr   )	item_typebounds)rH  rp  r   r   List)r   rD   rr  rs  r   r   s        r   r   zListOpt.__init__5  s5    gt%d 	0+0::	=C,E	0 )/	0r   rn  rh  rS  s   @r   rp  rp  &  s    0 0r   rp  c                   "     e Zd ZdZ fdZ xZS )DictOptzOption with Dict(String) type

    Option with ``type`` :class:`oslo_config.types.Dict`

    :param name: the option's name
    :param \*\*kwargs: arbitrary keyword arguments passed to :class:`Opt`

    .. versionadded:: 1.2
    c                 V    t        t        | 
  |fdt        j                         i| y rl  )rH  rv  r   r   DictrX  s      r   r   zDictOpt.__init__H  s"    gt%dHHHr   rh  rS  s   @r   rv  rv  <  s    I Ir   rv  c                   $     e Zd ZdZd fd	Z xZS )IPOptaB  Opt with IPAddress type

    Option with ``type`` :class:`oslo_config.types.IPAddress`

    :param name: the option's name
    :param version: one of either ``4``, ``6``, or ``None`` to specify
       either version.
    :param \*\*kwargs: arbitrary keyword arguments passed to :class:`Opt`

    .. versionadded:: 1.4
    c                 X    t        t        | 
  |fdt        j                  |      i| y rl  )rH  rz  r   r   	IPAddressr   rD   versionr   r   s       r   r   zIPOpt.__init__Z  s,    eT#D 	.uw/G 	.&,	.r   r   rh  rS  s   @r   rz  rz  L  s    
. .r   rz  c                   $     e Zd ZdZd fd	Z xZS )PortOpta>  Option for a TCP/IP port number.  Ports can range from 0 to 65535.

    Option with ``type`` :class:`oslo_config.types.Integer`

    :param name: the option's name
    :param min: minimum value the port can take
    :param max: maximum value the port can take
    :param choices: Optional sequence of either valid values or tuples of valid
        values with descriptions.
    :param \*\*kwargs: arbitrary keyword arguments passed to :class:`Opt`

    .. versionadded:: 2.6
    .. versionchanged:: 3.2
       Added *choices* parameter.
    .. versionchanged:: 3.4
       Allow port number with 0.
    .. versionchanged:: 3.16
       Added *min* and *max* parameters.
    .. versionchanged:: 5.2
       The *choices* parameter will now accept a sequence of tuples, where each
       tuple is of form (*choice*, *description*)
    c                 d    t        j                  |||d      }t        t        |   |fd|i| y )Nz
port value)rd  re  rC  	type_namer   )r   PortrH  r  r   )r   rD   rd  re  rC  r   r   r   s          r   r   zPortOpt.__init__x  s3    zzcsG$02gt%d@@@r   rg  rh  rS  s   @r   r  r  _  s    .A Ar   r  c                   "     e Zd ZdZ fdZ xZS )HostnameOpta  Option for a hostname.  Only accepts valid hostnames.

    Option with ``type`` :class:`oslo_config.types.Hostname`

    :param name: the option's name
    :param \*\*kwargs: arbitrary keyword arguments passed to :class:`Opt`

    .. versionadded:: 3.8
    c                 V    t        t        | 
  |fdt        j                         i| y rl  )rH  r  r   r   HostnamerX  s      r   r   zHostnameOpt.__init__  s*    k4)$ 	4U^^5E 	4,2	4r   rh  rS  s   @r   r  r  ~  s    4 4r   r  c                   $     e Zd ZdZd fd	Z xZS )HostAddressOpta  Option for either an IP or a hostname.

    Accepts valid hostnames and valid IP addresses.

    Option with ``type`` :class:`oslo_config.types.HostAddress`

    :param name: the option's name
    :param version: one of either ``4``, ``6``, or ``None`` to specify
       either version.
    :param \*\*kwargs: arbitrary keyword arguments passed to :class:`Opt`

    .. versionadded:: 3.22
    c                 X    t        t        | 
  |fdt        j                  |      i| y rl  )rH  r  r   r   HostAddressr}  s       r   r   zHostAddressOpt.__init__  s/    nd,T 	7272C2CG2L	7/5	7r   r   rh  rS  s   @r   r  r    s    7 7r   r  c                   $     e Zd ZdZd fd	Z xZS )HostDomainOpta  Option for either an IP or a hostname.

    Like HostAddress with the support of _ character.

    Option with ``type`` :class:`oslo_config.types.HostDomain`

    :param name: the option's name
    :param version: one of either ``4``, ``6``, or ``None`` to specify
       either version.
    :param \*\*kwargs: arbitrary keyword arguments passed to :class:`Opt`

    .. versionadded:: 8.6
    c                 X    t        t        | 
  |fdt        j                  |      i| y rl  )rH  r  r   r   
HostDomainr}  s       r   r   zHostDomainOpt.__init__  s/    mT+D 	6161A1A'1J	6.4	6r   r   rh  rS  s   @r   r  r    s    6 6r   r  c                   $     e Zd ZdZd fd	Z xZS )URIOpta  Opt with URI type

    Option with ``type`` :class:`oslo_config.types.URI`

    :param name: the option's name
    :param max_length: If positive integer, the value must be less than or
                       equal to this parameter.
    :param schemes: list of valid URI schemes, e.g. 'https', 'ftp', 'git'
    :param \*\*kwargs: arbitrary keyword arguments passed to :class:`Opt`

    .. versionadded:: 3.12

    .. versionchanged:: 3.14
       Added *max_length* parameter
    .. versionchanged:: 3.18
       Added *schemes* parameter
    c                 `    t        j                  ||      }t        t        |   |fd|i| y )N)rG  schemesr   )r   URIrH  r  r   )r   rD   rG  r  r   r   r   s         r   r   zURIOpt.__init__  s,    yyJ@fd$T???r   rn  rh  rS  s   @r   r  r    s    $@ @r   r  c                   0     e Zd ZdZdZ fdZ fdZ xZS )MultiOpta  Multi-value option.

    Multi opt values are typed opts which may be specified multiple times.
    The opt value is a list containing all the values specified.

    :param name: the option's name
    :param item_type: Type of items (see :class:`oslo_config.types`)
    :param \*\*kwargs: arbitrary keyword arguments passed to :class:`Opt`

    For example::

       cfg.MultiOpt('foo',
                    item_type=types.Integer(),
                    default=None,
                    help="Multiple foo option")

    The command line ``--foo=1 --foo=2`` would result in ``cfg.CONF.foo``
    containing ``[1,2]``

    .. versionadded:: 1.3
    Tc                 0    t        t        | 
  ||fi | y r   )rH  r  r   )r   rD   rr  r   r   s       r   r   zMultiOpt.__init__  s    h&tYA&Ar   c                 ^    t         t        |   |      }| j                  sd|d<   |S d|d<   |S )z?Extends the base argparse keyword dict for multi value options.r   r]  *r,  )rH  r  r  r   r   r<   r   r   s      r   r  zMultiOpt._get_argparse_kwargs  s<    x;EB'F8  "F7Or   )r   r   r   r-   r  r   r  rR  rS  s   @r   r  r    s    * EB r   r  c                   "     e Zd ZdZ fdZ xZS )MultiStrOptzMultiOpt with a MultiString ``item_type``.

    MultiOpt with a default :class:`oslo_config.types.MultiString` item
    type.

    :param name: the option's name
    :param \*\*kwargs: arbitrary keyword arguments passed to :class:`MultiOpt`
    c                 V    t        t        | 
  |fdt        j                         i| y )Nrr  )rH  r  r   r   MultiStringrX  s      r   r   zMultiStrOpt.__init__  s-    k4)$ 	4494E4E4G	4,2	4r   rh  rS  s   @r   r  r    s    4 4r   r  c                   0     e Zd ZdZ	 	 d fd	ZddZ xZS )SubCommandOpta  Sub-command options.

    Sub-command options allow argparse sub-parsers to be used to parse
    additional command line arguments.

    The handler argument to the SubCommandOpt constructor is a callable
    which is supplied an argparse subparsers object. Use this handler
    callable to add sub-parsers.

    The opt value is SubCommandAttr object with the name of the chosen
    sub-parser stored in the 'name' attribute and the values of other
    sub-parser arguments available as additional attributes.

    :param name: the option's name
    :param dest: the name of the corresponding :class:`.ConfigOpts` property
    :param handler: callable which is supplied subparsers object when invoked
    :param title: title of the sub-commands group in help output
    :param description: description of the group in help output
    :param help: a help string giving an overview of available sub-commands
    c                     t         t        |   |t        j                         ||       || _        || _        || _        y)a\  Construct an sub-command parsing option.

        This behaves similarly to other Opt sub-classes but adds a
        'handler' argument. The handler is a callable which is supplied
        an subparsers object when invoked. The add_parser() method on
        this subparsers object can be used to register parsers for
        sub-commands.
        )r   r   r   N)rH  r  r   r   r   handlertitledescription)r   rD   r   r  r  r  r   r   s          r   r   zSubCommandOpt.__init__"  s?     	mT+Du||~15D 	, 	B
&r   c                     | j                   }||j                  dz   |z   }|j                  || j                  | j                  | j
                        }d|_        | j                  | j                  |       yy)z7Add argparse sub-parsers and invoke the handler method.Nr   )r   r  r  r   T)r   rD   add_subparsersr  r  r   r   r  )r   r  r<   r   
subparserss        r   r!  zSubCommandOpt._add_to_cli2  sw    yy::#d*D**157;7G7G04		 + ;
 #
<<#LL$ $r   )NNNNNr   )r   r   r   r-   r   r!  rR  rS  s   @r   r  r    s    * 1548' %r   r  c                   V     e Zd ZdZ G d dej
                        Z fdZ fdZ xZ	S )_ConfigFileOpta  The --config-file option.

    This is an private option type which handles the special processing
    required for --config-file options.

    As each --config-file option is encountered on the command line, we
    parse the file and store the parsed values in the _Namespace object.
    This allows us to properly handle the precedence of --config-file
    options over previous command line arguments, but not over subsequent
    arguments.

    .. versionadded:: 1.2
    c                       e Zd ZdZddZy)_ConfigFileOpt.ConfigFileActiona/  An argparse action for --config-file.

        As each --config-file option is encountered, this action adds the
        value to the config_file attribute on the _Namespace object but also
        parses the configuration file and stores the values found also in
        the _Namespace object.
        Nc                     t        || j                  d      t        || j                  g        t        || j                        }|j                  |       t        j                  ||       y)z{Handle a --config-file command line argument.

            :raises: ConfigFileParseError, ConfigFileValueError
            N)rO  r   setattrr   ConfigParser_parse_file)r   r  r  valuesoption_stringitemss         r   __call__z(_ConfigFileOpt.ConfigFileAction.__call__^  sS    
 y$))T2:	499b1Ityy1ELL $$VY7r   r   r   r   r   r-   r  r    r   r   ConfigFileActionr  T  s    	
	8r   r  c                 2    t        t        | 
  |d fi | y )Nc                     | S r   r    r   s    r   <lambda>z)_ConfigFileOpt.__init__.<locals>.<lambda>k  s    Q r   )rH  r  r   rX  s      r   r   z_ConfigFileOpt.__init__j  s    nd,T;I&Ir   c                 L    t         t        |   |      }| j                  |d<   |S )z?Extends the base argparse keyword dict for the config file opt.r]  )rH  r  r  r  r  s      r   r  z#_ConfigFileOpt._get_argparse_kwargsm  s)    ~tA%H00xr   )
r   r   r   r-   argparseActionr  r   r  rR  rS  s   @r   r  r  D  s(    88?? 8,J r   r  c                   V     e Zd ZdZ G d dej
                        Z fdZ fdZ xZ	S )_ConfigDirOpta  The --config-dir option.

    This is an private option type which handles the special processing
    required for --config-dir options.

    As each --config-dir option is encountered on the command line, we
    parse the files in that directory and store the parsed values in the
    _Namespace object. This allows us to properly handle the precedence of
    --config-dir options over previous command line arguments, but not
    over subsequent arguments.

    .. versionadded:: 1.2
    c                       e Zd ZdZddZy)_ConfigDirOpt.ConfigDirActiona   An argparse action for --config-dir.

        As each --config-dir option is encountered, this action sets the
        config_dir attribute on the _Namespace object but also parses the
        configuration files and stores the values found also in the
        _Namespace object.
        Nc                    |j                   j                  |       t        || j                  |       t        j
                  j                  |      }t        j
                  j                  |      st        |      t        j
                  j                  |d      }t        t        j                  |            D ]  }t        j                  ||        y)zHandle a --config-dir command line argument.

            :raises: ConfigFileParseError, ConfigFileValueError,
                     ConfigDirNotFoundError
            *.confN)_config_dirsr   r  r   r}   r~   r   r   rj   rc   sortedglobr  r  )r   r  r  r  r  config_dir_globrs   s          r   r  z&_ConfigDirOpt.ConfigDirAction.__call__  s     ""))&1Ityy&1WW''/F77>>&),V44 ggll68<O%dii&@A A((i@Ar   r   r  r    r   r   ConfigDirActionr    s    		Ar   r  c                 V    t        t        | 
  |fdt        j                         i| y rl  )rH  r  r   r   rt  rX  s      r   r   z_ConfigDirOpt.__init__  s)    mT+D 	6uzz| 	6.4	6r   c                 L    t         t        |   |      }| j                  |d<   |S )rM  r]  )rH  r  r  r  r  s      r   r  z"_ConfigDirOpt._get_argparse_kwargs  s)    }d@G//xr   )
r   r   r   r-   r  r  r  r   r  rR  rS  s   @r   r  r  t  s)    A(// A:6 r   r  c                   J    e Zd ZdZ	 	 	 ddZd Zd ZddZd Zd Z	d	 Z
d
 Zy)OptGroupa  Represents a group of opts.

    CLI opts in the group are automatically prefixed with the group name.

    Each group corresponds to a section in config files.

    An OptGroup object has no public methods, but has a number of public string
    properties:

    .. py:attribute:: name

        the name of the group

    .. py:attribute:: title

        the group title as displayed in --help

    .. py:attribute:: help

        the group description as displayed in --help

    :param name: the group name
    :type name: str
    :param title: the group title for --help
    :type title: str
    :param help: the group description for --help
    :type help: str
    :param dynamic_group_owner: The name of the option that controls
                                repeated instances of this group.
    :type dynamic_group_owner: str
    :param driver_option: The name of the option within the group that
                          controls which driver will register options.
    :type driver_option: str

    Nc                     || _         |d|z  n|| _        || _        || _        || _        i | _        d| _        i | _        y)zConstructs an OptGroup object.Nz
%s options)rD   r  r   dynamic_group_ownerdriver_option_opts_argparse_group_driver_opts)r   rD   r  r   r  r  s         r   r   zOptGroup.__init__  sK     	,1M\D(u
	#6 *
#r   c                 :    | j                   j                  |       y)z}Save known driver opts.

        :param opts: mapping between driver name and list of opts
        :type opts: dict

        N)r  r.  )r   r   s     r   _save_driver_optszOptGroup._save_driver_opts  s     	  &r   c                 h    | j                   xs d| j                  | j                  | j                  dS )z1Return a dict with data for the sample generator.r   )r   r  r  driver_opts)r   r  r  r  r*   s    r   _get_generator_datazOptGroup._get_generator_data  s4     IIO#'#;#;!//,,	
 	
r   c                 j    t        | j                  |      ry||d| j                  |j                  <   y)zAdd an opt to this group.

        :param opt: an Opt object
        :param cli: whether this is a CLI option
        :returns: False if previously registered, True otherwise
        :raises: DuplicateOptError if a naming conflict is detected
        Fr   cliT)r   r  r   )r   r   r  s      r   _register_optzOptGroup._register_opt  s/     djj#.'*37

388r   c                 d    |j                   | j                  v r| j                  |j                   = yy)zJRemove an opt from this group.

        :param opt: an Opt object
        N)r   r  )r   r   s     r   _unregister_optzOptGroup._unregister_opt  s)    
 88tzz!

388$ "r   c                     | j                   ,	 |j                  | j                  | j                        | _         | j                   S r   )r  add_argument_groupr  r   )r   r  s     r   r)  zOptGroup._get_argparse_group	  s>    'B#)#<#<TZZ=AYY$HD ###r   c                     d| _         y)z(Clear this group's option parsing state.N)r  r*   s    r   _clearzOptGroup._clear  s
    #r   c                     | j                   S r   rD   r*   s    r   r+   zOptGroup.__str__  s    yyr   )NNr   r   F)r   r   r   r-   r   r  r  r  r  r)  r  r+   r    r   r   r  r    s;    "H /3%'!'
%$$r   r  c                   $     e Zd Z fdZd Z xZS )
ParseErrorc                 >    t         t        |   |||       || _        y r   )rH  r  r   filename)r   r(   linenoliner  r   s        r   r   zParseError.__init__  s    j$(fd; r   c                 d    d| j                   | j                  | j                  | j                  fz  S )Nzat %s:%d, %s: %r)r  r  r(   r  r*   s    r   r+   zParseError.__str__  s-    !T]]DKK%)XXtyy%: : 	:r   )r   r   r   r   r+   rR  rS  s   @r   r  r    s    !:r   r  c                   \     e Zd ZdZ fdZd Z fdZd Zd Zd
dZ	d Z
ed	        Z xZS )r  zParses a single config file, populating 'sections' to look like::

        {'DEFAULT': {'key': [value, ...], ...},
         ...}

       Also populates self._normalized which looks the same but with normalized
       section names.
    c                 b    t         t        |           || _        || _        d | _        d | _        y r   )rH  r  r   r  sections_normalizedsection)r   r  r  r   s      r   r   zConfigParser.__init__,  s-    lD*,  r   c                     || _         y r   )r  )r   
normalizeds     r   _add_normalizedzConfigParser._add_normalized3  s
    %r   c                     t        | j                        5 }t        t        |   |j                               cd d d        S # 1 sw Y   y xY wr   )openr  rH  r  parse	readlines)r   fr   s     r   r  zConfigParser.parse6  s?    $--  	BAt21;;=A	B 	B 	Bs   !AAc                     || _         | j                  j                  | j                   i        | j                  0| j                  j                  t	        | j                         i        y y r   )r  r  
setdefaultr  r   )r   r  s     r   new_sectionzConfigParser.new_section:  sU      r2'''(=dll(K(*, (r   c                    | j                   s| j                         dj                        fd} || j                  | j                          | j                  ' || j                  t        | j                                y y )NrN  c                 ^    | |   j                  g        | |      j                         y r   )r  r   )r  r  keyr  s     r   r   z'ConfigParser.assignment.<locals>.appendH  s0    W((b1Wc"))%0r   )r  error_no_sectionrc   r  r  r   )r   r  r  r   s    `` r   
assignmentzConfigParser.assignmentB  sk    ||''))		% 	1 	t}}dll+'4##%:4<<%HI (r   c                 2    t        |||| j                        S r   )r  r  )r   r(   r  r  s       r   	parse_exczConfigParser.parse_excP  s    #vtT]];;r   c                 :    | j                  d| j                        S )Nz)Section must be started before assignment)r  r  r*   s    r   r  zConfigParser.error_no_sectionS  s    ~~I"kk+ 	+r   c                    t        |      }i }i } | ||      }|j                  |       	 |j                          |j                  |||       |j                  |||       y# t        j                  $ r$}t        |j                  t        |            d}~wt        $ rl}|j                  t        j                  k(  r|j                  |       Y d}~y|j                  t        j                  k(  r|j                  |       Y d}~y d}~ww xY w)zParse a config file and store any values in the namespace.

        :raises: ConfigFileParseError, ConfigFileValueError
        N)r   r  r  r   r  rp   r  r   IOErrorerrnoENOENT_file_not_foundEACCES_file_permission_denied_add_parsed_config_file _parse_cli_opts_from_config_file)clsrs   r  r  r  r  peerrs           r   r  zConfigParser._parse_fileW  s     {+
[(+z*	LLN 	))+xL22:	/ ## 	=&r{{CG<< 	yyELL())+6yyELL(11+>	s/   A" "D5BD .D.DDDr   )r   r   r   r-   r   r  r  r  r  r  r  classmethodr  rR  rS  s   @r   r  r  "  sA    &B,J<+ / /r   r  c                   \    e Zd ZdZdZd Zd Zd Zd Zd Z	ddZ
	 dd
Zd Z	 	 ddZd Zy	)
_Namespaceae  An argparse namespace which also stores config file values.

    As we parse command line arguments, the values get set as attributes
    on a namespace object. However, we also want to parse config files as
    they are specified on the command line and collect the values alongside
    the option values parsed from the command line.

    Note, we don't actually assign values from config files as attributes
    on the namespace because config file options be registered after the
    command line has been parsed, so we may not know how to properly parse
    or convert a config file value at this point.
    zqOption "%(dep_option)s" from group "%(dep_group)s" is deprecated. Use option "%(option)s" from group "%(group)s".c                     || _         g | _        g | _        t               | _        g | _        g | _        g | _        i | _        y r   )	_conf_parsedr  set_emitted_deprecations_files_not_found_files_permission_deniedr  _sections_to_file)r   confs     r   r   z_Namespace.__init__  sB    
%(U" "(*%!#r   c           
      F   t        | j                        }|j                  |||       | j                  j                         D ]  \  }}||j                  nd}	 |j                  ||      \  }}	||j                  }n|dz   |j                  z   }|j                  r8t        | |d      t        | |g        t        | |      }|j                  |       t        | ||        y# t        $ r Y t        $ r)}
t        d|j                  dt        |
            d}
~
ww xY w)a  Parse CLI options from a config file.

        CLI options are special - we require they be registered before the
        command line is parsed. This means that as we parse config files, we
        can go ahead and apply the appropriate option-type specific conversion
        to the values in config files for CLI options. We can't do this for
        non-CLI options, because the schema describing those options may not be
        registered until after the config files are parsed.

        This method relies on that invariant in order to enforce proper
        priority of option values - i.e. that the order in which an option
        value is parsed, whether the value comes from the CLI or a config file,
        determines which value specified for a given option wins.

        The way we implement this ordering is that as we parse each config
        file, we look for values in that config file for CLI options only. Any
        values for CLI options found in the config file are treated like they
        had appeared on the command line and set as attributes on the namespace
        objects. Values in later config files or on the command line will
        override values found in this file.
        NValue for option  is not valid: r   )r  r  r
  _all_cli_optsrD   r  KeyErrorr   ry   r   r   r  rO  r  extend)r   rs   r  r  r  r   r<   rF   r  r  ver   r  s                r   r  z+_Namespace._parse_cli_opts_from_config_file  s   . tzz*	))+xL**224 	+JC','8dJ+ 44Y
K
s !xx!C'#((2yy4t,4D$+ t,e$dE*-	+   +*xxR*+ ++s   C$$	D /D 7$DD c                     |D ]  }|| j                   |<    | j                  j                  d|       | j                  j                  d|       y)a?  Add a parsed config file to the list of parsed files.

        :param filename: the full name of the file that was parsed
        :param sections: a mapping of section name to dicts of config values
        :param normalized: sections mapping with section names normalized
        :raises: ConfigFileValueError
        r   N)r  r  insertr  )r   r  r  r  r   s        r   r
  z"_Namespace._add_parsed_config_file  sM      	1A(0D""1%	1Ax(:.r   c                 :    | j                   j                  |       y)zsRecord that we were unable to open a config file.

        :param config_file: the path to the failed file
        N)r  r   r   rs   s     r   r  z_Namespace._file_not_found  s    
 	$$[1r   c                 :    | j                   j                  |       y)zzRecord that we have no permission to open a config file.

        :param config_file: the path to the failed file
        N)r  r   r%  s     r   r	  z"_Namespace._file_permission_denied  s    
 	%%,,[9r   c                 j    |D ])  \  }}||n|dz   |z   }t        | |d      }|"|r|s'|c S  t        )a  Fetch a CLI option value.

        Look up the value of a CLI option. The value itself may have come from
        parsing the command line or parsing config files specified on the
        command line. Type conversion have already been performed for CLI
        options at this point.

        :param names: a list of (section, name) tuples
        :param positional: whether this is a positional option
        Nr   )rO  r  )r   r  r   rF   rD   r  s         r   _get_cli_valuez_Namespace._get_cli_value  sV     !& 	J%-4:3Cd3JDD$-E e	 r   Nc           	         g }fd}|D cg c]  \  }} ||      |f }}}d}	r| j                   n| j                  D ]  }
|D ]  \  }}||
vr||
|   v s|xs |d   }| j                  ||f||dd        |
|   |   }|	4t        t        j
                  | j                  j                  |d            }	|r||z   }z||	fc c S   |r	|g k7  r||	fS t        c c}}w )aH  Fetch a config file value from the parsed files.

        :param names: a list of (section, name) tuples
        :param multi: a boolean indicating whether to return multiple values
        :param normalized: whether to normalize group names to lowercase
        :param current_name: current name in tuple being checked
        c                 *    | d} rt        |       S | S r   )r   )rD   r  s    r   	normalizez-_Namespace._get_file_value.<locals>.normalize  s     | 2<(.F$Fr   Nr   r	   r   )	r  r  _check_deprecatedr!   r   r   r  r   r  )r   r  r  r  r  rvaluer+  r  rD   r  r  vals      `        r   _get_file_valuez_Namespace._get_file_value  s"    	G
 BGG)G$d+GG-7))T\\ 	*H!& *(*8G,,#/#;58L**GT?L+096"7+D1C{*%NN 2266wC !$v #Sz)!*	*$ Vr\C= / Hs   Cc                     ||v rb|| j                   vrS| j                   j                  |       |d   xs d|d   f}|d   |d   |d   |d   d}t        | j                  |       yyy)aS  Check for usage of deprecated names.

        :param name: A tuple of the form (group, name) representing the group
                     and name where an opt value was found.
        :param current: A tuple of the form (group, name) representing the
                        current name for an option.
        :param deprecated: A list of tuples with the same format as the name
                    param which represent any deprecated names for an option.
                    If the name param matches any entries in this list a
                    deprecation warning will be logged.
        r   r@   r	   
dep_option	dep_groupr	  r<   N)r  addr   _deprecated_opt_message)r   rD   current
deprecatedr   s        r   r,  z_Namespace._check_deprecated  s     :$d.H.H"H&&**40qz.Y
;G)-atAw%,QZ'!*FK < <kJ #Ir   c                 :   t        t        j                  d      }	 |D cg c]  \  }}||nd|f }	}}| j                  |	|||      \  }
}d}	 | j                  ||      }||fS c c}}w # t        $ r d}Y *w xY w# t        $ r |r Y nw xY w|r
|fS 
d   |fS )a  Fetch a value from config files.

        Multiple names for a given configuration option may be supplied so
        that we can transparently handle files containing deprecated option
        names or groups.

        :param names: a list of (section, name) tuples
        :param positional: whether this is a positional option
        :param multi: a boolean indicating whether to return multiple values
        :param normalized: whether to normalize group names to lowercase
        r   r@   )r  r  r  FT)r!   r   r   r/  r  r(  )r   r  r  r   r  r  r  gr   
file_namesr  raise_laterr  s                r   r  z_Namespace._get_value2  s    , 91126	 &+-"a !"19a@ -J -..%J) / +KFC  K	''z:E3<!-
  	 K		  	  	  55VBZ55s3   A- A'A- A> 'A- -A;:A;>BBc              #   D   K   | j                   D ]  }|D ]  }|   y wr   )r  )r   r  r  s      r   	_sectionsz_Namespace._sectionse  s-      	H# 	s    r  )FFN)FFNT)r   r   r   r-   r5  r   r  r
  r  r	  r(  r/  r,  r  r>  r    r   r   r  r  v  sU     F$0+d/2:0 FJ'RK& 9>1516fr   r  c                   T     e Zd ZdZd fd	Zd Zd Zd fd	Zd	 fd	Zd	 fd	Z	 xZ
S )
_CachedArgumentParseraZ  class for caching/collecting command line arguments.

    It also sorts the arguments before initializing the ArgumentParser.
    We need to do this since ArgumentParser by default does not sort
    the argument options and the only way to influence the order of
    arguments in '--help' is to ensure they are added in the sorted
    order.
    c                 >    t        t        | 
  ||fi | i | _        y r   )rH  r@  r   _args_cache)r   r   usager   r   s       r   r   z_CachedArgumentParser.__init__v  s"    #T3D%J6Jr   c                     g }|| j                   v r| j                   |   }|j                  ||d       || j                   |<   y )N)r'  r   )rB  r   )r   r  r'  r   r  s        r   r&  z)_CachedArgumentParser.add_parser_argumentz  sF    (((%%i0Ftv67&,#r   c                    | j                   j                         D ]z  \  }}d}d}t        |      D ]   \  }}|d   d   j                  d      rd} n |r|n
t	        |      }t        |d | d       |d | |D ]  }	  |j                  |d   i |d     | i | _         y # t        j                  $ r  d	j                  |d         }t        |      w xY w)
Nr   Fr'  r   Tc                     | d   S )Nr'  r    r  s    r   r  zC_CachedArgumentParser.initialize_parser_arguments.<locals>.<lambda>  s
    &	 r   r  r   ra   )rB  r  	enumerater   lenr  add_argumentr  ArgumentErrorrc   rN   )r   r  r  indexhas_positionalargumentsizeoptionss           r   initialize_parser_argumentsz1_CachedArgumentParser.initialize_parser_arguments  s
    "&!1!1!7!7!9 	5IvE"N#,V#4 x'*55c:%)N +5FD"6%4=6IJF5DM" 55*I**HV,< A-5h-?A5	5    -- 5!hhx'78G+G445s   <B  3Cc                 L    | j                          t        t        |   ||      S r   )rQ  rH  r@  
parse_args)r   r'  r  r   s      r   rS  z _CachedArgumentParser.parse_args  s$    ((**D<T9MMr   c                 L    | j                          t        t        |   |       y r   )rQ  rH  r@  
print_helpr   filer   s     r   rU  z _CachedArgumentParser.print_help  s    ((*#T5d;r   c                 L    | j                          t        t        |   |       y r   )rQ  rH  r@  print_usagerV  s     r   rY  z!_CachedArgumentParser.print_usage  s    ((*#T6t<r   rn  r   )r   r   r   r-   r   r&  rQ  rS  rU  rY  rR  rS  s   @r   r@  r@  k  s,    -0N<= =r   r@  c                      e Zd ZdZdZ eddg d      Zd Zd Ze	d	        Z
ed
        Zd Zd Zd Z	 	 	 	 	 	 	 	 	 	 	 dLdZd Zd Zd Zd Zd Zd Zd Zd Zed        Zd ZdMdZedNd       ZedMd       ZedMd       ZedMd       Zd Z edMd        Z!edMd!       Z"dMd"Z#d# Z$edMd$       Z%edMd%       Z&d& Z'edMd'       Z(edMd(       Z)d) Z*d* Z+d+ Z,e-d,        Z.d- Z/d. Z0dMd/Z1dMd0Z2dOd1Z3dOd2Z4dOd3Z5 G d4 d5e6jn                        Z7d6 Z8dPd7Z9dMd8Z:dMd9Z;dMd:Z<d; Z=d< Z>d= Z?d> Z@eed?               ZAd@ ZBdA ZCdB ZDdC ZEdD ZFdMdEZG G dF dGeHj                        ZJ G dH dI      ZK G dJ dK      ZLy)Q
ConfigOptsat  Config options which may be set on the command line or in config files.

    ConfigOpts is a configuration option manager with APIs for registering
    option schemas, grouping options, parsing option values and retrieving
    the values of options.

    It has built-in support for :oslo.config:option:`config_file` and
    :oslo.config:option:`config_dir` options.

    )r   r   r~  rC  default_config_filesdefault_config_dirsconfig_sourceSOURCEzLists configuration groups that provide more details for accessing configuration settings from locations other than local files.r   r   r   c                    i | _         i | _        i | _        d| _        d| _        d| _        d| _        t        g       | _        i | _	        i | _
        g | _        t        j                         | _        d| _        g | _        d| _        d| _        t'        j(                         | _        | j-                  | j.                         y)zConstruct a ConfigOpts object.NFT)r  _groups_deprecated_opts_args_oparser
_namespace_mutable_nsr  _mutate_hooks_ConfigOpts__cache_ConfigOpts__drivers_cache_config_optscollectionsdeque	_cli_opts_validate_default_values_sources_ext_mgr_use_env_environmentEnvironmentConfigurationSource_env_driverregister_opt_config_source_optr*   s    r   r   zConfigOpts.__init__  s    
 "
 W!$**,(-%'FFH$112r   c	                 R   |Ft         j                  j                  t        j                  d         }|j                  d      r|dd }|t        ||      }|t        ||      }t        ||||      | _	        |)| j                  j                  | j                  dd|       |||fS )	z7Initialize a ConfigCliParser object for option parsing.Nr   r   r   )r   rC  r  epilogz	--versionr~  )r]  r~  )r}   r~   r   r   r   r   r   r   r@  re  r&  )	r   r   r   r~  rC  r  ry  r\  r]  s	            r   
_pre_setupzConfigOpts._pre_setup  s     <77##CHHQK0D}}U#CRy'#4Wd#C &"27D"A-UFL MM--dmm.95>6= . ?
 )+>>>r   c                 >    t        d| dd      t        dd|d      gS )	Nzconfig-filePATHzPath to a config file to use. Multiple config files can be specified, with values in later files taking precedence. Defaults to %(default)s. This option must be set from the command-line.r-  z
config-dirDIRaa  Path to a config directory to pull `*.conf` files from. This file set is sorted, so as to provide a predictable parse order if individual options are over-ridden. The set is parsed after the file(s) specified via previous --config-file, arguments hence over-ridden options in the directory take precedence. This option must be set from the command-line.r`  )r  r  )r\  r]  s     r   _make_config_optionszConfigOpts._make_config_options  s:     =#7#)":< ,"'"5 34
 	
r   c                 `    | j                  ||      }|j                  | j                         |S )zBReturn options to be used by list_opts() for the sample generator.)r~  r   rw  )r  r\  r]  rP  s       r   _list_options_for_discoveryz&ConfigOpts._list_options_for_discovery  s2    
 **+?+>@s--.r   c                     | j                  ||      | _        | j                  | j                         || _        || _        || _        || _        || _        || _        || _	        y)z2Initialize a ConfigOpts object for option parsing.N)
r~  rk  register_cli_optsr   r   r~  rC  r\  r]  rr  )r   r   r   r~  rC  r\  r]  use_envs           r   _setupzConfigOpts._setup  se     !556J6IKt001	
$8!#6 r   c                 B     t        j                          fd       }|S )Nc                     |j                  dd      r( | g|i |}| j                  j                          |S  | g|i |S )Nclear_cacheT)popri  clearr   r'  r   resultr  s       r   __innerz)ConfigOpts.__clear_cache.<locals>.__inner%  sO    zz-.41$1&1""$////r   	functoolswrapsr  _ConfigOpts__inners   ` r   __clear_cachezConfigOpts.__clear_cache$  %    			0 
	0 r   c                 B     t        j                          fd       }|S )Nc                     |j                  dd      r( | g|i |}| j                  j                          |S  | g|i |S )Nclear_drivers_cacheT)r  rj  r  r  s       r   r  z1ConfigOpts.__clear_drivers_cache.<locals>.__inner1  sR    zz/641$1&1$$**,////r   r  r  s   ` r   __clear_drivers_cachez ConfigOpts.__clear_drivers_cache0  r  r   Nc           
         | j                          || _        | j                  |||||	|
||      \  }}}| j                  |||||||       | j	                  ||nt
        j                  dd       | _        | j                  j                  rt        | j                  j                        | j                  j                  rt        | j                  j                        | j                          | j                          y)a  Parse command line arguments and config files.

        Calling a ConfigOpts object causes the supplied command line arguments
        and config files to be parsed, causing opt values to be made available
        as attributes of the object.

        The object may be called multiple times, each time causing the previous
        set of values to be overwritten.

        Automatically registers the --config-file option with either a supplied
        list of default config files, or a list from find_config_files().

        If the --config-dir option is set, any *.conf files from this
        directory are pulled in, after all the file(s) specified by the
        --config-file option.

        :param args: command line arguments (defaults to sys.argv[1:])
        :param project: the toplevel project name, used to locate config files
        :param prog: the name of the program (defaults to sys.argv[0]
            basename, without extension .py)
        :param version: the program version (for --version)
        :param usage: a usage string (%prog will be expanded)
        :param description: A description of what the program does
        :param epilog: Text following the argument descriptions
        :param default_config_files: config files to use by default
        :param default_config_dirs: config dirs to use by default
        :param validate_default_values: whether to validate the default values
        :param use_env: If True (the default) look in the environment as one
                        source of option values.
        :raises: SystemExit, ConfigFilesNotFoundError, ConfigFileParseError,
                 ConfigFilesPermissionDeniedError,
                 RequiredOptError, DuplicateOptError
        Nr	   )r  ro  rz  r  _parse_cli_optsr   r   rf  r  rZ   r  rf   _load_alternative_sources_check_required_opts)r   r'  r   r   r~  rC  r\  r]  validate_default_valuesr  ry  r  s               r   r  zConfigOpts.__call__<  s    Z 	

(?%:>//T7E; "5;77"$7 	GT7E3G'	2 ..t7Gt47HHQRLB??++*4??+K+KLL??33288: : 	&&(!!#r   c                     | j                   D ]1  }| j                  |      }|| j                  j                  |       3 y r   )r^  _open_source_from_opt_grouprp  r   )r   source_group_namesources      r   r  z$ConfigOpts._load_alternative_sources  sA    !%!3!3 	-556GHF!$$V,	-r   c                 j   | j                   st        j                  dd      | _         | j                  t	        d| j                   j                         t              |       	 | |   j                  }|t        j                  d|       y t        j                  d	||       | j                   |   j                  }	 |j                  | |      S # t        $ r+}t        j                  d||j                         Y d }~y d }~ww xY w# t        $ r"}t        j                  d
|||       Y d }~y d }~ww xY w)Nzoslo.config.driverT)invoke_on_loaddriver)rC  r   r   z(could not load configuration from %r. %sz9could not load configuration from %r, no 'driver' is set.z&loading configuration from %r using %rz8could not load configuration from %r using %s driver: %s)rq  	stevedoreExtensionManagerrv  rA  r  _SOURCE_DRIVER_OPTION_HELPr  ry   r   errorr(   infoobjopen_source_from_opt_groupr   )r   rF   driver_namer  r  s        r   r  z&ConfigOpts._open_source_from_opt_group  s)   }}%66$#%DM 	8==..024 	 	 		z*11K IIK 9[	* {+//	44T:FF% $ 	II:CGG% 		&  	IIJK. 		s0   %C >D 	D!C??D	D2D--D2c                 h    	 | j                  |      S # t        $ r  t        $ r t        |      w xY w)zLook up an option value and perform string substitution.

        :param name: the opt name (or 'dest', more precisely)
        :returns: the option value (after string substitution) or a GroupAttr
        :raises: ValueError or NoSuchOptError
        )_getr   r   r8   r   rD   s     r   __getattr__zConfigOpts.__getattr__  s:    	'99T?" 	 	' &&	's    1c                 $    | j                  |      S z8Look up an option value and perform string substitution.r  r   r  s     r   __getitem__zConfigOpts.__getitem__  s    $$r   c                 >    || j                   v xs || j                  v S z<Return True if key is the name of a registered opt or group.)r  rb  r  s     r   __contains__zConfigOpts.__contains__  s    djj 7C4<<$77r   c              #      K   t        j                  t        | j                  j	                               t        | j
                  j	                                     D ]  }|  ywz0Iterate over all registered opt and group names.N)	itertoolschainlistr  keysrb  r  s     r   __iter__zConfigOpts.__iter__  sJ     ??4

(9#:#'(9(9(;#<> 	CI	s   A#A%c                 X    t        | j                        t        | j                        z   S z/Return the number of options and option groups.)rI  r  rb  r*   s    r   __len__zConfigOpts.__len__  s    4::T\\!222r   c                 D    | j                          | j                          y)z8Clear the object state and unset overrides and defaults.N)_unset_defaults_and_overridesr  r*   s    r   resetzConfigOpts.reset  s    **,

r   c                     d| _         d| _        d| _        d| _        d| _        | j                  | j                         | j                  j                         D ]  }|j                           y)aE  Reset the state of the object to before options were registered.

        This method removes all registered options and discards the data
        from the command line and configuration files.

        Any subparsers added using the add_cli_subparsers() will also be
        removed as a side-effect of this method.
        NF)
rd  re  rf  rg  ro  unregister_optsrk  rb  r  r  r   r<   s     r   r  zConfigOpts.clear  sb     
(-%T../\\((* 	ELLN	r   c                     ||d| j                   v ry |j                  r| j                   j                  ||d       y | j                   j                  ||d       y )Nr   r<   )rn  r   r   
appendleftr   r   r<   s      r   _add_cli_optzConfigOpts._add_cli_opt  sK    '4>>9>>NN!!#">?NN%%cE&BCr   c                    t        |d      rz|j                  D ]j  }|j                  xs d}|j                  }|r|j	                  dd      }|| j
                  vr|||di| j
                  |<   V||d| j
                  |   |<   l y y )Nr   r@   r   r   r  )hasattrr   r<   rD   r   rc  )r   r   r<   dep_optr3  dep_dests         r   _track_deprecated_optsz!ConfigOpts._track_deprecated_opts  s    3)*.. #MM6Y	"<<'//S9HD$9$99 #&%*#8D)))4  #!&BD)))4X> +r   c                    |L| j                  |d      }|r| j                  ||       | j                  ||       |j                  ||      S |0|j                  | j
                  v rt        d|j                  z        |r| j                  |d       t        | j                  |      ry||d| j                  |j                  <   | j                  |       y)a  Register an option schema.

        Registering an option schema makes any option value which is previously
        or subsequently parsed from the command line or config files available
        as an attribute of this object.

        :param opt: an instance of an Opt sub-class
        :param group: an optional OptGroup object or group name
        :param cli: whether this is a CLI option
        :return: False if the opt was already registered, True otherwise
        :raises: DuplicateOptError
        NT)
autocreater   z%Name %s was reserved for oslo.config.Fr  )

_get_groupr  r  r  rD   disallow_namesr   r   r  r   )r   r   r<   r  s       r   rv  zConfigOpts.register_opt	  s     OOEdO;E!!#u-''5'9&&sC00
 =xx4... !H#&88", - - c4(djj#.'*37

388##C(r   c                 :    |D ]  }| j                  ||d        y)z)Register multiple option schemas at once.Fr  N)rv  r   r   r<   r   s       r   register_optszConfigOpts.register_opts*	  s(      	=Cc5e<	=r   c                 Z    | j                   t        d      | j                  ||dd      S )a  Register a CLI option schema.

        CLI option schemas must be registered before the command line and
        config files are parsed. This is to ensure that all CLI options are
        shown in --help and option validation works as expected.

        :param opt: an instance of an Opt sub-class
        :param group: an optional OptGroup object or group name
        :return: False if the opt was already registered, True otherwise
        :raises: DuplicateOptError, ArgsAlreadyParsedError
        zcannot register CLI optionTF)r  r  )rd  r3   rv  r  s      r   register_cli_optzConfigOpts.register_cli_opt0	  s4     ::!()EFF  e5 IIr   c                 :    |D ]  }| j                  ||d        y)z-Register multiple CLI option schemas at once.Fr  N)r  r  s       r   r  zConfigOpts.register_cli_optsB	  s*      	AC!!#u%!@	Ar   c                     |j                   | j                  v ryt        j                  |      | j                  |j                   <   y)zRegister an option group.

        An option group must be registered before options can be registered
        with the group.

        :param group: an OptGroup object
        N)rD   rb  r   r  s     r   register_groupzConfigOpts.register_groupH	  s2     ::%#'99U#3UZZ r   c                    | j                   t        d      d}| j                  D ]P  }|d   j                  |j                  k(  s |,| j	                  |      j
                  |d   j
                  k(  sN|} n || j                  j                  |       |!| j	                  |      j                  |       y|j                  | j                  v r| j                  |j                  = yy)zUnregister an option.

        :param opt: an Opt object
        :param group: an optional OptGroup object or group name
        :raises: ArgsAlreadyParsedError, NoSuchGroupError
        Nz"reset before unregistering optionsr   r<   )	rd  r3   rn  r   r  rD   remover  r  )r   r   r<   remitemitems        r   unregister_optzConfigOpts.unregister_optU	  s     ::!()MNNNN 	DU  CHH,OOE*//4=3E3EE	 NN!!'*OOE"2237XX#

388$ $r   c                 :    |D ]  }| j                  ||d        y)z/Unregister multiple CLI option schemas at once.Fr  N)r  r  s       r   r  zConfigOpts.unregister_optso	  s(      	?CU>	?r   c                 >    t        |       | j                  ||       y)a  Import an option definition from a module.

        Import a module and check that a given option is registered.

        This is intended for use with global configuration objects
        like cfg.CONF where modules commonly register options with
        CONF at module load time. If one module requires an option
        defined by another module it can use this method to explicitly
        declare the dependency.

        :param name: the name/dest of the opt
        :param module_str: the name of a module to import
        :param group: an option OptGroup object or group name
        :raises: NoSuchOptError, NoSuchGroupError
        N)
__import___get_opt_info)r   rD   
module_strr<   s       r   
import_optzConfigOpts.import_optu	  s      	:4'r   c                 <    t        |       | j                  |       y)aY  Import an option group from a module.

        Import a module and check that a given option group is registered.

        This is intended for use with global configuration objects
        like cfg.CONF where modules commonly register options with
        CONF at module load time. If one module requires an option group
        defined by another module it can use this method to explicitly
        declare the dependency.

        :param group: an option OptGroup object or group name
        :param module_str: the name of a module to import
        :raises: ImportError, NoSuchGroupError
        N)r  r  )r   r<   r  s      r   import_groupzConfigOpts.import_group	  s     	:r   c                     | j                  ||      }| j                  |d   |      |d<   t        t        j                  t        d            |d<   y)aI  Override an opt value.

        Override the command line, config file and default values of a
        given option.

        :param name: the name/dest of the opt
        :param override: the override value
        :param group: an option OptGroup object or group name

        :raises: NoSuchOptError, NoSuchGroupError
        r   overrider   r"   N)r  _get_enforced_type_valuer!   r   r   r   )r   rD   r  r<   opt_infos        r   r   zConfigOpts.set_override	  sT     %%dE2#<<UOX '+""q! 
r   c                     | j                  ||      }| j                  |d   |      |d<   t        t        j                  t        d            |d<   y)a  Override an opt's default value.

        Override the default value of given option. A command line or
        config file value will still take precedence over this default.

        :param name: the name/dest of the opt
        :param default: the default value
        :param group: an option OptGroup object or group name

        :raises: NoSuchOptError, NoSuchGroupError
        r   r   r   r"   N)r  r  r!   r   r   r   )r   rD   r   r<   r  s        r   r   zConfigOpts.set_default	  sT     %%dE2";;UOW&+!!q! 
r   c                 ,    |y | j                  ||      S r   )_convert_value)r   r   r  s      r   r  z#ConfigOpts._get_enforced_type_value	  s    =""5#..r   c                 L    | j                  ||      }|j                  dd       y)a?  Clear an override an opt value.

        Clear a previously set override of the command line, config file
        and default values of a given option.

        :param name: the name/dest of the opt
        :param group: an option OptGroup object or group name
        :raises: NoSuchOptError, NoSuchGroupError
        r  Nr  r  r   rD   r<   r  s       r   clear_overridezConfigOpts.clear_override	  s$     %%dE2Z&r   c                 L    | j                  ||      }|j                  dd       y)a   Clear an override an opt's default value.

        Clear a previously set override of the default value of given option.

        :param name: the name/dest of the opt
        :param group: an option OptGroup object or group name
        :raises: NoSuchOptError, NoSuchGroupError
        r   Nr  r  s       r   clear_defaultzConfigOpts.clear_default	  s$     %%dE2Y%r   c              #      K   | j                   j                         D ]  }|df 
 | j                  j                         D ]'  }|j                   j                         D ]  }||f 
 ) yw)z-A generator function for iteration opt infos.N)r  r  rb  r   r  r<   s      r   _all_opt_infoszConfigOpts._all_opt_infos	  sn     JJ%%' 	D*	\\((* 	"E**, "Ek!"	"s   A+A-c              #   F   K   | j                   D ]  }|d   |d   f  yw)z,A generator function for iterating CLI opts.r   r<   N)rn  )r   r  s     r   r  zConfigOpts._all_cli_opts	  s,     NN 	-Du+tG},,	-s   !c                 |    | j                         D ])  \  }}|j                  dd       |j                  dd       + y)z-Unset any default or override on all options.r   Nr  )r  r  r  s      r   r  z(ConfigOpts._unset_defaults_and_overrides	  s:    ..0 	'KD%HHY%HHZ&	'r   c                 J    | j                   g S | j                   j                  S r   )rf  r  r*   s    r   config_dirszConfigOpts.config_dirs	  s!    ??"I+++r   c                    | j                   s
t               g }| j                   j                  r5| j                   j                  D ]  }|j                  t	        |              t        | j                        D ]9  }|j                  t        j                  j                  t	        |                   ; |j                  t        | j                               t        ||      S )a  Locate a file located alongside the config files.

        Search for a file with the supplied basename in the directories
        which we have already loaded config files from and other known
        configuration directories.

        The directory, if any, supplied by the config_dir option is
        searched first. Then the config_file option is iterated over
        and each of the base directories of the config_files values
        are searched. Failing both of these, the standard directories
        searched by the module level find_config_files() function is
        used. The first matching file is returned.

        :param name: the filename, for example 'policy.json'
        :returns: the path to a matching file, or None
        )rf  r/   r  r   r   reversedrs   r}   r~   dirnamer   r   r   r   )r   rD   r   	directorycfs        r   	find_filezConfigOpts.find_file	  s    " %''??''!__99 1	HY/01 4++, 	7BKK56	7 	$T\\23D$''r   c                    |j                  |d       |j                  |d       |j                  |d| j                         |j                  |dt        | d      xr | j                  xs g        |j                  |d       d }t	        | j
                        D ];  }| j                  |      d   }|j                  |d	| ||t        | |                   = t        | j                        D ]  }| j                  | | j                  |            }t	        | j                  |   j
                        D ]A  }| j                  ||      d   }|j                  |d	|d
| ||t        ||                   C  |j                  |d       y)a  Log the value of all registered opts.

        It's often useful for an app to log its configuration to a log file at
        startup for debugging. This method dumps to the entire config state to
        the supplied logger at a given log level.

        :param logger: a logging.Logger object
        :param lvl: the log level (for example logging.DEBUG) arg to
                    logger.log()
        zP********************************************************************************z$Configuration options gathered from:zcommand line args: %szconfig files: %srs   zP================================================================================c                 "    | j                   s|S dS )z,Obfuscate values of options declared secret.z****)r   )r   r  s     r   	_sanitizez,ConfigOpts.log_opt_values.<locals>._sanitize/
  s     #

577r   r   z
%-30s = %sr   N)logrd  r  rs   r  r  r  rO  r  rb  	GroupAttrr  )r   loggerlvlr  r;   r   rF   
group_attrs           r   log_opt_valueszConfigOpts.log_opt_values
  su    	

3!

3>?

3/<

3*4/DD4D4DJ	L

3!	8 tzz* 	@H$$X.u5CJJsL( gdH&=>@	@
 t||, 	JJdooj.IJJ"4<<
#;#A#AB J((:>uE

3&0(;$S'*h*GHJJ	J 	

3!r   c                 f    | j                   s
t               | j                   j                  |       y)at  Print the usage message for the current program.

        This method is for use after all CLI options are known
        registered using __call__() method. If this method is called
        before the __call__() is invoked, it throws NotInitializedError

        :param file: the File object (if None, output is on sys.stdout)
        :raises: NotInitializedError
        N)re  r/   rY  r   rW  s     r   rY  zConfigOpts.print_usageB
  s&     }}%''!!$'r   c                 f    | j                   s
t               | j                   j                  |       y)as  Print the help message for the current program.

        This method is for use after all CLI options are known
        registered using __call__() method. If this method is called
        before the __call__() is invoked, it throws NotInitializedError

        :param file: the File object (if None, output is on sys.stdout)
        :raises: NotInitializedError
        N)re  r/   rU  r  s     r   rU  zConfigOpts.print_helpP
  s&     }}%''  &r   c                     t        |t              r|j                  |f}n||f}|	 | j                  |   S | j                  |||      \  }}|| j                  |<   |S # t        $ r Y 2w xY wr   )r   r  rD   ri  r  _do_get)r   rD   r<   r  r  r  r  s          r   r  zConfigOpts._get^
  s|    eX&::t$C$-C||C(( \\$y9
s!S	  s   A 	A)(A)c           	      V    1| j                   v r# j                    j                  |            dfS  j                  |      }|d   d|v r|d   }nj                  }t        t              r j                   j                        dfS d|v r j                  |d         |fS  fd}rj                  nd}||f}t        j                  df}	 j                  r j                  j                  ||      }	j                   r j"                   j$                  	 d}
	 j'                  |      \  }}
|t        j                  k7  r'|
j(                  t*        j,                  k(  r
 ||      |
fS |	d   t        j                  k7  r ||	d         |	d   fS |t        j                  k7  r
 ||      |
fS 	 	  j@                  |   S # t.        $ r_ t1        t*        j2                   j                  j5                  ||            }
|	d   t        j                  k7  r ||	d         |	d   fcY S Y ww xY w# t6        $ rV}dj                  d	
d
t9        |      }|
j(                  t*        j:                  k(  rt=        |      t?        |      d}~ww xY w# t.        $ r Y nw xY w jB                  D ]N  }|j                  ||      }|d   t        j                  k7  s- ||d         |d   f}| j@                  |<   |c S  d|v r j                  |d         |fS  jD                  rUjF                  I	  |jF                         n5# t6        $ r)}t=        dj                  d
t9        |            d}~ww xY wjF                   |jF                        |fS y)a  Look up an option value.

        :param name: the opt name (or 'dest', more precisely)
        :param group: an OptGroup
        :param namespace: the namespace object to get the option value from
        :returns: 2-tuple of the option value or a GroupAttr object
                  and LocationInfo or None
        :raises: NoSuchOptError, NoSuchGroupError, ConfigFileValueError,
                 TemplateSubstitutionError
        Nr   r"   r  c                 J    j                  j                  |             S r   )r  _substitute)r  r<   r  r   r   s    r   convertz#ConfigOpts._do_get.<locals>.convert
  s,    &&  y93@ @r   r   r	   r  z from r  r   zDefault value for option rn  )$rb  r
  r  r  r   r   r  SubCommandAttrr   r  rD   r   _NoValuerr  ru  r   r   rg  rf  r  r"   r   r   r  r!   r   get_namer   r   r   ry   rv   rj  rp  ro  r   )r   rD   r<   r  r  r  r  rF   r  env_valalt_locr.  r!  messager  r  er   s   ` ``             @r   r  zConfigOpts._do_getl
  s    =TT\\1NN4)>?FF!!$.5kz"C##Cc=)''eSXX>EE$$T*%56<<	@ $)UZZd
4  ##T*==&&**:tSAG;;9,((II 6A#&#:#:9;E$GLC w/// ' 0 0I4J4J J 'g66qzW%5%55 '
 3WQZ@@g... 'g66 /(	'',,'   A*!--((11*dCG qzW%5%55 '
 3WQZ@@ 6A  6HHgs2w0 ##y~~5.w77,W556  		 mm 	F**Zs3C1v)))!#a&/3q62,2$$S)	 $$T)_5s;;(({{&.CKK(! ..88SV-. ..
 ;;"CKK(#..s{   0I 3AG %G (G I J# A#H>9I ;I =H>>I 	J 
AJJ #	J/.J/M 	N$NNc           
         t        |t              r"|D cg c]  }| j                  |||       c}S t        |t              rLd|v r|j	                  dd      }| j                  |      }|j                  | j                  | ||            }|S t        |t              rH|j                         D ci c],  \  }}| j                  |||      | j                  |||      . c}}S |S c c}w c c}}w )a  Perform string template substitution.

        Substitute any template variables (for example $foo, ${bar}) in
        the supplied string value(s) with opt values.

        :param value: the string value, or list of string values
        :param group: the group that retrieves the option value from
        :param namespace: the namespace object that retrieves the option
                          value from
        :returns: the substituted string(s)
        r<   r  r   r   )
r   r  r  r   r   Templatesafe_substituteStrSubWrapperr   r  )	r   r  r<   r  ir   r6   r  r.  s	            r   r  zConfigOpts._substitute
  s    eT""$ $$Qey$I $ $s# ~eT2=='D&&""4u	"JLCJt$ %*KKM3 S $$S$K$$S$KL 3 3 L%$3s   C)21C.c                       e Zd ZdZy)ConfigOpts.Templatez[_a-z][\._a-z0-9]*N)r   r   r   	idpatternr    r   r   r!  r&  
  s    )	r   r!  c                     |j                   r|D cg c]  }|j                  |       c}S |j                  |      S c c}w )ae  Perform value type conversion.

        Converts values using option's type. Handles cases when value is
        actually a list of values (for example for multi opts).

        :param value: the string value, or list of string values
        :param opt: option definition (instance of Opt class or its subclasses)
        :returns: converted value
        )r  r   )r   r  r   r   s       r   r  zConfigOpts._convert_value
  s7     99)./ACHHQK//88E?" 0s   =c                     t        |t              r|nd}|r|j                  n|}|| j                  vr,|st	        |      | j                  |xs t        |             | j                  |   S )a  Looks up a OptGroup object.

        Helper function to return an OptGroup given a parameter which can
        either be the group's name or an OptGroup object.

        The OptGroup object returned is from the internal dict of OptGroup
        objects, which will be a copy of any OptGroup object that users of
        the API have access to.

        If autocreate is True, the group will be created if it's not found. If
        group is an instance of OptGroup, that same instance will be
        registered, otherwise a new instance of OptGroup will be created.

        :param group_or_name: the group's name or the OptGroup object itself
        :param autocreate: whether to auto-create the group if it's not found
        :raises: NoSuchGroupError
        Nr  )r   r  rD   rb  rH   r  )r   group_or_namer  r<   rF   s        r   r  zConfigOpts._get_group
  sb    $ ",M8!D$#(UZZm
T\\)&z22 Bz)BC||J''r   c                     d }d }|xs d}t        |d      r|j                  }| j                  j                  |      }|r6|j                  |      }|r#|d   j                  }|d   r|d   j                  }||fS )Nr@   rD   r   r<   )r  rD   rc  r   )r   r;   r<   real_opt_namereal_group_namerF   r3  real_opt_dicts           r   _find_deprecated_optsz ConfigOpts._find_deprecated_opts'  s    'i
:v&#J))--j9	%MM(3M -e 4 9 9 )&3G&<&A&AOo--r   c                 <   || j                   }n| j                  |      }|j                   }||vrh| j                  ||      \  }}|st        ||      |xs d}d}t        j                  |||||d       |}|r| j                  |      }|j                   }||   S )zReturn the (opt, override, default) dict for an opt.

        :param opt_name: an opt name/dest
        :param group: an optional group name or OptGroup object
        :raises: NoSuchOptError, NoSuchGroupError
        r   r@   zcConfig option %(dep_group)s.%(dep_option)s  is deprecated. Use option %(group)s.%(option)s instead.r1  )r  r  r/  r8   r   r   )r   r;   r<   r   r,  r-  log_real_group_namedep_messages           r   r  zConfigOpts._get_opt_info6  s     =::DOOE*E;;D4-1-G-G .H .'*M? $Xu55"1">Y1K KKH380=/B&D E %H8{{H~r   c                     | j                         D ]S  \  }}|d   }|j                  sd|v sd|v r!| j                  |j                  ||      ?t	        |j
                  |       y)zCheck that all opts marked as required have values specified.

        :param namespace: the namespace object be checked the required options
        :raises: RequiredOptError
        r   r   r  N)r  r   r  r   rS   rD   )r   r  r  r<   r   s        r   r  zConfigOpts._check_required_optsW  sj      ..0 	<KD%u+C||$
d(:99SXXui8@*388U;;	<r   c                     || _         | j                         D ]!  \  }}|j                  | j                  |       # | j	                         S )aw  Parse command line options.

        Initializes the command line option parser and parses the supplied
        command line arguments.

        :param args: the command line arguments
        :returns: a _Namespace object containing the parsed option values
        :raises: SystemExit, DuplicateOptError
                 ConfigFileParseError, ConfigFileValueError

        )rd  r  r!  re  _parse_config_files)r   r'  r   r<   s       r   r  zConfigOpts._parse_cli_optsg  sJ     
,,. 	2JCOODMM51	2 ''))r   c                    t        |       }| j                  D ]  }|dk(  s|j                  d      s n( | j                  D ]  }t        j                  ||        | j                  D ]  }|dk(  s|j                  d      s n | j                  D ]{  }t        j                  j                  |      s#t        j                  j                  |d      }t        t        j                  |            D ]  }t        j                  ||        } | j                  j                  | j                  |       | j                  |       |S )zParse configure files options.

        :raises: SystemExit, ConfigFilesNotFoundError, ConfigFileParseError,
                 ConfigFilesPermissionDeniedError,
                 RequiredOptError, DuplicateOptError
        z--config-filez--config-file=z--config-dirz--config-dir=r  )r  rd  r   r\  r  r  r]  r}   r~   r   rc   r  r  re  rS  _validate_cli_options)r   r  r$  rs   rm   r  s         r   r5  zConfigOpts._parse_config_filesy  s1    t$	 :: 	ACo%8H)I	A  $88 A((i@A :: 	ECn$(G	E #66 
E
 ww~~j1"$'',,z8"D#)$))O*D#E EK ,,[)DE
E 	  Y7""9-r   c                    t        | j                         d       D ]R  \  }}|r|j                  nd }	 |j                  ||      \  }}| j                  |||      }	 | j                  ||       T y # t        $ r Y aw xY w# t        $ rM t        j                  j                  d|j                  dt        |j                        d|d       t        w xY w)Nc                      | d   j                   S )Nr   r  r  s    r   r  z2ConfigOpts._validate_cli_options.<locals>.<lambda>  s    qtyy r   rG  r   zargument --z
: Invalid z value: rN  )r  r  rD   r  r  r  r  r   r   stderrwriter   reprr   
SystemExit)r   r  r   r<   rF   r  r  s          r   r7  z ConfigOpts._validate_cli_options  s     !3!3!5%8: 	!JC',$J 44Y
K
s $$U%9$ME!##E3/	!
    !

  HHd388ne"5 6  !s   A3B3	A?>A?ACc                     | j                         }|j                  rt        |j                        |j                  rt	        |j                        | j                  |       |S r   )r5  r  rZ   r  rf   r  )r   r  s     r   _reload_config_fileszConfigOpts._reload_config_files  s]    ,,.	%%*9+E+EFF--2224 4!!),r   c                     	 | j                         }|| _        y# t        $ r*}t        j	                  d|j
                         Y d}~yd}~wt        $ r }t        j	                  d|       Y d}~yd}~ww xY w)zReload configure files and parse all options

        :return: False if reload configure files failed or else return True
        TzDCaught SystemExit while reloading configure files with exit code: %dNFz0Caught Error while reloading configure files: %s)r?  rf  r=  r   r   coder%   )r   r  excr  s       r   reload_config_fileszConfigOpts.reload_config_files  sn    	113I (DO  	KK 347HH> 	KK !#	s     	A4 AA4A//A4c                 :    | j                   j                  |       y)zRegisters a hook to be called by mutate_config_files.

        :param hook: a function accepting this ConfigOpts object and a dict of
                     config mutations, as returned by mutate_config_files.
        :return: None
        N)rh  r4  )r   hooks     r   register_mutate_hookzConfigOpts.register_mutate_hook  s     	t$r   c           	         | j                   j                          | j                  xs | j                  }| j	                         | _        | j                          | j                  || j                        }d }t        |j                         |      }|D ],  \  \  }}\  }}|r|nd}t        j                  d||||d       . | j                  D ]  }	 |	| |        |S )aw  Reload configure files and parse all options.

        Only options marked as 'mutable' will appear to change.

        Hooks are called in a NON-DETERMINISTIC ORDER. Do not expect hooks to
        be called in the same order as they were added.

        :return: {(None or 'group', 'optname'): (old_value, new_value), ... }
        :raises: Error if reloading fails
        c                 (    | d   \  }}|r| d   S d|fS )Nr   	r    )r  	groupnameoptnames      r   key_fnz.ConfigOpts.mutate_config_files.<locals>.key_fn  s'     $(7 Y'47<dG_<r   rG  r@   zGOption %(group)s.%(option)s changed from [%(old_val)s] to [%(new_val)s])r<   r	  old_valnew_val)ri  r  rg  rf  r?  _warn_immutability_diff_nsr  r  r   r  rh  )
r   old_mutate_nsfreshrL  sorted_freshrJ  rK  oldnewrE  s
             r   mutate_config_fileszConfigOpts.mutate_config_files  s     	((;DOO446!mT-=-=>	=
 ekkm80< 	', Y*3%.	IIHH 6( '!$!$&'	' && 	Du	r   c                    | j                         D ]  \  }}|d   }|j                  r|r|j                  nd}	 |j                  | j                  |      \  }}	 |j                  | j                  |      \  }}||k7  snt        j                  d||j                  d        y# t
        $ r d}Y Yw xY w# t
        $ r d}Y Jw xY w)zCheck immutable opts have not changed.

        _do_get won't return the new values but presumably someone changed the
        config file expecting them to change so we should warn them they won't.
        r   r@   Nz8Ignoring change to immutable option %(group)s.%(option)s)r<   r	  )	r  r   rD   r  rf  r  rg  r   r   )r   r  r<   r   rJ  rT  r   rU  s           r   rO  zConfigOpts._warn_immutability   s      ..0 	FKD%u+C{{&+

I00)LQ001A1A9MQ cz 3&/388DF	F    s#   B%B6%B32B36CCc                 L   i }| j                         D ]l  \  }}|d   }|j                  s|r|j                  nd}	 |j                  ||      \  }}		 |j                  ||      \  }
}	||
k7  sZ||
f|||j                  f<   n |S # t        $ r d}Y @w xY w# t        $ r d}
Y ;w xY w)zCompare mutable option values between two namespaces.

        This can be used to only reconfigure stateful sessions when necessary.

        :return {(None or 'group', 'optname'): (old_value, new_value), ... }
        r   N)r  r   rD   r  r  )r   old_nsnew_nsdiffr  r<   r   rJ  rT  r   rU  s              r   rP  zConfigOpts._diff_ns  s     ..0 	9KD%u+C;;&+

I00CQ00CQ cz/2Cji*+	9     s#   BBBBB#"B#c                     t        g       }| j                  r&|t        | j                  j                               z  }| j                  r&|t        | j                  j                               z  }t	        |      S )zList all sections from the configuration.

        Returns a sorted list of all section names found in the
        configuration files, whether declared beforehand or not.
        )r  rg  r>  rf  r  )r   r   s     r   list_all_sectionszConfigOpts.list_all_sections1  sa     GT%%//122A??T__..011Aayr   c                 P    |t        |      nd}| j                  ||d      \  }}|S )a  Return the location where the option is being set.

        :param name: The name of the option.
        :type name: str
        :param group: The name of the group of the option. Defaults to
                      ``'DEFAULT'``.
        :type group: str
        :return: LocationInfo

        .. seealso::

           :doc:`/reference/locations`

        .. versionadded:: 5.3.0
        N)r  r  )r   rD   r<   	opt_groupr  r  s         r   get_locationzConfigOpts.get_location>  s/      (-'8HUOd	\\$	48
s
r   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	ConfigOpts.GroupAttrzdHelper class.

        Represents the option values of a group as a mapping and attributes.
        c                      || _         || _        y)zConstruct a GroupAttr object.

            :param conf: a ConfigOpts object
            :param group: an OptGroup object
            N)r  _group)r   r  r<   s      r   r   zConfigOpts.GroupAttr.__init__Y  s     DJDKr   c                 N    | j                   j                  || j                        S )z:Look up an option value and perform template substitution.)r  r  rd  r  s     r   r  z ConfigOpts.GroupAttr.__getattr__b  s    ::??455r   c                 $    | j                  |      S r  r  r  s     r   r  z ConfigOpts.GroupAttr.__getitem__f  s    ##C((r   c                 2    || j                   j                  v S r  )rd  r  r  s     r   r  z!ConfigOpts.GroupAttr.__contains__j  s    $++++++r   c              #   f   K   | j                   j                  j                         D ]  }|  ywr  )rd  r  r  r  s     r   r  zConfigOpts.GroupAttr.__iter__n  s-     {{((--/ 	s   /1c                 @    t        | j                  j                        S r  )rI  rd  r  r*   s    r   r  zConfigOpts.GroupAttr.__len__s  s    t{{(())r   N)
r   r   r   r-   r   r  r  r  r  r  r    r   r   r
  rb  R  s%    	
	 	6	)	,	
	*r   r
  c                       e Zd ZdZd Zd Zy)ConfigOpts.SubCommandAttrz\Helper class.

        Represents the name and arguments of an argparse sub-parser.
        c                 .    || _         || _        || _        y)zConstruct a SubCommandAttr object.

            :param conf: a ConfigOpts object
            :param group: an OptGroup object
            :param dest: the name of the sub-parser
            N)r  rd  _dest)r   r  r<   r   s       r   r   z"ConfigOpts.SubCommandAttr.__init__~  s     DJDKDJr   c                 X   |dk(  rT| j                   }| j                  | j                  j                  dz   |z   }t        | j                  j
                  |      S || j                  v rt        |      	 t        | j                  j
                  |      S # t        $ r t        |      w xY w)z,Look up a sub-parser name or argument value.rD   r   )	rm  rd  rD   rO  r  rf  rN   AttributeErrorr8   r  s     r   r  z%ConfigOpts.SubCommandAttr.__getattr__  s    v~zz;;*;;++c1D8Dtzz44d;;tzz!'--+tzz44d;;! +$T**+s   4B B)N)r   r   r   r-   r   r  r    r   r   r  rk  w  s    	
			+r   r  c                       e Zd ZdZddZd Zy)ConfigOpts.StrSubWrapperzUHelper class.

        Exposes opt values as a dict for string substitution.
        Nc                 .    || _         || _        || _        y)zConstruct a StrSubWrapper object.

            :param conf: a ConfigOpts object
            :param group: an OptGroup object
            :param namespace: the namespace object that retrieves the option
                              value from
            N)r  r<   r  )r   r  r<   r  s       r   r   z!ConfigOpts.StrSubWrapper.__init__  s     DIDJ&DNr   c                    	 |j                  dd      \  }}t        |      }	 | j                  j                  ||| j                        }t        || j                  j                        rt        d|z        |y|S # t        $ r | j                  }|}Y uw xY w# t        $ r* | j                  j                  || j                        }Y w xY w)zLook up an opt value from the ConfigOpts object.

            :param key: an opt name
            :returns: an opt value
            r   r	   r  r   )r  z#substituting group %s not supportedr   )splitr  r   r<   r  r  r  r8   r   r
  rW   )r   r  rF   r	  r<   r  s         r   r  z$ConfigOpts.StrSubWrapper.__getitem__  s    2%(YYsA%6"
F
 !j1F		vU15 ' A %!4!45/9C?A A}L  

 " F		sdnnEFs"   A? (B ?BB0CCrn  )r   r   r   r-   r   r  r    r   r   r#  rq    s    	

	'	r   r#  )NNNNNNNFNNTr   )NFrn  r  )Mr   r   r   r-   r  rp  rw  r   rz  staticmethodr~  r  r  r  _ConfigOpts__clear_cache _ConfigOpts__clear_drivers_cacher  r  r  r  r  r  r  r  r  r  r  r  rv  r  r  r  r  r  r  r  r  r   r   r  r  r  r  r  r  propertyr  r  r  rY  rU  r  r  r  stringr!  r  r  r/  r  r  r  r5  r7  r?  rC  rF  rV  rO  rP  r]  r`  r   Mappingr
  r  r#  r    r   r   r[  r[    s   	NN !7	32?4 
 
0   

 &*%)).!B$H-%N'%83
  &D( $ $L = =
 J J" A A
4 % %2 ? ?
(&$ 
 
( 
 
(/ ' ' 
& 
&"-
' , ,
(>#"J('iVB*6?? *#(:.B< *$&P!$   (%"HF02(#*CKK #*J +  +D* *r   r[  r   r4  )NNz.conf)NNz.conf.d)r
   )`r-   r  rl  r   r   enumr  r  r  r   r  loggingr}   ry  r   r   ImportErroroslo_configr   r    oslo_config.sources._environmentrs  r   r  	getLoggerr   r   r  Enumr   
namedtupler!   r   r%   r/   r3   ro  r8   rH   rN   rS   rW   rZ   rf   rj   rp   r   rv   ry   r{   r   r   r   r   r   r   r   boolr   r   r   r   r   r   r   total_orderingr   r   rA  rU  rb  rj  rp  rv  rz  r  r  r  r  r  r  r  r  r  r  r  r  
BaseParserr  	Namespacer  ArgumentParserr@  rz  r[  CONFr    r   r   <module>r     sS              	  

 "  7 7  g! 
5		 
5 &{%%nz86LMI @% @U 	OUN 	O6u 66 6
Ku 
K< <-u --u -NU NG5 G	UJ 	
	1 	
Ez E2
"&J"
*8>8<( BJJNN%' ( 2C-* ~* ~* ~*BC" C"LCS CL6c 6r/S /@1s 1*0c 0,Ic I .C .&Ac A>4# 4"7S 7,6C 6,@S @2#s #L4( 4"6%C 6%r-S -`5C 5pi iX:%% :Q/9'' Q/hr## rj8=H33 8=v] ]@) |Ae  Hs   K' 'K21K2