File: //usr/lib/python3/dist-packages/twisted/python/__pycache__/_shellcomp.cpython-310.pyc
o
�b�b � @ s� d Z ddlZddlZddlZddlmZ ddlmZmZm Z ddl
mZmZm
Z
ddlmZ dd� ZG d d
� d
ej�ZG dd� d�ZG d
d� de�ZG dd� d�Zdd� Zdd� ZdS )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 C s\ |rt |�tkr|j}|d �d�\}}t|�}|d8 }|| }|dkr7||d �d�r2|d8 }nn|dks$|d|� }t| dd�}|r�d}z
t�|| j| j �\} }W n
tj
y^ Y nw |r�| jD ]&\}
}}}
|d |
ksv|d |kr�|� }| |_t
|| ||�}|�� dS qdd }|�d�r�d
}t| ||�}|j|d� dS t| ||�}|�� dS )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�subCommandsr TF)�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�genr � r. �;/usr/lib/python3/dist-packages/twisted/python/_shellcomp.py�
shellComplete'