%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/python/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/python/__pycache__/_shellcomp.cpython-312.pyc

�

Ϫ�f�b����dZddlZddlZddlZddlmZddlmZmZm	Z	ddl
mZmZm
Z
ddlmZd�ZGd�d	ej"�ZGd
�d�ZGd�d
e�ZGd�d�Zd�Zd�Zy)a�
No public APIs are provided by this module. Internal use only.

This module implements dynamic tab-completion for any command that uses
twisted.python.usage. Currently, only zsh is supported. Bash support may
be added in the future.

Maintainer: Eric P. Mangold - twisted AT teratorn DOT org

In order for zsh completion to take place the shell must be able to find an
appropriate "stub" file ("completion function") that invokes this code and
displays the results to the user.

The stub used for Twisted commands is in the file C{twisted-completion.zsh},
which is also included in the official Zsh distribution at
C{Completion/Unix/Command/_twisted}. Use this file as a basis for completion
functions for your own commands. You should only need to change the first line
to something like C{#compdef mycommand}.

The main public documentation exists in the L{twisted.python.usage.Options}
docstring, the L{twisted.python.usage.Completions} docstring, and the
Options howto.
�N)�
MethodType)�Dict�List�Set)�reflect�usage�util)�ioTypec��|rt|�tk(r|j}|djd�\}}t	|�}|dz}||}|dk\r$||dz
jd�r|dz}nn|dk\r�$|d|}t
|dd�}|r�d}	tj||j|j�\}	}|rT|jD]E\}
}}}
|d|
k(s	|d|k(s�|�}||_t||||�}|j�yd	}|jd�rd
}t|||�}|j|��yt|||�}|j�y#tj$rY��wxYw)ao
    Perform shell completion.

    A completion function (shell script) is generated for the requested
    shell and written to C{shellCompFile}, typically C{stdout}. The result
    is then eval'd by the shell to produce the desired completions.

    @type config: L{twisted.python.usage.Options}
    @param config: The L{twisted.python.usage.Options} instance to generate
        completions for.

    @type cmdName: C{str}
    @param cmdName: The name of the command we're generating completions for.
        In the case of zsh, this is used to print an appropriate
        "#compdef $CMD" line at the top of the output. This is
        not necessary for the functionality of the system, but it
        helps in debugging, since the output we produce is properly
        formed and may be saved in a file and used as a stand-alone
        completion function.

    @type words: C{list} of C{str}
    @param words: The raw command-line words passed to use by the shell
        stub function. argv[0] has already been stripped off.

    @type shellCompFile: C{file}
    @param shellCompFile: The file to write completion data to.
    ����:���-N�subCommandsrTF)�genSubs)r
�str�buffer�split�int�
startswith�getattr�getopt�shortOpt�longOpt�errorr�parent�ZshSubcommandBuilder�write�
ZshBuilder)�config�cmdName�words�
shellCompFile�	shellName�position�cWordr�args�opts�cmd�short�parser�doc�
subOptions�genrs                 �;/usr/lib/python3/dist-packages/twisted/python/_shellcomp.py�
shellCompleter1's���>��
�.�#�5�%�,�,�
� ��)�/�/�#�.��I�x��8�}�H�
��M�H��(�O�E��a�-���A���)�)�#�.���M�H��	�a�-�

�)�8��E��&�-��6�K����	����u�f�o�o�v�~�~�N�J�D�$��+1�+=�+=�	
�'��U�F�C���7�c�>�T�!�W��%5�!'��J�(.�J�%�&:�"�F�G�]�'�C��I�I�K��	
������C� ��G����-�8���	�	�'�	�"����-�8���	�	���7�|�|�	��	�s�
.E$�$E:�9E:c��eZdZd�Zy)�SubcommandActionc�F�|tjk(rytd|����)Nz*::subcmd:->subcmdzUnknown shellType )r�_ZSH�NotImplementedError)�self�optName�	shellTypes   r0�
_shellCodezSubcommandAction._shellCode�s$����
�
�"�'�!�$6�y�m�"D�E�E�N)�__name__�
__module__�__qualname__r:�r;r0r3r3�s��Fr;r3c��eZdZdZd�Zdd�Zy)r a�
    Constructs zsh code that will complete options for a given usage.Options
    instance, possibly including a list of subcommand names.

    Completions for options to subcommands won't be generated because this
    class will never be used if the user is completing options for a specific
    subcommand. (See L{ZshSubcommandBuilder} below)

    @type options: L{twisted.python.usage.Options}
    @ivar options: The L{twisted.python.usage.Options} instance defined for this
        command.

    @type cmdName: C{str}
    @ivar cmdName: The name of the command we're generating completions for.

    @type file: C{file}
    @ivar file: The C{file} to write the completion function to.  The C{file}
        must have L{bytes} I/O semantics.
    c�.�||_||_||_y�N)�optionsr"�file)r7rCr"rDs    r0�__init__zZshBuilder.__init__�s����������	r;c���|�r.t|jdd���t|j|j|j�}|j
j
dt��|j�|jjd�|jjD]L\}}}}|jjd|jd�zdz|jd�zdz��N|jjd	�|jjd
�yt|j|j|j�}|j�y)a�
        Generate the completion function and write it to the output file
        @return: L{None}

        @type genSubs: C{bool}
        @param genSubs: Flag indicating whether or not completions for the list
            of subcommand should be generated. Only has an effect
            if the C{subCommands} attribute has been defined on the
            L{twisted.python.usage.Options} instance.
        rNrs.local _zsh_subcmds_array
_zsh_subcmds_array=(
�"�utf-8�:s"
s)

s+_describe "sub-command" _zsh_subcmds_array
)rrC�ZshArgumentsGeneratorr"rD�extraActions�insertr3rr�encode)r7rr/r*r+r,�descs       r0rzZshBuilder.write�s���w�t�|�|�]�D�A�M�'����d�l�l�D�I�I�N�C����#�#�A�'7�'9�:��I�I�K��I�I�O�O�O�P�,0�L�L�,D�,D�
�(��U�F�D��	�	����3�:�:�g�.�.��5����G�8L�L�v�U��
�
�I�I�O�O�H�%��I�I�O�O�K�L�'����d�l�l�D�I�I�N�C��I�I�Kr;N)T�r<r=r>�__doc__rErr?r;r0r r �s���(�
r;r c��eZdZdZd�Zd�Zy)ra�
    Constructs zsh code that will complete options for a given usage.Options
    instance, and also for a single sub-command. This will only be used in
    the case where the user is completing options for a specific subcommand.

    @type subOptions: L{twisted.python.usage.Options}
    @ivar subOptions: The L{twisted.python.usage.Options} instance defined for
        the sub command.
    c�>�||_tj|g|���yrB)r.r rE)r7r.r(s   r0rEzZshSubcommandBuilder.__init__�s��$������D�(�4�(r;c�8�t|j|j|j�}|jjdt
��|j�t|j|j|j�}|j�y)zk
        Generate the completion function and write it to the output file
        @return: L{None}
        rN)	rJrCr"rDrKrLr3rr.)r7r/s  r0rzZshSubcommandBuilder.write�sd��
$�D�L�L�$�,�,��	�	�J��������#3�#5�6��	�	��#�D�O�O�T�\�\�4�9�9�M���	�	�r;NrOr?r;r0rr�s���)�
r;rc�~�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
dd	�Zd
ee
ee
ffd�Zd�Zd
�Zd�Zd�Zdd�Zy)rJa0	
    Generate a call to the zsh _arguments completion function
    based on data in a usage.Options instance

    The first three instance variables are populated based on constructor
    arguments. The remaining non-constructor variables are populated by this
    class with data gathered from the C{Options} instance passed in, and its
    base classes.

    @type options: L{twisted.python.usage.Options}
    @ivar options: The L{twisted.python.usage.Options} instance to generate for

    @type cmdName: C{str}
    @ivar cmdName: The name of the command we're generating completions for.

    @type file: C{file}
    @ivar file: The C{file} to write the completion function to.  The C{file}
        must have L{bytes} I/O semantics.

    @type descriptions: C{dict}
    @ivar descriptions: A dict mapping long option names to alternate
        descriptions. When this variable is defined, the descriptions
        contained here will override those descriptions provided in the
        optFlags and optParameters variables.

    @type multiUse: C{list}
    @ivar multiUse: An iterable containing those long option names which may
        appear on the command line more than once. By default, options will
        only be completed one time.

    @type mutuallyExclusive: C{list} of C{tuple}
    @ivar mutuallyExclusive: A sequence of sequences, with each sub-sequence
        containing those long option names that are mutually exclusive. That is,
        those options that cannot appear on the command line together.

    @type optActions: C{dict}
    @ivar optActions: A dict mapping long option names to shell "actions".
        These actions define what may be completed as the argument to the
        given option, and should be given as instances of
        L{twisted.python.usage.Completer}.

        Callables may instead be given for the values in this dict. The
        callable should accept no arguments, and return a C{Completer}
        instance used as the action.

    @type extraActions: C{list} of C{twisted.python.usage.Completer}
    @ivar extraActions: Extra arguments are those arguments typically
        appearing at the end of the command-line, which are not associated
        with any particular named option. That is, the arguments that are
        given to the parseArgs() method of your usage.Options subclass.
    c��||_||_||_i|_t	�|_g|_i|_g|_ttj|j��D]�}t|dd�}|s�|jj|j�|jj|j�|j
j|j
�|jj|j�|js��|j|_��t j"}g}g}||jd|�||jd|�t%|�D]-\}	}
t'|
�dk7s�t)j*d|
�||	<�/t%|�D]-\}	}
t'|
�dk7s�t)j*d|
�||	<�/||_||_i}|D]
}
|
dd||
d<�||_i}|D]
}
|
dd||
d<�||_i}
|
j|�|
j|�|
|_|j7�|j9�|j;�|_y)N�compData�optFlags�
optParameters��rr)rCr"rD�descriptions�set�multiUse�mutuallyExclusive�
optActionsrK�reversed�inspect�getmro�	__class__r�update�extendr�accumulateClassList�	enumerate�lenr	�padTorW�	optParams�paramNameToDefinition�flagNameToDefinition�allOptionsNameToDefinition�addAdditionalOptions�verifyZshNames�makeExcludesDict�excludes)r7rCr"rD�cls�data�aCLrWrj�i�optListrkrlrms              r0rEzZshArgumentsGenerator.__init__sc����������	�������
�!#����������G�N�N�7�+<�+<�=�>�
	:�C��3�
�D�1�D���!�!�(�(��):�):�;����&�&�t���7��
�
�$�$�T�]�]�3��&�&�-�-�d�.D�.D�E�
�$�$�(,�(9�(9�D�%�
	:��)�)��')��(*�	��G���z�8�4��G����	�:�#�H�-�	5�J�A�w��7�|�q� �"�j�j��G�4����	5�$�I�.�	6�J�A�w��7�|�q� �#�z�z�!�W�5�	�!��	6�!��
�"��� "�� �	<�G�07����!�'�!�*�-�	<�%:��"�!���	;�G�/6�q�r�{� ����,�	;�$8��!�%'�"�"�)�)�*?�@�"�)�)�*>�?�*D��'��!�!�#�	
�����-�-�/��
r;c��|j�|j�|j�|j�y)zf
        Write the zsh completion code to the file given to __init__
        @return: L{None}
        N)�writeHeader�writeExtras�writeOptions�writeFooter�r7s r0rzZshArgumentsGenerator.write\s4��
	
���������������r;c�x�|jjd|jjd�zdz�y)z^
        This is the start of the code that calls _arguments
        @return: L{None}
        s	#compdef rHs

_arguments -s -A "-*" \
N)rDrr"rMr|s r0rxz!ZshArgumentsGenerator.writeHeaderfs5��
	
�	�	����4�<�<�.�.�w�7�7�;*�
*�	
r;c��t|jj��}|j�|D]}|j	|��y)z]
        Write out zsh code for each option in this command
        @return: L{None}
        N)�listrm�keys�sort�writeOpt)r7�optNames�longnames   r0rzz"ZshArgumentsGenerator.writeOptionspsA��
��7�7�<�<�>�?���
�
�� �	$�H��M�M�(�#�	$r;c	�z�t|j�D]�\}}|jr&|t|j�dz
k7rt	d��|j
j
t|jdtj��jd��|j
j
d���y)a�
        Write out completion information for extra arguments appearing on the
        command-line. These are extra positional arguments not associated
        with a named option. That is, the stuff that gets passed to
        Options.parseArgs().

        @return: L{None}

        @raise ValueError: If C{Completer} with C{repeat=True} is found and
            is not the last item in the C{extraActions} list.
        rzDCompleter with repeat=True must be last item in Options.extraActions�rH� \
N)rgrK�_repeatrh�
ValueErrorrDr�escaper:rr5rM)r7ru�actions   r0ryz!ZshArgumentsGenerator.writeExtraszs���#�4�#4�#4�5�	&�I�A�v��~�~�!�s�4�+<�+<�'=��'A�"A� �8���
�I�I�O�O�F�6�#4�#4�R����#D�E�L�L�W�U�V��I�I�O�O�H�%�	&r;c�:�|jjd�y)zj
        Write the last bit of code that finishes the call to _arguments
        @return: L{None}
        s&& return 0
N)rDrr|s r0r{z!ZshArgumentsGenerator.writeFooter�s��
	
�	�	���(�)r;c����fd�}tj�j�j�j�D]}|�j
vs�||���jD] }|D]}|�j
vs�||���"y)z�
        Ensure that none of the option names given in the metadata are typoed
        @return: L{None}
        @raise ValueError: If unknown option names have been found.
        c�:��td|�d�j����)NzUnknown option name "z1" found while
examining Completions instances on )r�rC)�namer7s �r0�errz1ZshArgumentsGenerator.verifyZshNames.<locals>.err�s����;?����O��
r;N)�	itertools�chainr[r_r]rmr^)r7r�r��seqs`   r0roz$ZshArgumentsGenerator.verifyZshNames�s����	��O�O�D�$5�$5�t����
�
�V�	�D��4�:�:�:��D�	�	��)�)�	�C��
���t�>�>�>���I�
�	r;c���||jvr|j|j�}n
t�}||jvr:|dur%|j	|�}|�#|j|�n|j|�|syg}|D]9}t
|�dk(r|jd|z��&|jd|z��;|j�ddj|�zS)a�
        Generate an "exclusion string" for the given option

        @type longname: C{str}
        @param longname: The long option name (e.g. "verbose" instead of "v")

        @type buildShort: C{bool}
        @param buildShort: May be True to indicate we're building an excludes
            string for the short option that corresponds to the given long opt.

        @return: The generated C{str}
        Fr�rrz--z(%s)� )
rq�copyr\r]�getShortOption�addrh�appendr��join)r7r��
buildShort�
exclusionsr+�stringsr8s       r0�
excludeStrz ZshArgumentsGenerator.excludeStr�s����t�}�}�$����x�0�5�5�7�J���J�
�4�=�=�(��U�"��+�+�H�5���$��N�N�5�)����x�(�����!�	/�G��7�|�q� ����s�W�}�-����t�g�~�.�	/�	���������)�)�)r;�returnc��i}tj|j|j�D]}|ddk7s�|d||d<�i}|jD]{}t|�D]k\}}t
|d|||dzdz�}|j�D]}||vs�|j||��||vr||j|�||<�g|||<�m�}|S)z�
        @return: A C{dict} that maps each option name appearing in
            self.mutuallyExclusive to a set of those option names that is it
            mutually exclusive with (can't appear on the cmd line with).
        rNr)
r�r�rjrWr^rgr\r�r��union)	r7�longToShortrvrq�lstrur��tmpr�s	         r0rpz&ZshArgumentsGenerator.makeExcludesDict�s����� ���t�~�~�t�}�}�E�	5�G��q�z�T�!�*1�!�*��G�A�J�'�	5�)+���)�)�
	-�C�(��~�	
-���8��#�b�q�'�C��A���L�0�1���H�H�J�3�D��{�*�����D� 1�2�3��x�'�)1�(�);�)A�)A�#�)F�H�X�&�),�H�X�&�	
-�
	-��r;c	���||jvrd|z}nd|z}|j|�}|dk7rd|z}nd}|j|�}|jdd�}|jdd	�}d
|z}|j	|�}||j
vrd}nd}|j
|�}	|rk|j
|d�
�}
|jjt|
�|�|�|�|���jd��|jjd�|jjt|	�|�|�|�|���jd��|jjd�y)a
        Write out the zsh code for the given argument. This is just part of the
        one big call to _arguments

        @type longname: C{str}
        @param longname: The long option name (e.g. "verbose" instead of "v")

        @return: L{None}
        z--%sz--%s=Nrr��[z\[�]z\]z[%s]�*T)r�rHr�)rlr��getDescription�replace�	getActionr]r�rDrr�rM)r7r��	longFieldr+�
shortField�descr�descriptionField�actionField�
multiField�longExclusionsField�shortExclusionsFields           r0r�zZshArgumentsGenerator.writeOpt�sj���t�0�0�0���)�I��(�*�I��#�#�H�-���D�=��u��J��J��#�#�H�-�� �=�=��e�4��+�3�3�C��?��!�$4�4���n�n�X�.���t�}�}�$��J��J�"�o�o�h�7���#'�?�?�8��?�#M� ��I�I�O�O��-�"�"�(�#�
�	��&��/�
�
�I�I�O�O�H�%��	�	����(���$��
�	
��f�W�o�	
�	
�	�	����!r;c��||jvr\t|j|�r|j|�}n|j|}|j|tj�S||j
vrd|�d�Sy)z]
        Return a zsh "action" string for the given argument
        @return: C{str}
        r
z:_filesr�)r_�callabler:rr5rk)r7r�r�s   r0r�zZshArgumentsGenerator.getAction4sy��
�t���&������1�2�2�����2�4������2���$�$�X�u�z�z�:�:��t�1�1�1��x�j��(�(�r;c�P�||jvr|j|S	|j|d}|�|S|j	dd�}t|jd|zd�}|�t|�}|�|S|S#t$r(	|j|d}n#t$rd}YnwxYwY�swxYw)z]
        Return the description to be used for this argument
        @return: C{str}
        rrNr�_zopt_%s)r[rl�KeyErrorrkr�rrC�descrFromDoc)r7r�r��longMangled�objs     r0r�z$ZshArgumentsGenerator.getDescriptionDs����t�(�(�(��$�$�X�.�.�	��-�-�h�7��:�E����L��&�&�s�C�0���d�l�l�H�{�$:�D�A���?� ��%�E�� ������#�	�
��2�2�8�<�Q�?����
���
��	�s5�A4�4	B%�>B�B%�B�B%�B�B%�$B%c�2�|j|}|dxsdS)z[
        Return the short option letter or None
        @return: C{str} or L{None}
        rN)rm)r7r�rvs   r0r�z$ZshArgumentsGenerator.getShortOptioncs#��
�1�1�(�;���q�z�!�T�!r;Nc��i}tj|j|d�i}|j�D]}t	|�dk(s�||||<||=�|j�D]�\}}|j
dd�}||jvr�'|j|�}d}||vr||}|jjj}	|	dk(rD|jj||d|g�|d|g|j|<|d|g|j|<��|jj|||g�||g|j |<|d|g|j|<��y)z�
        Add additional options to the optFlags and optParams lists.
        These will be defined by 'opt_foo' methods of the Options subclass
        @return: L{None}
        �opt_rr�rNr)r�accumulateMethodsrCr�rh�itemsr�rmr��__func__�__code__�co_argcountrjr�rkrWrl)
r7�methodsDict�
methodToShortr��
methodName�	methodObjr�r�r+�reqArgss
          r0rnz*ZshArgumentsGenerator.addAdditionalOptionsksx��.0���!�!�$�,�,��V�D��
��$�$�&�	&�D��4�y�A�~�37�
�k�$�/�0���%�	&�
&1�%6�%6�%8�	Q�!�J�	�!�)�)�#�s�3�H��4�:�:�:���'�'��1�E��E��M�)�%�i�0���(�(�1�1�=�=�G��!�|����%�%�x���e�&D�E�8=�t�U�7K��*�*�8�4�=B�D�%�<P��/�/��9��
�
�$�$�h��u�%=�>�7<�e�n��)�)�(�3�=B�D�%�<P��/�/��9�/	Qr;)F)r�N)r<r=r>rPrErrxrzryr{ror�rrrrpr�r�r�r�rnr?r;r0rJrJ�sh��2�hB0�H�
�$�&�,*��,(*�T�$�s�C��H�}�"5��6@"�D� �>"�%Qr;rJc��|j�|jj�ry|jjd�D�cgc]&}|s�|j�r�|j���(}}dj	|�Scc}w)zP
    Generate an appropriate description from docstring of the given object
    N�
r�)rP�isspacer�stripr�)r��x�liness   r0r�r��sf���{�{��c�k�k�1�1�3�� #��� 1� 1�$� 7�Q�1�1�Q�Y�Y�[�Q�W�W�Y�Q�E�Q��8�8�E�?���
Rs�B�
B�Bc�V�d|vrd|zdzSd}|D]}|dvr|dz}||z}�|dz}|S)zw
    Shell escape the given string

    Implementation borrowed from now-deprecated commands.mkarg() in the stdlib
    �'�"z\$"`�\r?)r��s�cs   r0r�r��sV���!�|��Q�w��}���A�
�����<��D��A�
��E���	
�C��A��Hr;)rPrrar��typesr�typingrrr�twisted.pythonrrr	�twisted.python.compatr
r1�	Completerr3r rrJr�r�r?r;r0�<module>r�sp��
�0����"�"�/�/�(�a�HF�u���F�2�2�j�:��8mQ�mQ�`
�
r;

Zerion Mini Shell 1.0