HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/ipalib/__pycache__/cli.cpython-36.pyc
3

�d[e=��
@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZyddlZddlZWnek
r�dZZYnXddlZddlmZddlmZmZmZmZejr�eZ ej!�re"e�ej#d�ddl$m%Z%ddl$m&Z&dd	l$m'Z'dd
l(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3m4Z4ddl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;dd
l<m=Z=ddl$m>Z>ddl?m@Z@ddlAmBZBddlCZCejDeE�ZFdd�ZGdd�ZHGdd�de&jI�ZJGdd�de%jK�ZLGdd�de%jM�ZNGdd�dejO�ZPGdd�de%jM�ZQGdd �d e%jM�ZReLeQeRfZSGd!d"�d"�ZTGd#d$�d$ejU�ZVGd%d&�d&ejW�ZXGd'd(�d(e&jY�ZZGd)d*�d*ejU�Z[eZeJeQeLeNfZ\d+d,�Z]dS)-z+
Functionality for Command Line Interface.
�)�print_functionN)�input)�check_client_configuration�	get_pager�get_terminal_height�
open_in_pagerzutf-8)�frontend)�backend)�plugable)	�PublicError�CommandError�	HelpError�
InternalError�NoSuchNamespaceError�ValidationError�NotFound�NotConfiguredError�PromptFailed)�CLI_TAB�LDAP_GENERALIZED_TIME_FORMAT)�File�
BinaryFile�Str�Enum�Any�Flag)�_)�api)�DNSName)�ScriptErrorcCst|t�st�|jdd�S)zl
    Takes a Python identifier and transforms it into form suitable for the
    Command Line Interface.
    r�-)�
isinstance�str�AssertionError�replace)�name�r&�/usr/lib/python3.6/cli.py�to_cliPsr(cCst|�jdd�S)zh
    Takes a string from the Command Line Interface and transforms it into a
    Python identifier.
    r r)r"r$)�cli_namer&r&r'�from_cliYsr*c@sFeZdZdZdd�ZdHdd�Zdd�Zejr>d	d
�Z	dd�Z
nd
d
�Z	dd�Z
dIdd�Zdd�Zdd�Z
dJdd�ZdKdd�ZdLdd�ZdMdd�ZdNd d!�Zdid"gdfd#d$�ZdOd%d&�ZdPd'd(�ZdQd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�ZdRd7d8�Zd9d:�Zefd;d<�Zd=d>�Z dSd@dA�Z!dTdBdC�Z"dUdDdE�Z#dVdFdG�Z$dS)W�textuiz;
    Backend plugin to nicely format output to stdout.
    cCsTtjj�rPy0tjtjtjtjddddd��}tj	d|�dSt
k
rNYnXdS)z�
        Return the width (in characters) of output tty.

        If stdout is not a tty, this method will return ``None``.
        ZHHHHr�N)�sys�stdout�isatty�fcntlZioctl�termiosZ
TIOCGWINSZ�struct�pack�unpack�IOError)�selfZwinsizer&r&r'�
get_tty_widthfs
ztextui.get_tty_widthNcsbt|�ttfkr"tdtt|f��t|�dkr2dS�dkrLtdd�|D��St�fdd�|D��S)a�
        Return the max width (in characters) of a specified column.

        For example:

        >>> ui = textui(api)
        >>> rows = [
        ...     ('a', 'package'),
        ...     ('an', 'egg'),
        ... ]
        >>> ui.max_col_width(rows, col=0)  # len('an')
        2
        >>> ui.max_col_width(rows, col=1)  # len('package')
        7
        >>> ui.max_col_width(['a', 'cherry', 'py'])  # len('cherry')
        6
        zrows: need %r or %r; got %rrNcss|]}t|�VqdS)N)�len)�.0�rowr&r&r'�	<genexpr>�sz'textui.max_col_width.<locals>.<genexpr>c3s|]}t|��VqdS)N)r8)r9r:)�colr&r'r;�s)�type�list�tuple�	TypeErrorr8�max)r6�rowsr<r&)r<r'�
max_col_widthwsztextui.max_col_widthcCs.|tjtjfkst�t|dd�dkr(dS|jS)N�encodingzUTF-8)r-�stdinr.r#�getattrrD)r6�streamr&r&r'Z__get_encoding�sztextui.__get_encodingcsLt|�tkr"�jtj�}|j|�St|�ttfkrHt�fdd�|D��S|S)z1
            Decode text from stdin.
            c3s|]}�j|�VqdS)N)�decode)r9�v)r6r&r'r;�sz textui.decode.<locals>.<genexpr>)r=�bytes�_textui__get_encodingr-rErHr>r?)r6�valuerDr&)r6r'rH�s
z
textui.decodecCs&t|�tkst�|jtj�}|j|�S)z;
            Encode text for output to stdout.
            )r=�unicoder#rKr-r.�encode)r6Zunicode_textrDr&r&r'rN�sz
textui.encodecCs|S)Nr&)r6rLr&r&r'rH�scCs|S)Nr&)r6rLr&r&r'rN�scCs |dks|dkr||S||S)Nr,r&)r6�n�singular�pluralr&r&r'�
choose_number�sztextui.choose_numbercCsNt|�tkrtj|�jd�St|�tjkr4|jt�St|t	�rFt
|�S|SdS)z�
        Convert a binary value to base64. We know a value is binary
        if it is a python bytes type, otherwise it is a plain string.
        This function also converts datetime and DNSName values to string.
        �asciiN)r=rJ�base64Z	b64encoderH�datetimeZstrftimerr!rrM)r6rLr&r&r'�
encode_binary�s

ztextui.encode_binarycCstt|��dS)z?
        Print exactly like ``print`` statement would.
        N)�printrM)r6�stringr&r&r'�print_plain�sztextui.print_plaincCsH|dkr|j�}|dk	r8|t|�kr8|d|d�d}tt|��dS)a�
        Force printing on a single line, using ellipsis if needed.

        For example:

        >>> ui = textui(api)
        >>> ui.print_line('This line can fit!', width=18)
        This line can fit!
        >>> ui.print_line('This line wont quite fit!', width=18)
        This line wont ...

        The above example aside, you normally should not specify the
        ``width``.  When you don't, it is automatically determined by calling
        `textui.get_tty_width()`.
        N�z...)r7r8rWrM)r6�text�widthr&r&r'�
print_line�s
ztextui.print_linecCs6|dkr|j�}x tj|j�|�D]}t|�q"WdS)a+
        Print a paragraph, automatically word-wrapping to tty width.

        For example:

        >>> text = '''
        ... Python is a dynamic object-oriented programming language that can
        ... be used for many kinds of software development.
        ... '''
        >>> ui = textui(api)
        >>> ui.print_paragraph(text, width=45)
        Python is a dynamic object-oriented
        programming language that can be used for
        many kinds of software development.

        The above example aside, you normally should not specify the
        ``width``.  When you don't, it is automatically determined by calling
        `textui.get_tty_width()`.

        The word-wrapping is done using the Python ``textwrap`` module.  See:

            http://docs.python.org/library/textwrap.html
        N)r7�textwrap�wrap�striprW)r6r[r\�liner&r&r'�print_paragraph�sztextui.print_paragraphr,cCstt||�dS)a~
        Print at specified indentation level.

        For example:

        >>> ui = textui(api)
        >>> ui.print_indented('One indentation level.')
          One indentation level.
        >>> ui.print_indented('Two indentation levels.', indent=2)
            Two indentation levels.
        >>> ui.print_indented('No indentation.', indent=0)
        No indentation.
        N)rWr)r6r[�indentr&r&r'�print_indentedsztextui.print_indentedcCs0x*|D]"\}}|jd||j|�f|�qWdS)a�
        Print (key = value) pairs, one pair per line.

        For example:

        >>> items = [
        ...     ('in_server', True),
        ...     ('mode', u'production'),
        ... ]
        >>> ui = textui(api)
        >>> ui.print_keyval(items)
          in_server = True
          mode = u'production'
        >>> ui.print_keyval(items, indent=0)
        in_server = True
        mode = u'production'

        Also see `textui.print_indented`.
        z%s = %rN)rdrV)r6rBrc�keyrLr&r&r'�print_keyvalsztextui.print_keyval�%s: %sTcs�t|t�st�t|ttf�s:�j||�j|�f|��nl|rjx&|D]}�j||�j|�f|�qDW�n<�fdd�|D�}t|�dkr�t|d�ttfkr�x0|D](}dj	|�}�j||�j|�f|�q�WdSt|�dkr�dj	dd�|D��}ndS�j
�}	|	�rZ|�rZd	t|d
t|�df}
|	t|
�8}	tj
||	dd
�}t|�dk�rddg}n
d}
|g}�j|||df|�x(|dd�D]}�jd	|
|f��q�WdS)a�
        Print an ldap attribute.

        For example:

        >>> attr = 'dn'
        >>> ui = textui(api)
        >>> ui.print_attribute(attr, u'dc=example,dc=com')
          dn: dc=example,dc=com
        >>> attr = 'objectClass'
        >>> ui.print_attribute(attr, [u'top', u'someClass'], one_value_per_line=False)
          objectClass: top, someClass
        >>> ui.print_attribute(attr, [u'top', u'someClass'])
          objectClass: top
          objectClass: someClass
        csg|]}�j|��qSr&)rV)r9rI)r6r&r'�
<listcomp>Bsz*textui.print_attribute.<locals>.<listcomp>rz: Nz, css|]}t|�VqdS)N)r")r9rIr&r&r'r;Ksz)textui.print_attribute.<locals>.<genexpr>z%s%s� �F)Zbreak_long_words�r,)r!r"r#r>r?rdrVr8r=�joinr7rr^r_rY)r6�attrrL�formatrc�one_value_per_linerI�lr[Zline_lenZs_indentrar&)r6r'�print_attribute's:
" 

ztextui.print_attributeZdncs�t�t�st�t�t�st�t|ttf�s.t�������fdd�}x"|D]���krJ|����=qJWxt��D]�|��qrWdS)z+
        Print an ldap entry dict.
        cs>��kr$�j������d�n�j�����d�dS)N)rcro)rq)�a)rm�attr_map�entryrcror6r&r'�
print_attris
z'textui.print_entry1.<locals>.print_attrN)r!�dictr#r>r?�sorted)r6rtrcrsZ
attr_orderrorur&)rmrsrtrcror6r'�print_entry1`s


ztextui.print_entry1c
	CsNt|ttf�st�d}x2|D]*}	|s,td�d}|j|	||||||�qWdS)NTrkF)r!r>r?r#rW�print_entry)
r6�entries�order�labels�flags�	print_allrnrc�firstrtr&r&r'�
print_entrieszs
ztextui.print_entriesc

Cs�t|ttf�rt|�}t|t�s$t�|dkr8t�}d}nd}|dk	�rP�x|D]�}	|	|kr\qN|j|	|	�}
|j|	g�}||	}d|kr�|ddfgdgkr�qNt|t�r�tj|�dkr�qN|j||
df|�|j	|||||||dd�nbt|ttf��r4t
dd	�|D���r4|j|
d||�|j|||||||d�n|j|
||||�||	=qNW|�r�x4t
|�D](}	|j|	|	�}
|j|	||	|||��q`WdS)
NTFZsuppress_emptyrkrr,)rccss|]}t|t�VqdS)N)r!rv)r9�valr&r&r'r;�sz%textui.print_entry.<locals>.<genexpr>)r!r>r?rvr#�getrZentry_countrdry�allrqr�rw)
r6rtr{r|r}r~rnrcrore�label�flagrLr&r&r'ry�sJ


ztextui.print_entryrr cCsZt|t�st�t|�dkst�|t|�}|r:|j||�|j||�|rV|j||�dS)a�
        Print a string with a dashed line above and/or below.

        For example:

        >>> ui = textui(api)
        >>> ui.print_dashed('Dashed above and below.')
        -----------------------
        Dashed above and below.
        -----------------------
        >>> ui.print_dashed('Only dashed below.', above=False)
        Only dashed below.
        ------------------
        >>> ui.print_dashed('Only dashed above.', below=False)
        ------------------
        Only dashed above.
        r,N)r!r"r#r8rd)r6rXZaboveZbelowrc�dashZdashesr&r&r'�print_dashed�sztextui.print_dashedcCs|j|ddd�dS)z�
        Print a primary header at indentation level 0.

        For example:

        >>> ui = textui(api)
        >>> ui.print_h1('A primary header')
        ================
        A primary header
        ================
        r�=)rcr�N)r�)r6r[r&r&r'�print_h1�sztextui.print_h1cCs|j|ddd�dS)z�
        Print a secondary header at indentation level 1.

        For example:

        >>> ui = textui(api)
        >>> ui.print_h2('A secondary header')
          ------------------
          A secondary header
          ------------------
        r,r )rcr�N)r�)r6r[r&r&r'�print_h2�sztextui.print_h2cCs|jdt|��dS)ae
        Print a command name.

        The typical use for this is to mark the start of output from a
        command.  For example, a hypothetical ``show_status`` command would
        output something like this:

        >>> ui = textui(api)
        >>> ui.print_name('show_status')
        ------------
        show-status:
        ------------
        z%s:N)r�r()r6r%r&r&r'�
print_name�sztextui.print_namecCs|j||�dS)N)r�)r6�msg�outputr&r&r'�print_header�sztextui.print_headercCs|j|�dS)z�
        Print a summary at the end of a comand's output.

        For example:

        >>> ui = textui(api)
        >>> ui.print_summary('Added user "jdoe"')
        -----------------
        Added user "jdoe"
        -----------------
        N)r�)r6r�r&r&r'�
print_summary�sztextui.print_summarycCsBt|�tk	r*t|�tttfks"t�t|�}|j|j|||��dS)a�
        Print a summary count.

        The typical use for this is to print the number of items returned
        by a command, especially when this return count can vary.  This
        preferably should be used as a summary and should be the final text
        a command outputs.

        For example:

        >>> ui = textui(api)
        >>> ui.print_count(1, '%d goose', '%d geese')
        -------
        1 goose
        -------
        >>> ui.print_count(['Don', 'Sue'], 'Found %d user', 'Found %d users')
        -------------
        Found 2 users
        -------------

        If ``count`` is not an integer, it must be a list or tuple, and then
        ``len(count)`` is used as the count.
        N)	r=�intr>r?rvr#r8r�rR)r6�countrPrQr&r&r'�print_count	s
ztextui.print_countcCstdt|��dS)Nz
  ** %s **)rWrM)r6r[r&r&r'�print_error(sztextui.print_errorcCsBy|j||j|���Sttfk
r<t�t|d��YnXdS)z�Prompt user for input

        Handles encoding the prompt and decoding the input.
        On end of stream or ctrl+c, raise PromptFailed.
        )r%N)rHrN�KeyboardInterrupt�EOFErrorrWr)r6�promptr��prompt_funcr&r&r'�
prompt_helper+s
ztextui.prompt_helpercCs|jd||f�dS)Nz
>>> %s: %s)rY)r6Z	attribute�errorr&r&r'�print_prompt_attribute_error7sz#textui.print_prompt_attribute_errorFcCs@|rd|}nd|}|dkr(d|}nd||f}|j||�S)z(
        Prompt user for input.
        z[%s]z%sNz%s: z	%s [%s]: )r�)r6r��defaultZ
get_values�optionalr�r&r&r'r�:s

z
textui.promptcCszd}|dk	r|rd}nd}|r,d||f}nd|}x@|j||�j�}|d
krRdS|dkr^dS|dk	r6|dkr6|Sq6W|S)a�
        Prompt user for yes/no input. This method returns True/False according
        to user response.

        Parameter "default" should be True, False or None

        If Default parameter is not None, user can enter an empty input instead
        of Yes/No answer. Value passed to Default is returned in that case.

        If Default parameter is None, user is asked for Yes/No answer until
        a correct answer is provided. Answer is then returned.
        NZYesZNoz%s Yes/No (default %s): z%s Yes/No: �yes�yTrO�noFrk)r�r�)rOr�)r��lower)r6r�r�Zdefault_promptr��datar&r&r'�prompt_yesnoIs"ztextui.prompt_yesnocCs�tjj�rzdt|�}ttd�t|d��}x`|j||tjd�}|sH|S|j||tjd�}||krf|S|jtd��q.Wn|j	tjj
�j��SdS)zx
        Prompt user for a password or read it in via stdin depending
        on whether there is a tty or not.
        z%s: z!Enter %(label)s again to verify: )r�)r�zPasswords do not match!N)r-rEr/rMrrvr��getpassr�rH�readliner`)r6r��confirmr�Z
repeat_promptZpw1Zpw2r&r&r'�prompt_passwordos
ztextui.prompt_passwordcCsL|jjstjj�rdSt|�}|dkr8ttd�d��d}xL|D]D}i}x|D]}	|j|	d�||	<qPW|j	d|||f�|d}qBW|r�|j
|dd�x�y|jd	|�}
Wntk
r�dSX|
j
�dkr�dS|
j
�dkr�dSy.t|
�d}||k�odkn�rPWntk
�r*YnX|j	d
|�q�W|j	d�|S)a�
        Display a list of lines in with formatting defined in ``format``.
        ``attrs`` is a list of attributes in the format.

        Prompt user for a selection and return the value (index of
        ``entries`` -1).

        If only one entry is provided then always return 0.

        Return: 0..n for the index of the selected entry
                -1 if all entries should be displayed
                -2 to quit, no entries to be displayed
        r,rzNo matching entries found)�reasonrkz%d: %szFound %d matchzFound %d matchesz*Choose one: (1 - %s), a for all, q to quitrj�qrrz&Please enter a number between 1 and %s������r�r�)�env�interactiver-r.r/r8rrr�r]r�r�r�r�r��	Exception)r6rzrnZattrsZ
display_countZcounter�i�e�drrZrespZ	selectionr&r&r'�select_entry�s@


ztextui.select_entry)N)N)N)N)r,)r,)rgr,T)NNNTrgr,)NNNTrgr,)TTrr )N)NNF)N)T)T)%�__name__�
__module__�__qualname__�__doc__r7rCrK�six�PY2rHrNrRrVrYr]rbrdrfrqrxr�ryr�r�r�r�r�r�r�r�rr�r�r�r�r�r�r&r&r&r'r+asF







9
	
.



&
r+cs�eZdZdZGdd�d�Zedded�ed�d�fZed	d
gd�fZ	e
�ZdZd
d�Z
dd�Z�fdd�Zddd�Zdd�Zdd�Z�ZS)�helpz.
    Display help for a command or topic.
    c@s6eZdZdZdd�Zedd��Zddd�Zd	d
�ZdS)
zhelp.Writerz$
        Writer abstraction
        cCs||_g|_dS)N)�outfile�buffer)r6r�r&r&r'�__init__�szhelp.Writer.__init__cCs*d}x |jD]}|t|jd��7}qW|S)Nr�
)r�r8�split)r6Zlengthrar&r&r'�
buffer_length�szhelp.Writer.buffer_lengthrkcCs|jjt|��dS)N)r��appendrM)r6rXr&r&r'r��szhelp.Writer.appendcCspt�}|r4|jt�kr4dj|j�jd�}t||�n8y"x|jD]}t||jd�q>WWnt	k
rjYnXdS)Nr�zutf-8)�file)
rr�rrlr�rNrrWr�r5)r6Zpagerr�rar&r&r'�write�szhelp.Writer.writeN)rk)	r�r�r�r�r��propertyr�r�r�r&r&r&r'�Writer�s

r�zcommand?�topiczTopic or CommandzThe topic or command name.)r)r��doczoutfile?�	no_option)r}NcCs�d}d}x�|jjD]�}dj|j|�}ytj|}Wn:tk
rlytj|�}Wnt	k
rfwYnXYnX|j
dk	r�t|j
p�d�j�}y
|j
}Wqtk
r�YqXqW||fS)Nrkz{0}.{1})rZpackagesrnr�r-�modules�KeyError�	importlib�
import_module�ImportErrorr�rMr`r��AttributeError)r6r�r�Zparent_topic�packageZmodule_name�moduler&r&r'�
_get_topic�s$


zhelp._get_topiccCs,t|j|dt|�f�}||j|d<dS)Nr,)rA�_topicsr8)r6�
topic_name�mod_name�mclr&r&r'�_count_topic_mclszhelp._count_topic_mclcsi|_g|_�x�|jjD�]�}||jjj|j�k	r4q|jr<q|jdk	�r�|j|j�\}}|j	dd�d}|dkr�|j}||jkr�|j|dj
|�n|d|gg|j|<t|j|dt|j�f�}||j|d<n�|j|�}|j}||jk�r�||j|dk�r"|j|d|dj
|�n&|d|gg|j|d|<|j
||�t|j|d|dt|j�f�}||j|d|d<n8|dj	dd�dd||d|ggig|j|<|j
||�q|jj
|�qWt|j�dd�|jD�}tdd�|D��|_tt|�j�dS)	Nr�r,rrjcSsg|]
}|j�qSr&)r%)r9�cr&r&r'rh:sz%help._on_finalize.<locals>.<listcomp>css|]}t|�VqdS)N)r8)r9�sr&r&r'r;;sz$help._on_finalize.<locals>.<genexpr>)r�Z	_builtinsr�Command�
get_pluginr%�NO_CLIr�r�r�r�rAr8r�r>�_mtl�superr��_on_finalize)r6r�r�r�r�r�r��topics)�	__class__r&r'r�sH

zhelp._on_finalizecsP|dkrtj}|j|�}t|��|dkr:|jjj|�dS�dkrP|j|�dS�|jkrh|j	�|�n܈|j
kr�|j
�}|jr�t�d��|j
jj|�j|�n�t�fdd�|jj�D��r�|j	�|�nx�dk�r:d}xh|j
D]R}||j
j|j�k	r�q�|j�rq�t|t|j��}|jdjt|j�j|�|j��q�Wn
t�d��|j�dS)Nr�)r�c3s*|]"}t|d�tkr�|dkVqdS)rjN)r=rv)r9�t)r%r&r'r;Sszhelp.run.<locals>.<genexpr>�commandsrz{0}  {1})r-r.r�r*r�parserZ
print_help�print_topicsr��print_commandsr�r�r
�Backend�cli�build_parser�any�valuesr�r%rAr8r�rnr(�ljust�summaryr�)r6rer��options�writer�cmdr�Z
cmd_pluginr&)r%r'�run?s>







zhelp.runcCsT|j|�}x<t|jj��D]*\}}|jdjt|�j|j�|d��qW|j	�dS)Nz{0}  {1}r)
r�rwr��itemsr�rnr(r�r�r�)r6r�r�r�r�r&r&r'r�ds

zhelp.print_topicscCs�|j|�}||jkr�t|j|d�tkr�xV|j|dD]D}|j|d|d}|j|d}|jdjt|�j|�|��q:W�n4||jkr�|j|d}|j|d}nXg}xR|jj�D]D}t	|dt�s�q�||dkr�q�|d|d}|d|d}Pq�W|j
|�\}}	||jk�r8t|�dk�r8t
|d��|j|�|�r�|j�|jtd��x.|D]&}
|jdjt|
j�j|�|
j���qdW|j�|jtd��|jtd��|j�|j�dS)	Nrjrr,z
  {0}  {1})r�zTopic commands:zTo get command help, use:z  ipa <command> --help)r�r�r=rvr�rnr(r�r�r!r�r�r8r
rr%r�r�)r6r�r�r�Zsubtopicr�r�r�rIZ_topicr�r&r&r'r�lsF
 



zhelp.print_commands)NN)r�r�r�r�r�rr�
takes_argsrZ
takes_optionsr?�
has_outputr�r�r�r�r�r�r��
__classcell__r&r&)r�r'r��s 8
%r�c@s4eZdZdZeded�d�fZe�ZdZ	dd�Z
dS)�
show_mappingszA
    Show mapping of LDAP attributes to command-line option.
    �command_namezCommand name)r�NcKs�t|�}||jkrt|d��|j|j}d
dg}t|dd�}xB|�D]8}|jr^d|jkr^qH|j|j|jf�t	|t|j��}qHWx.|D]&}t
t|d�j|�d|d	�q�WdS)N)r%�	Parameter�LDAP attribute�	=========�==============rZwebuiz : r,)r�r�)r�r�)
r*r�rr�r8�excluder�r)Z
param_specrArWr(r�)r6r�r��params�outr��param�itemr&r&r'r��s


zshow_mappings.run)r�r�r�r�rrr�r?r�r�r�r&r&r&r'r��sr�cseZdZ�fdd�Z�ZS)�IPACompletercs$t|tjtjf�r|St�j||�S)N)r!r
�APINameSpaceZAPIr��_callable_postfix)r6r�Zword)r�r&r'r�szIPACompleter._callable_postfix)r�r�r�rr�r&r&)r�r'r��sr�c@s0eZdZdZdZe�ZdZdd�Zd	dd�Z	dS)
�consolez�Start the IPA interactive Python console, or run a script.

    An IPA API object is initialized and made available
    in the `api` global variable.
    �	filename?Ncsjtjd�tjt|�j�tjjtj	j
d��ytj��Wntk
rNYnX�fdd�}t
j|�dS)Nz
tab: completezconsole.historycs`tjj��}tjj|�s"tj|�tjd�ytj��Wn tk
rZt	j
d��YnXdS)N�2zUnable to store history %s)�os�path�dirname�isdir�makedirsr�Zset_history_length�write_history_file�OSError�logger�	exception)Z	directory)�historyr&r'�save_history�s

z3console._setup_tab_completion.<locals>.save_history)r��parse_and_bindZ
set_completerr�Zcompleterrrlrr�Zdot_ipa�read_history_filer
�atexit�register)r6�localrr&)r
r'�_setup_tab_completion�s

zconsole._setup_tab_completioncKs�t|jtjtd�}|r�y t|��}|j�}WdQRXWn8tk
rn}ztjd|j	|j
f�WYdd}~XnXy$t||dtj
d�}t|t�|�Wq�tk
r�tj�tjd�Yq�Xn&tdk	r�|j|�tjdjd�|d
�dS)N)rZpp�__builtins__z%s: %s�exec)r}r,r��'(Custom IPA interactive Python console)�    api: IPA API object�    pp: pretty printer)r)rrr)rvr�pprint�builtins�open�readr5r-�exit�filename�strerror�compilerZ
compiler_flagr�globalsr��	traceback�	print_excr�r�codeZinteractrl)r6rr�r�f�sourcer�Zcompiledr&r&r'r��s8
(

zconsole.run)r)N)
r�r�r�r�r�r?r�r�rr�r&r&r&r'r�src@s4eZdZdZdZdZddd�Zdd�Zd
d	d
�ZdS)�show_apiz%Show attributes on dynamic API object�namespaces*Nc	Cs�|dkrt|j�}n&x |D]}||jkrt|d��qW|}|j|�}tdd�|D��}|jjjd�d}xV|D]N}|ddkr�|r�td�|r�d}td	d
|d|dj	|�|df�qnWt
|�dkr�d
}ndt
|�}|jjj|�dS)N)r%css|]}t|d�VqdS)r,N)r8)r9rpr&r&r'r;szshow_api.run.<locals>.<genexpr>r�TrrkFz%s%s %rrir,rjz1 attribute shown.z%d attributes show.)r?rr�_show_api__traverserAr�r+r�rWr�r8r�)	r6Z
namespaces�namesr%�linesZmlrrar�r&r&r'r�s.




zshow_api.runcCs2g}x(|D] }|j|}|jd|||�q
W|S)Nz%s)r�_show_api__traverse_namespace)r6r+r,r%�	namespacer&r&r'Z
__traverse*s


zshow_api.__traverserc	Cs�|j|||f�xv|D]n}||}|j|d||f�t|d�sBqx@|D]8}||}t|tj�rHt|�dkrH|j||||d�qHWqWdS)Nr,�__iter__rrj)r��hasattrr!r
r�r8r-)	r6r%r.r,Ztab�member_name�memberrOrmr&r&r'Z__traverse_namespace1s


zshow_api.__traverse_namespace)r))N)r)	r�r�r�r�r�r�r�r*r-r&r&r&r'r(s
r(c@s$eZdZdd�Zdd�Zdd�ZdS)�	CollectorcCstj|di�dS)N�_Collector__options)�object�__setattr__)r6r&r&r'r�FszCollector.__init__cCsP||jkr4|j|}t|�tkr,||f}n||f}||j|<tj|||�dS)N)r4r=r?r5r6)r6r%rLrIr&r&r'r6Is


zCollector.__setattr__cCs
t|j�S)N)rvr4)r6r&r&r'�
__todict__UszCollector.__todict__N)r�r�r�r�r6r7r&r&r&r'r3Esr3c@seZdZdd�ZdS)�CLIOptionParserFormattercs�g}�j�jd}t|�|kr8d�jd|f}�j}nd�jd||f}d}|j|�|r�tj|�j�}|jd|d|df�|j�fdd�|dd�D��n|d
d	kr�|jd	�dj|�S)Nrjz%*s%s
rkz	%*s%-*s  rcsg|]}d�jd|f�qS)z%*s%s
rk)�
help_position)r9ra)r6r&r'rhfsz<CLIOptionParserFormatter.format_argument.<locals>.<listcomp>r,r�r�)	r9Zcurrent_indentr8r�r^r_Z
help_width�extendrl)r6r%�help_string�resultZ	opt_widthZindent_firstZ
help_linesr&)r6r'�format_argumentYs 

z(CLIOptionParserFormatter.format_argumentN)r�r�r�r=r&r&r&r'r8Xsr8c@s*eZdZdZdd�Zd	dd�Zdd�ZdS)
�CLIOptionParserz�
    This OptionParser subclass adds an ability to print positional
    arguments in CLI help. Custom formatter is used to format the argument
    list in the same way as OptionParser formats options.
    cOs0g|_d|krt�|d<tjj|f|�|�dS)N�	formatter)�
_argumentsr8�optparse�OptionParserr�)r6�args�kwargsr&r&r'r�rs
zCLIOptionParser.__init__NcCs�tjj||�}t|t�r�ttd��}|j|�g}|j�x$|j	D]\}}|j
|j||��q@W|j�t
|�dkr~|j
d�ng}dj|�|}|S)zN
        Prepend argument help to standard OptionParser's option help
        zPositional argumentsr,r�rk)rArB�format_option_helpr!r8rMrZformat_headingrcr@r�r=�dedentr8rl)r6r?Zoption_helpZheadingZ	argumentsr%r;r&r&r'rExs
z"CLIOptionParser.format_option_helpcCs|jj||f�dS)N)r@r�)r6r%r;r&r&r'�add_argument�szCLIOptionParser.add_argument)N)r�r�r�r�r�rErGr&r&r&r'r>ls
r>c@sbeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	ddd�Z
dd�Zdd�Zdd�Z
dS)r�zC
    Backend plugin for executing from command line interface.
    cCs�t|�dkr@|jjtjd�ttjd�tdtjd�tjd�|d|dd�}}t|�}||jkr�t|�dkr�y|jjt|�tjd�Wnt	k
r�YnX||jks�|j|j
r�t|d��|j|}|S)	z�Given CLI arguments, return the Command to use

        On incorrect invocation, prints out a help message and returns None
        r)r�)r�zError: Command not specifiedrjr,N)r%)r8r�r�r-�stderrrWrr*rMr
r�r)r6�argvrer%r�r&r&r'�get_command�s 


zcli.get_commandcCs`|jjrP|j||�y|jd�}Wntk
r6YnXx|D]}|||�q>W|j||�|S)z'Get the keyword arguments for a CommandZinteractive_prompt)r�r��prompt_interactivelyZ
get_callbacksr��
load_files)r6r��kwZ	callbacks�callbackr&r&r'�process_keyword_arguments�s
zcli.process_keyword_argumentsc

Cs�|j|�}|dkrdS|j}|j||dd��}t|tj�sD|j�z�|j||�}|j|f|�}t	|j
�r�x(|j�D]}|jrt|j
|krt||j
=qtW|jf|�\}}|j
|jjj|f|�|�}	|	r�|	SdSWd|j�XdS)Nr,r)rJZ	full_name�parser!r�LocalZcreate_contextrOZexecute�callableZoutput_for_clir��passwordr%Zparams_2_args_optionsrr�r+Zdestroy_context)
r6rIr�r%rMr<r�rCr��rvr&r&r'r��s*


zcli.runcCs@|j|�}|j|t��\}}|j�}|j||�}t|j||��S)N)r��
parse_argsr3r7Zargs_options_2_paramsrv�
parse_iter)r6r�rIr�Z	collectorrCr�rMr&r&r'rP�s

z	cli.parseccs.x(|j�D]\}}||jjj|�fVq
WdS)z5
        Decode param values if appropriate.
        N)r�r�r+rH)r6r�rMrerLr&r&r'rV�szcli.parse_itercs�tdj|j|��t|j�t�d��i���fdd�}�xH|j�D�]:}t|jt|j�d�}d|j	krfq@|j
r~|jjr~d|d<n2t
|t�r�|jd	kr�d
|d<q�d|d<n
|j|d<t|j�}d|g}|jr�|jd
|j�tj||�}|jdkr��j|�n||j�j|�|jr@t|�}td�||d<t
|t��r>d|d<|ttd���}	x,|jD]"}
d|
}|	jtj|f|���qVWq@WxP|j�D]D}|j|dd�}d|j	k�s�|dk�r��q�t|j�}
�j||
��q�W�S)Nri)Zusage�descriptionr?cs4�j|�}|dkr0tj�|�}�j|�|�|<|S)z0Get or create an option group for the given nameN)r�rAZOptionGroupZadd_option_group)Z
group_name�option_group)�
option_groupsr�r&r'�_get_option_group�s

z+cli.build_parser.<locals>._get_option_group)�destr�r��
store_true�actionTZstore_false�metavarz--%sz-%szSame as --%sr�ZVALzDeprecated optionsF)�format_name)r>rl�
usage_iterrMr��IPAHelpFormatterr�rvr%r}rSr�r�r!rr�Zcli_metavarr(r)Zcli_short_namer�rAZmake_optionrXZ
add_optionZdeprecated_cli_aliasesrrrC�_cli__get_arg_namerG)r6r�rZZoptionrMr)Zoption_names�optZnew_kw�group�aliasr%�argr�r&)rYr�r'r��sV
	










zcli.build_parserTcCsD|jr
dSt|j�j�}|s |S|jr.d|}|jr8|Sd|SdS)Nz%s...z[%s])rSr(r)�upperZ
multivalue�required)r6rfr_r%r&r&r'Z__get_arg_name"szcli.__get_arg_nameccsFdt|j�Vx*|j�D]}|j|�}|dkr2q|VqWdVdS)Nz!Usage: %%prog [global-options] %sz	[options])r(r%rCrb)r6r�rfr%r&r&r'r`0s

zcli.usage_itercCsHd}x&|j�D]}|jr|j|krd}PqW�x|j�D�]}|jrN|j|ksb|jrX|sb|jj�r|jr~|j|jf|�||j<|j|kr�||jdk	r�|jr8||j=q8|jr�|j	j
j|j|j
�||j<nD|j|jf|�}|jp�|j}|j||||d�}|dk	�r@|||j<q8|jr8|j|jd�dkr8|j	j
j|j|j
�||j<q8WdS)a]
        Interactively prompt for missing or invalid values.

        By default this method will only prompt for *required* Param that
        have a missing or invalid value.  However, if
        ``self.env.prompt_all`` is ``True``, this method will prompt for any
        params that have a missing values, even if the param is optional.
        TFN)r�r�rM)r�Z	alwaysaskr%rhr�Z
prompt_allZautofillZget_default_ofrSr�r+r�r�r�Zprompt_paramr�)r6r�rMZhonor_alwaysaskr�r�r�rLr&r&r'rK9s8

zcli.prompt_interactivelycCs��x�|j�D�]|}t|ttf�rd}|j|kr�t||j�ttfkrT||jd}n
||j}y$t||j	��}|j
�}WdQRXWnBtk
r�}z&tt
|j�d||jdfd��WYdd}~XnXnr|j�r:y,tjr�|jtkr�tjjj
�}n
tjj
�}Wn<tk
�r8}ztt
|j�|jdd��WYdd}~XnX|�rn|jtk�rX|||j<n|jjj|�||j<q|jrtt
|j�td�d��qWdS)a�
        Load files from File parameters.

        This has to be done after all required parameters have been read
        (i.e. after prompt_interactively has or would have been called)
        AND before they are passed to the command. This is because:
        1) we need to be sure no more files are going to be added
        2) we load files from the machine where the command was executed
        3) the webUI will use a different way of loading files
        Nrz%s: %s:r,)r%r�zNo file to read)r�r!rrr%r=r?r>rZ	open_moderr5rr(r)rCZstdin_if_missingr��PY3rJr-rEr�r�r+rHrhr)r6r�rM�p�rawZfnamer&r�r&r&r'rLgs:

*(zcli.load_filesN)T)r�r�r�r�rJrOr�rPrVr�rbr`rKrLr&r&r&r'r��s	@
	.r�c@seZdZdZdd�ZdS)raa1Formatter suitable for printing IPA command help

    The default help formatter reflows text to fit the terminal, but it
    ignores line/paragraph breaks.
    IPA's descriptions already have correct line breaks. This formatter
    doesn't touch them (save for removing initial/trailing whitespace).
    cCs|r|j�SdSdS)Nrk)r`)r6rWr&r&r'�format_description�sz#IPAHelpFormatter.format_descriptionN)r�r�r�r�rlr&r&r&r'ra�sracCsbd}y�|jdd�\}}yt|jd�Wn,tk
rR}ztj|�WYdd}~XnXxtD]}|j|�qZW|j�d|jkr�d|kr�t	��tj|j
jj|��Wn�t
k
r�td�tjd�Yndtk
r�}z
|}WYdd}~Xn@tk
�r*}z"tjd|jjt|��t�}WYdd}~XnX|dk	�r^t|t��sFt�tj|j�tj|j�dS)	Nr�)�context)r�Z
config_loadedr�rkzoperation abortedz%s: %s)Zbootstrap_with_global_optionsrr�rr-r�cli_pluginsZ
add_plugin�finalizerr�r�r�r�rWr�inforr�rr�r�r"rr!r#r�r Zrval)rr�Z_optionsrIr��klassr&r&r'r��s2

r�)^r�Z
__future__rrrr�Zloggingr^r-r�r%rArrr0r1r2rTr#r��rlcompleterr�r�Z	six.movesrZipalib.utilrrrrrir"rMr��reloadZsetdefaultencodingZipalibrr	r
Z
ipalib.errorsrrr
rrrrrrZipalib.constantsrrZipalib.parametersrrrrrrZipalib.textrrZipapython.dnsutilrZipapython.admintoolrrUZ	getLoggerr�rr(r*r�r+rQr�r�r�Z	Completerr�rr(Zcli_application_commandsr3ZIndentedHelpFormatterr8rBr>ZExecutionerr�rarnr�r&r&r&r'�<module>s�
, 
	`^G8$