HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/ipalib/__pycache__/cli.cpython-39.pyc
a

�N(i���@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZzddlZddlZWney�dZZYn0ddlZddlmZddlmZmZmZmZejr�eZej �re!e�e�"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.m/Z/m0Z0ddl1m2Z2m3Z3ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:dd
l;m<Z<ddl#m=Z=ddl>m?Z?ddl@mAZAddlBmCZCmDZDmEZEmFZFddlGZGe�HeI�ZJdd�ZKdd�ZLGdd�de%jM�ZNGdd�de$jO�ZPGdd�de$jQ�ZRGdd�dejS�ZTGdd�de
jU�ZUGd d!�d!e$jQ�ZVGd"d#�d#e$jQ�ZWePeVeWfZXGd$d%�d%�ZYGd&d'�d'eD�ZZGd(d)�d)eC�Z[Gd*d+�d+e%j\�Z]Gd,d-�d-eD�Z^e]eNeVePeRfZ_d.d/�Z`dS)0z+
Functionality for Command Line Interface.
�)�print_functionN)�input)�check_client_configuration�	get_pager�get_terminal_height�
open_in_pager�utf-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)�ScriptError)�IPAOptionParser�IPAFormatter�OptionGroup�make_optioncCst|t�sJ�|�dd�S)zl
    Takes a Python identifier and transforms it into form suitable for the
    Command Line Interface.
    r�-)�
isinstance�str�replace��name�r+�./usr/lib/python3.9/site-packages/ipalib/cli.py�to_cliQsr-cCst|��dd�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_cliZsr/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.
    cCsTtj��rPz2t�tjtjt�ddddd��}t�	d|�dWSt
yNYn0dS)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_widthgs
�ztextui.get_tty_widthNcsbt|�ttfvr"tdtt|f��t|�dkr2dS�durLtdd�|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>��z'textui.max_col_width.<locals>.<genexpr>c3s|]}t|��VqdSr=r>r@��colr+r,rC�rD)�type�list�tuple�	TypeErrorr?�max)r;�rowsrFr+rEr,�
max_col_widthxs�ztextui.max_col_widthcCs.|tjtjfvsJ�t|dd�dur(dS|jS)N�encodingzUTF-8)r2�stdinr3�getattrrN)r;�streamr+r+r,Z__get_encoding�sztextui.__get_encodingcsLt|�tur"��tj�}|�|�St|�ttfvrHt�fdd�|D��S|S)z1
            Decode text from stdin.
            c3s|]}��|�VqdSr=)�decode�rA�v�r;r+r,rC�rDz textui.decode.<locals>.<genexpr>)rG�bytes�_textui__get_encodingr2rOrRrHrI)r;�valuerNr+rUr,rR�s
z
textui.decodecCs&t|�tusJ�|�tj�}|�|�S)z;
            Encode text for output to stdout.
            )rG�unicoderWr2r3�encode)r;Zunicode_textrNr+r+r,rZ�sz
textui.encodecCs|Sr=r+�r;rXr+r+r,rR�scCs|Sr=r+r[r+r+r,rZ�scCs |dks|dur||S||S�Nr1r+)r;�n�singular�pluralr+r+r,�
choose_number�sztextui.choose_numbercCsNt|�turt�|��d�St|�tjur4|�t�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)rGrV�base64Z	b64encoderR�datetime�strftimerr&rrYr[r+r+r,�
encode_binary�s

ztextui.encode_binarycCstt|��dS)z?
        Print exactly like ``print`` statement would.
        N��printrY�r;�stringr+r+r,�print_plain�sztextui.print_plaincCsH|dur|��}|dur8|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...)r<r?rgrY)r;�text�widthr+r+r,�
print_line�s
ztextui.print_linecCs2|dur|��}t�|��|�D]}t|�q dS)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)r<�textwrap�wrap�striprg)r;rlrm�liner+r+r,�print_paragraph�sztextui.print_paragraphr1cCstt||�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)rgr)r;rl�indentr+r+r,�print_indentedsztextui.print_indentedcCs,|D]"\}}|�d||�|�f|�qdS)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)rure)r;rLrt�keyrXr+r+r,�print_keyvalsztextui.print_keyval�%s: %sTcs�t|t�sJ�t|ttf�s:��||��|�f|��n`|rf|D]}��||��|�f|�qB�n4�fdd�|D�}t|�dkr�t|d�ttfvr�|D](}d�|�}��||��|�f|�q�dSt|�dkr�d�dd�|D��}ndS��	�}	|	�rR|�rRd	t
|d
t|�df}
|	t|
�8}	tj||	dd
�}t|�dk�r\dg}n
d}
|g}��|||df|�|dd�D]}��
d	|
|f��q�dS)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|]}��|��qSr+)rerSrUr+r,�
<listcomp>CrDz*textui.print_attribute.<locals>.<listcomp>rz: Nz, css|]}t|�VqdSr=)r'rSr+r+r,rCLrDz)textui.print_attribute.<locals>.<genexpr>z%s%s� �F)Zbreak_long_words�r1)r&r'rHrIrurer?rG�joinr<rrorprj)r;�attrrX�formatrt�one_value_per_linerT�lrl�line_lenZs_indentrrr+rUr,�print_attribute(s>  
��ztextui.print_attributeZdncs~t�t�sJ�t�t�sJ�t|ttf�s.J�������fdd�}|D]���vrH|����=qHt��D]�|��qldS)z+
        Print an ldap entry dict.
        cs>��vr$�j������d�n�j�����d�dS)N)rtr�)r�)�a�r~�attr_map�entryrtr�r;r+r,�
print_attrjs��z'textui.print_entry1.<locals>.print_attrN)r&�dictrHrI�sorted)r;r�rtr�Z
attr_orderr�r�r+r�r,�print_entry1as
ztextui.print_entry1c

CsJt|ttf�sJ�d}|D]*}	|s*td�d}|�|	||||||�qdS)NTr|F)r&rHrIrg�print_entry)
r;�entries�order�labels�flags�	print_allrrt�firstr�r+r+r,�
print_entries{sztextui.print_entriesc
Cs�t|ttf�rt|�}t|t�s$J�|dur8t�}d}nd}|du�rJ|D]�}	|	|vrXqJ|�|	|	�}
|�|	g�}||	}d|vr�|dddgdfvr�qJt|t�r�t�|�dkr�qJ|�||
df|�|j|||||||dd�nbt|ttf��r0t	d	d
�|D���r0|�
|
d||�|�|||||||d�n|�
|
||||�||	=qJ|�r�t|�D](}	|�|	|	�}
|�
|	||	|||��qXdS)NTFZsuppress_emptyr|r+rr1)rtcss|]}t|t�VqdSr=)r&r�)rA�valr+r+r,rC�rDz%textui.print_entry.<locals>.<genexpr>)
r&rHrIr��getr	Zentry_countrur��allr�r�r�)
r;r�r�r�r�r�rrtr�rv�label�flagrXr+r+r,r��sV
�
���
��ztextui.print_entryrr%cCsZt|t�sJ�t|�dksJ�|t|�}|r:|�||�|�||�|rV|�||�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.
        r1N)r&r'r?ru)r;riZaboveZbelowrt�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�=�rtr�N�r��r;rlr+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
          ------------------
        r1r%r�Nr�r�r+r+r,�print_h2�sztextui.print_h2cCs|�dt|��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-)r;r*r+r+r,�
print_name�sztextui.print_namecCs|�||�dSr=r�)r;�msg�outputr+r+r,�print_header�sztextui.print_headercCs|�|�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"
        -----------------
        Nr�)r;r�r+r+r,�
print_summary�sztextui.print_summarycCsBt|�tur*t|�tttfvs"J�t|�}|�|�|||��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)rG�intrHrIr�r?r�r`)r;�countr^r_r+r+r,�print_count
s�ztextui.print_countcCstdt|��dS)Nz
  ** %s **rfr�r+r+r,�print_error)sztextui.print_errorc	CsBz|�||�|���WSttfy<t�t|d��Yn0dS)z�Prompt user for input

        Handles encoding the prompt and decoding the input.
        On end of stream or ctrl+c, raise PromptFailed.
        r)N)rRrZ�KeyboardInterrupt�EOFErrorrgr)r;�promptr��prompt_funcr+r+r,�
prompt_helper,s
ztextui.prompt_helpercCs|�d||f�dS)Nz
>>> %s: %s)rj)r;Z	attribute�errorr+r+r,�print_prompt_attribute_error8sz#textui.print_prompt_attribute_errorFcCs@|rd|}nd|}|dur(d|}nd||f}|�||�S)z(
        Prompt user for input.
        �[%s]�%sN�%s: z	%s [%s]: )r�)r;r��defaultZ
get_values�optionalr�r+r+r,r�;s

z
textui.promptcCsvd}|dur|rd}nd}|r,d||f}nd|}|�||���}|dvrPdS|dvr\d	S|dur4|d
kr4|Sq4|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: )Zyes�yT)r]�noFr|)r��lower)r;r�r�Zdefault_promptr��datar+r+r,�prompt_yesnoJs ztextui.prompt_yesnocCs�tj��rvdt|�}ttd�t|d��}|j||tjd�}|sF|S|j||tjd�}||krd|S|�td��q,n|�	tj�
����SdS)zx
        Prompt user for a password or read it in via stdin depending
        on whether there is a tty or not.
        r�z!Enter %(label)s again to verify: �r�)r�zPasswords do not match!N)r2rOr4rYrr�r��getpassr�rR�readlinerq)r;r��confirmr�Z
repeat_promptZpw1Zpw2r+r+r,�prompt_passwordps
ztextui.prompt_passwordcCs>|jjrtj��sdSt|�}|dkr4ttd�d��d}|D]@}i}|D]}	|�|	d�||	<qH|�	d|||f�|d}q<|r�|�
|dd	�z|�d
|�}
Wnty�YdS0|
�
�dkr�dS|
�
�d
kr�dSz2t|
�d}||k�r�dk�rnnW�q0Wnt�yYn0|�	d|�q�|�	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
        ���rzNo matching entries found)�reasonr1r|z%d: %szFound %d matchzFound %d matchesz*Choose one: (1 - %s), a for all, q to quit����qr�z&Please enter a number between 1 and %s)�env�interactiver2r3r4r?rrr�rnr�r�r�r�r��	Exception)r;r�r�attrsZ
display_countZcounter�i�e�dr�ZrespZ	selectionr+r+r,�select_entry�s>


ztextui.select_entry)N)N)N)N)r1)r1)rxr1T)NNNTrxr1)NNNTrxr1)TTrr%)N)NNF)N)T)T)%�__name__�
__module__�__qualname__�__doc__r<rMrW�six�PY2rRrZr`rerjrnrsrurwr�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�r+r+r+r,r0bsH







9�

	
.



&
r0cs�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|_dSr=)�outfile�buffer)r;r�r+r+r,�__init__�szhelp.Writer.__init__cCs&d}|jD]}|t|�d��7}q
|S)Nr�
)r�r?�split)r;�lengthrrr+r+r,�
buffer_length�s
zhelp.Writer.buffer_lengthr|cCs|j�t|��dSr=)r��appendrYrhr+r+r,r��szhelp.Writer.appendcCsjt�}|r4|jt�kr4d�|j��d�}t||�n2z|jD]}t||jd�q<Wnt	ydYn0dS)Nr�r��file)
rr�rr}r�rZrrgr�r:)r;Zpagerr�rrr+r+r,�write�s
zhelp.Writer.writeN)r|)	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�NcCs�d}d}|jjD]�}d�|j|�}ztj|}Wn:tyjzt�|�}Wnt	ydYYqYn0Yn0|j
dur�t|j
p�d���}z
|j
}Wqty�Yq0q||fS)Nr|z{0}.{1})rZpackagesrr�r2�modules�KeyError�	importlib�
import_module�ImportErrorr�rYrqr��AttributeError)r;r�r�Zparent_topic�packageZmodule_name�moduler+r+r,�
_get_topic�s$

zhelp._get_topiccCs,t|j|dt|�f�}||j|d<dSr\)rK�_topicsr?)r;�
topic_name�mod_name�mclr+r+r,�_count_topic_mclszhelp._count_topic_mclcsi|_g|_|jjD�]�}||jj�|j�ur0q|jr8q|jdu�r�|�|j�\}}|�	dd�d}|dur�|j}||jvr�|j|d�
|�n|d|gg|j|<t|j|dt|j�f�}||j|d<n�|�|�}|j}||jv�r�||j|dv�r|j|d|d�
|�n&|d|gg|j|d|<|�
||�t|j|d|dt|j�f�}||j|d|d<n8|d�	dd�dd||d|ggig|j|<|�
||�q|j�
|�qt|j�dd�|jD�}tdd�|D��|_tt|���dS)	Nr�r1rr{cSsg|]
}|j�qSr+r))rA�cr+r+r,ry;rDz%help._on_finalize.<locals>.<listcomp>css|]}t|�VqdSr=r>)rA�sr+r+r,rC<rDz$help._on_finalize.<locals>.<genexpr>)r�Z	_builtinsr�Command�
get_pluginr*�NO_CLIr�r�r�r�rKr?r�rH�_mtl�superr��_on_finalize)r;r�r�r�r�r�r��topics��	__class__r+r,r�sN

���
zhelp._on_finalizecsL|durtj}|�|�}t|��|dur:|jj�|�dS�dkrP|�|�dS�|jvrh|�	�|�n؈|j
vr�|j
�}|jr�t�d��|j
j�|��|�n�t�fdd�|j��D��r�|�	�|�nt�dk�r6d}|j
D]R}||j
�|j�ur�q�|j�rq�t|t|j��}|�d�t|j��|�|j��q�n
t�d��|��dS)Nr��r�c3s*|]"}t|d�tur�|dvVqdS)r{N)rGr�)rA�tr)r+r,rCTs�zhelp.run.<locals>.<genexpr>�commandsr�{0}  {1})r2r3r�r/r�parser�
print_help�print_topicsr��print_commandsr�r�r�Backend�cli�build_parser�any�valuesr�r*rKr?r�rr-�ljust�summaryr�)r;rvr��options�writer�cmdr�Z
cmd_pluginr+r)r,�run@s@







�

zhelp.runcCsP|�|�}t|j���D]*\}}|�d�t|��|j�|d��q|�	�dS)Nrr)
r�r�r��itemsr�rr-r
r�r�)r;r�r
r�r�r+r+r,res
�zhelp.print_topicscCs�|�|�}||jvr�t|j|d�tur�|j|dD]D}|j|d|d}|j|d}|�d�t|��|�|��q8�n0||jvr�|j|d}|j|d}nXg}|j��D]H}t	|dt�s�q�||dvr�q�|d|d}|d|d}�qq�|�
|�\}}	||jv�r4t|�dk�r4t
|d��|�|�|�r�|��|�td��|D]&}
|�d�t|
j��|�|
j���q^|��|�td��|�td��|��|��dS)	Nr{rr1z
  {0}  {1}r�zTopic commands:zTo get command help, use:z  ipa <command> --help)r�r�rGr�r�rr-r
r	r&r�r�r?rrr*rr�)r;r�r�r
Zsubtopicr�r�r�rTZ_topicr�r+r+r,rmsL
 �


��zhelp.print_commands)NN)r�r�r�r�r�rr�
takes_argsrZ
takes_optionsrI�
has_outputr�r�r�r�rrr�
__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 namer�NcKs�t|�}||jvrt|d��|j|j}ddg}t|dd�}|�D]8}|jr\d|jvr\qF|�|j|jf�t	|t|j��}qF|D]&}t
t|d��|�d|d�q�dS)Nr))Z	ParameterzLDAP attribute)z	=========z==============rZwebuiz : r1)
r/r�r
rr?Zexcluder�r.Z
param_specrKrgr-r
)r;rr�params�outr��param�itemr+r+r,r�s

�
zshow_mappings.run)r�r�r�r�rrrrIrr�rr+r+r+r,r�s��rcseZdZ�fdd�Z�ZS)�IPACompletercs$t|tjtjf�r|St��||�Sr=)r&r�APINameSpaceZAPIr��_callable_postfix)r;r�Zwordr�r+r,r�szIPACompleter._callable_postfix)r�r�r�rrr+r+r�r,r�srcseZdZ�fdd�Z�ZS)�InteractiveConsolecsDt��}|d}t|t�r6|�d|jjt|�f�n
t��	�dS)Nr1z#IPA public error exception: %s: %s
)
r2�exc_infor&rr�r�r�r'r��
showtraceback)r;Zeir�r�r+r,r�s
�z InteractiveConsole.showtraceback)r�r�r�rrr+r+r�r,r�src@s0eZdZdZdZe�ZdZdd�Zddd�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.
    )z	filename?Ncsht�d�t�t|�j�tj�tj	j
d��zt���WntyLYn0�fdd�}t
�|�dS)Nz
tab: completezconsole.historycs^tj���}tj�|�s"t�|�t�d�zt���WntyXt	�
d��Yn0dS)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_completerrZcompleter"r#r}rr�Zdot_ipa�read_history_filer(�atexit�register)r;�localr-r+r+r,�_setup_tab_completion�s

zconsole._setup_tab_completionc	
Kst|jtjtd�}|r�z4t|��}|��}Wd�n1s>0YWn:ty�}z"t�d|j	|j
f�WYd}~n
d}~00z$t||dtj
d�}t|t�|�Wn$ty�t��t�d�Yn0n.tdur�|�|�t|�}|jd�d�dd�dS)	N)r�pp�__builtins__rx�execr�r1r�)z'(Custom IPA interactive Python console)z    api: IPA API objectz    pp: pretty printer)Zexitmsg)r�r�pprint�builtins�open�readr:r2�exit�filename�strerror�compilerZ
compiler_flagr6�globalsr��	traceback�	print_excr�r3rZinteractr})	r;r<rr2�f�sourcer�ZcompiledZconsr+r+r,r�s:�
*,�
�zconsole.run)N)
r�r�r�r�rrIrr�r3rr+r+r+r,r �sr c@s4eZdZdZdZdZddd�Zdd�Zdd	d
�ZdS)
�show_apiz%Show attributes on dynamic API object)znamespaces*Nc	Cs�|durt|j�}n"|D]}||jvrt|d��q|}|�|�}tdd�|D��}|jj�d�d}|D]L}|ddkr�|s�td�|r�d}td	d
|d|d�	|�|df�qht
|�dkr�d
}ndt
|�}|jj�|�dS)Nr)css|]}t|d�VqdS)r1Nr>)rAr�r+r+r,rC$rDzshow_api.run.<locals>.<genexpr>rTrr|Fz%s%s %rrzr1r{z1 attribute shown.z%d attributes show.)rIrr�_show_api__traverserKrr0r�rgr
r?r�)	r;Z
namespaces�namesr*�lines�mlr�rrr�r+r+r,rs0


�
zshow_api.runcCs.g}|D] }|j|}|�d|||�q|S)Nr�)r�_show_api__traverse_namespace)r;rFrGr*�	namespacer+r+r,Z
__traverse7s

zshow_api.__traverserc		Cs�|�|||f�|D]j}||}|�|d||f�t|d�s@q|D]8}||}t|tj�rDt|�dkrD|�||||d�qDqdS)Nr1�__iter__rr{)r��hasattrr&rrr?rI)	r;r*rJrGZtab�member_name�memberr]r~r+r+r,Z__traverse_namespace>s
zshow_api.__traverse_namespace)N)r)	r�r�r�r�rr�rrErIr+r+r+r,rDs
rDc@s$eZdZdd�Zdd�Zdd�ZdS)�	CollectorcCst�|di�dS)N�_Collector__options)�object�__setattr__rUr+r+r,r�SszCollector.__init__cCsP||jvr4|j|}t|�tur,||f}n||f}||j|<t�|||�dSr=)rPrGrIrQrR)r;r*rXrTr+r+r,rRVs


zCollector.__setattr__cCs
t|j�Sr=)r�rPrUr+r+r,�
__todict__bszCollector.__todict__N)r�r�r�r�rRrSr+r+r+r,rORsrOc@seZdZdd�ZdS)�CLIOptionParserFormattercs�g}�j�jd}t|�|kr8d�jd|f}�j}nd�jd||f}d}|�|�|r�t�|�j�}|�d|d|df�|��fdd�|dd�D��n|d	d
kr�|�d
�d�|�S)Nr{�%*s%s
r|z	%*s%-*s  rcsg|]}d�jd|f�qS)rUr|)�
help_position)rArrrUr+r,ryts�z<CLIOptionParserFormatter.format_argument.<locals>.<listcomp>r1r�r�)	rV�current_indentr?r�rorp�
help_width�extendr})r;r*�help_string�resultZ	opt_width�indent_first�
help_linesr+rUr,�format_argumentgs"

�

z(CLIOptionParserFormatter.format_argumentN)r�r�r�r^r+r+r+r,rTfsrTc@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.
    cOs4g|_d|vrt�|d<tj|g|�Ri|��dS)N�	formatter)�
_argumentsrTr!r�)r;�args�kwargsr+r+r,r��s
zCLIOptionParser.__init__NcCs�t�||�}t|t�r�ttd��}|�|�g}|��|jD]\}}|�	|�
||��q<|��t|�dkrx|�	d�ng}d�
|�|}|S)zN
        Prepend argument help to standard OptionParser's option help
        zPositional argumentsr1r�r|)r!�format_option_helpr&rTrYrZformat_headingrtrar�r^�dedentr?r})r;r`Zoption_help�headingZ	argumentsr*rZr+r+r,rd�s
z"CLIOptionParser.format_option_helpcCs|j�||f�dSr=)rar�)r;r*rZr+r+r,�add_argument�szCLIOptionParser.add_argument)N)r�r�r�r�r�rdrgr+r+r+r,r_{s
r_c@sbeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	ddd�Z
dd�Zdd�Zdd�Z
dS)rzC
    Backend plugin for executing from command line interface.
    cCs�t|�dkr@|jjtjd�ttjd�tdtjd�t�d�|d|dd�}}t|�}||jvr�t|�dkr�z|jjt|�tjd�Wnt	y�Yn0||jvs�|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 specifiedr{r1Nr))r?r�r�r2�stderrrgr;r/rYrr�r
)r;�argvrvr*rr+r+r,�get_command�s 


zcli.get_commandcCsZ|jjrJ|�||�z|�d�}Wnty4Yn0|D]}|||�q:|�||�|S)z'Get the keyword arguments for a CommandZinteractive_prompt)r�r��prompt_interactivelyZ
get_callbacksr��
load_files)r;r�kwZ	callbacks�callbackr+r+r,�process_keyword_arguments�szcli.process_keyword_argumentsc
Cs|�|�}|durdS|j}|�||dd��}t|tj�sD|��z�|�||�}|j|fi|��}t	|j
�r�|��D]}|jrv|j
|vrv||j
=qv|jfi|��\}}|j
|jjj|g|�Ri|��}	|	r�|	W|��SW|��dSW|��n
|��0dS)Nr1r)rjZ	full_name�parser&r	�LocalZcreate_contextroZexecute�callableZoutput_for_clir�passwordr*Zparams_2_args_optionsrrr0Zdestroy_context)
r;rirr*rmr[rrbr�rvr+r+r,r�s2


 ��zcli.runcCsD|�|�}|�|t��\}}|��}|j|i|��}t|�||��Sr=)r�
parse_argsrOrSZargs_options_2_paramsr��
parse_iter)r;rrirZ	collectorrbrrmr+r+r,rp�s

z	cli.parseccs*|��D]\}}||jj�|�fVqdS)z5
        Decode param values if appropriate.
        N)rrr0rR)r;rrmrvrXr+r+r,rv�szcli.parse_itercs�td�|�|��t|j�t�d��i���fdd�}|��D�]:}t|jt|j�d�}d|j	vrbq<|j
rz|jjrzd|d<n2t
|t�r�|jd	ur�d
|d<q�d|d<n
|j|d<t|j�}d|g}|jr�|�d
|j�t|i|��}|jdur���|�n||j��|�|jr<t|�}td�||d<t
|t��r<d|d<|ttd���}	|jD]$}
d|
}|	�t|fi|����qRq<|��D]D}|j|dd�}d|j	v�s�|du�r��q�t|j�}
��||
��q��S)Nrz)�usage�descriptionr`cs2��|�}|dur.t�|�}��|�|�|<|S)z0Get or create an option group for the given nameN)r�r#Zadd_option_group)Z
group_name�option_group�Z
option_groupsrr+r,�_get_option_group�s


z+cli.build_parser.<locals>._get_option_group)�destr�r��
store_true�actionT�store_false�metavarz--%sz-%szSame as --%sr�ZVALzDeprecated optionsF)�format_name)r_r}�
usage_iterrYr��IPAHelpFormatterrr�r*r�rsr�r�r&rr�Zcli_metavarr-r.Zcli_short_namer�r$ryZ
add_optionZdeprecated_cli_aliasesrrrb�_cli__get_arg_namerg)r;rr{�optionrmr.Zoption_names�optZnew_kw�group�aliasr*�argr�r+rzr,r�sZ�	�











zcli.build_parserTcCsD|jr
dSt|j���}|s |S|jr.d|}|jr8|Sd|SdS)Nz%s...r�)rsr-r.�upperZ
multivalue�required)r;r�r�r*r+r+r,Z__get_arg_name1szcli.__get_arg_nameccsBdt|j�V|��D]}|�|�}|dur0q|VqdVdS)Nz!Usage: %%prog [global-options] %sz	[options])r-r*rbr�)r;rr�r*r+r+r,r�?s
zcli.usage_itercCsHd}|��D]}|jr|j|vrd}q*q|��D�]}|jrH|j|vs\|jrR|s\|jj�r|jr||j|jfi|��||j<|j|vr�||jdur�|jr2||j=q2|jr�|j	j
�|j|j
�||j<nH|j|jfi|��}|jp�|j}|j||||d�}|du�rB|||j<q2|jr2|�|jd�dur2|j	j
�|j|j
�||j<q2dS)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)rZ	alwaysaskr*r�r�Z
prompt_allZautofillZget_default_ofrsrr0r�r�r�Zprompt_paramr�)r;rrmZhonor_alwaysaskrr�r�rXr+r+r,rkHsH
�����
�zcli.prompt_interactivelycCs�|��D�]�}t|ttf�rd}|j|vr�t||j�ttfvrP||jd}n
||j}z8t||j	��}|�
�}Wd�n1s�0YWnDty�}z,tt
|j�d||jdfd��WYd}~n
d}~00nx|j�rRz0tj�r|jtu�rtjj�
�}n
tj�
�}Wn>t�yP}z$tt
|j�|jdd��WYd}~n
d}~00|�r�|jtu�rp|||j<n|jj�|�||j<q|jrtt
|j�td�d��qdS)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:r1)r*r�zNo file to read)rr&rrr*rGrIrHr9Z	open_moder:r:rr-r.rbZstdin_if_missingr��PY3rVr2rOr�rr0rRr�r)r;rrm�p�raw�fnamerBr�r+r+r,rlvs@

*���zcli.load_filesN)T)r�r�r�r�rjrorrprvrr�r�rkrlr+r+r+r,r�s	@
	.rc@seZdZdZdd�ZdS)r�a1Formatter 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|��SdSdS)Nr|)rq)r;rxr+r+r,�format_description�sz#IPAHelpFormatter.format_descriptionN)r�r�r�r�r�r+r+r+r,r��sr�c
Csbd}z�|jdd�\}}zt|jd�Wn.tyT}zt�|�WYd}~n
d}~00tD]}|�|�qZ|��d|jvr�d|vr�t	��t�|j
j�|��Wn�t
y�td�t�d�Ynhty�}z|}WYd}~nJd}~0t�y*}z(t�d|jjt|��t�}WYd}~n
d}~00|du�r^t|t��sFJ�t�|j�t�|j�dS)	Nr)�context)r�Z
config_loadedr�r|zoperation abortedrx)Zbootstrap_with_global_optionsrr�r r2r;�cli_pluginsZ
add_plugin�finalizerrrrr�rgr)�inforr�r*r�r�r'rr&r�r=Zrval)rr�Z_optionsrir��klassr+r+r,r�s2 
r)ar�Z
__future__rr0r8r�Zloggingror2r��coder"r7r5r6r7rbr@r��rlcompleterr�r�Z	six.movesrZipalib.utilrrrrr�r'rYr��reloadZsetdefaultencodingZipalibr	r
rZ
ipalib.errorsrr
rrrrrrrZipalib.constantsrrZipalib.parametersrrrrrrZipalib.textrrZipapython.dnsutilrZipapython.admintoolr Zipapython.configr!r"r#r$rcZ	getLoggerr�r)r-r/rr0rqr�r�rZ	Completerrrr rDZcli_application_commandsrOrTr_ZExecutionerrr�r�rr+r+r+r,�<module>s�
, 
	`^H8�$�