HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/python/test/__pycache__/test_shellcomp.cpython-38.pyc
U


W[1U�@sTdZddlmZmZddlZddlmZddlmZddl	m
Z
mZmZddl
mZmZmZddl
mZGd	d
�d
e�ZGdd�de�Zd
d�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�de�Zdd�ZGdd�dej�Z Gdd �d ej�Z!Gd!d"�d"ej�Z"Gd#d$�d$e �Z#d%Z$d&Z%dS)'z*
Test cases for twisted.python._shellcomp
�)�division�absolute_importN)�BytesIO)�unittest)�
_shellcomp�usage�reflect)�Completions�	Completer�
CompleteFiles��CompleteListc@seZdZdZdd�ZdS)�ZshScriptTestMetaz*
    Metaclass of ZshScriptTestMixin.
    cCsHdd�}d|kr8|dD]\}}|||�}||d|<qt�||||�S)Ncs��fdd�}|S)Ncst|���S)N)�test_genZshFunction��self��cmdName�optionsFQPN��D/usr/lib/python3/dist-packages/twisted/python/test/test_shellcomp.py�runTestsz<ZshScriptTestMeta.__new__.<locals>.makeTest.<locals>.runTestr)rrrrrr�makeTestsz+ZshScriptTestMeta.__new__.<locals>.makeTestZgenerateForZtest_genZshFunction_)�type�__new__)�cls�name�basesZattrsrrr�testrrrrs
zZshScriptTestMeta.__new__N)�__name__�
__module__�__qualname__�__doc__rrrrrrsrc@seZdZdZeZdS)�ZshScriptTestMixina�
    Integration test helper to show that C{usage.Options} classes can have zsh
    completion functions generated for them without raising errors.

    In your subclasses set a class variable like so:

    #            | cmd name | Fully Qualified Python Name of Options class |
    #
    generateFor = [('conch',  'twisted.conch.scripts.conch.ClientOptions'),
                   ('twistd', 'twisted.scripts.twistd.ServerOptions'),
                   ]

    Each package that contains Twisted scripts should contain one TestCase
    subclass which also inherits from this mixin, and contains a C{generateFor}
    list appropriate for the scripts in that package.
    N)rr r!r"rZ
__metaclass__rrrrr#)sr#c
Cs�t�}|�tjd|�zt�|��}Wn2tk
rX}zt�d|f��W5d}~XYnXz|�	dddg�WnBt
k
r�}zt�d|f��W5d}~XYntk
r�YnX|�d�|�
d	�|�d
t|�d
���|�
d	�|��t|d��r�|jD]�\}}}}	z|�	|dddg�WnFt
k
�rT}zt�d
|f��W5d}~XYn tk
�rhYnX|�d�|�
d	�|�d
t|�d
���|�
d	�|���q|��dS)aI
    Generate completion functions for given twisted command - no errors
    should be raised

    @type cmdName: C{str}
    @param cmdName: The name of the command-line utility e.g. 'twistd'

    @type optionsFQPN: C{str}
    @param optionsFQPN: The Fully Qualified Python Name of the C{Options}
        class to be tested.
    �_shellCompFilez0Couldn't import or instantiate Options class: %sN��--_shell-completion�zsh:2z&ImportError calling parseOptions(): %szSystemExit not raisedr��subCommandszzsh:3z4ImportError calling parseOptions() on subcommand: %s)r�patchr�OptionsrZnamedAny�	ExceptionrZSkipTest�parseOptions�ImportError�
SystemExitZfail�seek�assertEqual�len�read�truncate�hasattrr)Z
flushWarnings)
rrr�
outputFile�o�e�cmdZshort�parser�docrrrr>sJ�



�
�


rc@sxeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�ZshTestsz'
    Tests for zsh completion code
    cCs�t�}t�|dt��}tjj��}|�tjj�|�	|j|�|�	|j
ttjj
��|�	|jtjj�tjj
��}|�tjj
�|�	|j
|�|�	|jtjj�dS)zi
        Are `compData' attributes you can place on Options classes
        picked up correctly?
        �aceN)�FighterAceExtendedOptionsr�ZshArgumentsGeneratorr�FighterAceOptions�compData�descriptions�copy�updater1�multiUse�set�mutuallyExclusive�
optActions�extraActions)r�opts�agrBrHrrr�test_accumulateMetadata�s"
���z ZshTests.test_accumulateMetadatacCs�Gdd�dt�}|�}t�|dt��}tdddddd	d
g�tddddddd	d
g�tdddddd	d
g�tdddddd	d
g�tdddddddg�d
�}|�|j|�dS)z�
        Exercise a corner-case of ZshArgumentsGenerator.makeExcludesDict()
        where the long option name already exists in the `excludes` dict being
        built.
        c@s.eZdZdddggZedddddggd�ZdS)	zGZshTests.test_mutuallyExclusiveCornerCase.<locals>.OddFighterAceOptions�anatraNz0Select the Anatra DS as your dogfighter aircraft�fokker�albatros�spad�bristol�rG)rr r!�optFlagsr	rArrrr�OddFighterAceOptions�s���rTr=rM�brQ�frN�srP�arO)rOrMrQrNrPN)r>rr?rrFr1Zexcludes)rrTrJrKZexpectedrrr� test_mutuallyExclusiveCornerCase�s>

�
�
�
�
��z)ZshTests.test_mutuallyExclusiveCornerCasecCsRt�}t�|dt��}|�d|j�|�d|j�|�d|j�|�d|j�dS)z�
        We pick up options that are only defined by having an
        appropriately named method on your Options class,
        e.g. def opt_foo(self, foo)
        r=Znocrash�
difficultyN)r>rr?rZassertInZflagNameToDefinitionZallOptionsNameToDefinitionZparamNameToDefinition)rrJrKrrr� test_accumulateAdditionalOptions�sz)ZshTests.test_accumulateAdditionalOptionscCsTGdd�dt�}|�ttj|�dt��Gdd�dt�}|�ttj|�dt��dS)z\
        Using a parameter/flag name that doesn't exist
        will raise an error
        c@seZdZeddid�ZdS)z0ZshTests.test_verifyZshNames.<locals>.TmpOptionsZdetaillN)rH�rr r!r	rArrrr�
TmpOptions�sr]r=c@seZdZedgd�ZdS)z1ZshTests.test_verifyZshNames.<locals>.TmpOptions2)ZfooZbarrRNr\rrrr�TmpOptions2�s�r^N)r>�assertRaises�
ValueErrorrr?r)rr]r^rrr�test_verifyZshNames�s
�
�zZshTests.test_verifyZshNamescCsTt�}|�tjd|�|�tdddddg�t�}|�t|j�|�	t
|���dS)zt
        Generate a completion function, and test the textual output
        against a known correct output
        r$�argv�sillyr%r&r'N)rr*rr+�sys�SimpleProgOptionsr_r/r-r1�testOutput1�getvalue�rr6rJrrr�test_zshCode�szZshTests.test_zshCodecCsTt�}|�tjd|�|�tdddddg�t�}|�t|j�|�	t
|���dS)z�
        Generate a completion function with subcommands,
        and test the textual output against a known correct output
        r$rbZsilly2r%r&r'N)rr*rr+rd�SimpleProgWithSubcommandsr_r/r-r1�testOutput2rgrhrrr�test_zshCodeWithSubs�szZshTests.test_zshCodeWithSubsc
Cs\t�}|�tjd|�t�}|�t|jddddddg�|�d�|�	d	t
|�d	���d
S)zx
        Completion still happens even if a command-line is given
        that would normally throw UsageError.
        r$�--fokker�server�--unknown-optionz--unknown-option2r&�zsh:5rr(N�rr*rr+r@r_r/r-r0r1r2r3rhrrr�test_incompleteCommandLines
��
z#ZshTests.test_incompleteCommandLinec
Csnt�}|�tjd|�t�}|�t|jddddddg�|�d�|�	d	t
|�d	���|�d�|��d
S)z�
        Completion still happens even if a command-line is given
        that would normally throw UsageError.

        The existence of --unknown-option prior to the subcommand
        will break subcommand detection... but we complete anyway
        r$rmrorn�
--list-serverr&rprr(N)
rr*rr+r@r_r/r-r0r1r2r3r4rhrrr� test_incompleteCommandLine_case2s
��

z)ZshTests.test_incompleteCommandLine_case2c	CsZt�}|�tjd|�t�}|�t|jdddddg�|�d�|�	dt
|�d���d	S)
z�
        Completion still happens even if a command-line is given
        that would normally throw UsageError.

        Break subcommand detection in a different way by providing
        an invalid subcommand name.
        r$rmzunknown-subcommandrsr&zzsh:4rr(Nrqrhrrr� test_incompleteCommandLine_case3*s
��
z)ZshTests.test_incompleteCommandLine_case3cCsVt�}|�tjd|�t�}|�t|jdddg�|�d�|�	dt
|�d���dS)z�
        Ensure the optimization which skips building the subcommand list
        under certain conditions isn't broken.
        r$z--albar&r'rr(Nrqrhrrr�test_skipSubcommandList>s
�
z ZshTests.test_skipSubcommandListcCs.t�}t�|dd�}|�d�}|�|d�dS)zY
        Test corner case fetching an option description from a method docstring
        r=Nrc)r@rr?�getDescriptionr1)rrJ�argGen�descrrrr�test_poorlyDescribedOptMethodNs
z&ZshTests.test_poorlyDescribedOptMethodcCsFGdd�dtj�}t�}|�}|�|d|�|�t|jdddg�dS)zu
        A C{Completer} with repeat=True may only be used as the
        last item in the extraActions list.
        c@s(eZdZejejdd�e��gd�ZdS)z2ZshTests.test_brokenActions.<locals>.BrokenActionsT)�repeat)rIN)rr r!rr	r
rArrrr�
BrokenActionsas

��r|r$r%r&r'N)rr+rr*r_r`r-)rr|r6rJrrr�test_brokenActions\s
�zZshTests.test_brokenActionscCsNGdd�dtj�}|�}t�|dd�}|�|�d�d�|�|�d�d�dS)	z~
        opt_* methods on Options classes should not override the
        data provided in optFlags or optParameters.
        c@s6eZdZdddggZddddggZdd	�Zd
d�ZdS)z5ZshTests.test_optMethodsDontOverride.<locals>.Options�flagrV�A flag�param�pN�A paramcSsdS�z junk description Nrrrrr�opt_flagwsz>ZshTests.test_optMethodsDontOverride.<locals>.Options.opt_flagcSsdSr�r)rr�rrr�	opt_paramzsz?ZshTests.test_optMethodsDontOverride.<locals>.Options.opt_param)rr r!rS�
optParametersr�r�rrrrr+ssr+r=Nr~rr�r�)rr+rr?r1rw)rr+rJrxrrr�test_optMethodsDontOverridens

z$ZshTests.test_optMethodsDontOverrideN)rr r!r"rLrYr[rarirlrrrtrurvrzr}r�rrrrr<�s"

r<c@seZdZdd�ZdS)�EscapeTestscCs2tj}d}|�||�d�d}|�||�d�dS)z5
        Verify _shellcomp.escape() function
        �$z'$'zA--'$"\`--Bz"A--'\$\"\\\`--B"N)r�escaper1)rZescrrrr�test_escape�s
zEscapeTests.test_escapeN)rr r!r�rrrrr��sr�c@seZdZdZdd�ZdS)�CompleterNotImplementedTestsz�
    Test that using an unknown shell constant with SubcommandAction
    raises NotImplementedError

    The other Completer() subclasses are tested in test_usage.py
    cCst��}|�t|jdd�dS)zM
        Using an unknown shellType should raise NotImplementedError
        NZbad_shell_type)rZSubcommandActionr_�NotImplementedErrorZ
_shellCode)r�actionrrr�test_unknownShell�s

�z.CompleterNotImplementedTests.test_unknownShellN)rr r!r"r�rrrrr��sr�c@s*eZdZdZdddggZddddggZdS)�FighterAceServerOptionsz4
    Options for FighterAce 'server' subcommand
    zlist-serverNz3List this server with the online FighterAce networkzpackets-per-secondz+Number of update packets to send per secondZ20)rr r!r"rSr�rrrrr��s��r�c	@s�eZdZdZdddgdddgdd	d
gddd
gdddgdddgdddggZddddgddddggZdded ggZed!d"d#�dgddddggde	d$g�ie
d%d&�gd'�Zd(d)�ZdS)*r@zB
    Command-line options for an imaginary `Fighter Ace` game
    rNrVz2Select the Fokker Dr.I as your dogfighter aircraftrOrXz5Select the Albatros D-III as your dogfighter aircraftrPrWz1Select the SPAD S.VII as your dogfighter aircraftrQrUz4Select the Bristol Scout as your dogfighter aircraft�physicsr�z$Enable secret Twisted physics engineZjam�jz6Enable a small chance that your machine guns will jam!�verbose�v�1Verbose logging (may be specified more than once)z
pilot-nameNzWhat's your name, Ace?zManfred von Richthofen�detail�dz*Select the level of rendering detail (1-5)�3rnzStart FighterAce game-server.zTwisted-PhysicszRendering detail level)r�r�Z12345zsaved game file to load�ry�rBrErGrHrIcCsdS)� Nrrrrr�	opt_silly�szFighterAceOptions.opt_silly)
rr r!r"rSr�r�r)r	r
rrAr�rrrrr@�s\��������������
�r@c@sTeZdZdZdddggZddddggZeddided	d
�id�Zdd
�Z	dd�Z
dS)r>z�
    Extend the options and zsh metadata provided by FighterAceOptions.
    _shellcomp must accumulate options and metadata from all classes in the
    hiearchy so this is important to test.
    z	no-stallsNz+Turn off the ability to stall your aircraftz
reality-levelz)Select the level of physics reality (1-5)�5zCan't stall your planezPhysics reality levelr�)rBrHcCsdS)z8
        Select that you can't crash your plane
        Nrrrrr�opt_nocrash�sz%FighterAceExtendedOptions.opt_nocrashcCsdS)z+
        How tough are you? (1-10)
        Nr)rrZrrr�opt_difficulty�sz(FighterAceExtendedOptions.opt_difficulty)rr r!r"rSr�r	r
rAr�r�rrrrr>�s ����r>cCstdddgdd�S)N�1�2r�zAccuracy'`?r�rrrrr�_accuracyAction�sr�c
@s�eZdZdZdddgdddgdd	d
ggZddd
dgddddggZeddd�dgddggeddddd
gdd�ed�e	dd�gd�Z
dd�ZdS) rez>
    Command-line options for a `Silly` imaginary program
    �color�czTurn on color outputZgray�gzTurn on gray-scale outputr�r�r��optimizationNr�z&Select the level of optimization (1-5)�accuracyrXr�z"Select the level of accuracy (1-3)zColor onzOptimization level)r�r�r�r��4z
Optimization?r�)r�r�zoutput filer�cCsdS)zM
        usage.Options does not recognize single-letter opt_ methods
        Nrrrrr�opt_X szSimpleProgOptions.opt_X)rr r!r"rSr�r	r
r�rrAr�rrrrres8��������
�rec@seZdZdddggZdS)�SimpleProgSub1�sub-optrWzSub Opt OneN�rr r!rSrrrrr�'sr�c@seZdZdddggZdS)�SimpleProgSub2r�rWzSub Opt TwoNr�rrrrr�,sr�c@sHeZdZdgddggZdgddgddd	ggZd
dedgd
dedggZdS)rjzsome-optionzother-optionr7z
some-paramzother-paramr�z
another-param�PzYet Another ParamZsub1Nz
Sub Command 1Zsub2z
Sub Command 2)rr r!rSr�r�r�r)rrrrrj1s��

�rjs�#compdef silly

_arguments -s -A "-*" \
':output file (*):_files -g "*"' \
"(--accuracy)-a[Select the level of accuracy (1-3)]:Accuracy'\`?:(1 2 3)" \
"(-a)--accuracy=[Select the level of accuracy (1-3)]:Accuracy'\`?:(1 2 3)" \
'(--color --gray -g)-c[Color on]' \
'(--gray -c -g)--color[Color on]' \
'(--color --gray -c)-g[Turn on gray-scale output]' \
'(--color -c -g)--gray[Turn on gray-scale output]' \
'--help[Display this help and exit.]' \
'--optimization=[Optimization level]:Optimization?:(1 2 3 4 5)' \
'*-v[Verbose logging (may be specified more than once)]' \
'*--verbose[Verbose logging (may be specified more than once)]' \
'--version[Display Twisted version and exit.]' \
&& return 0
s�#compdef silly2

_arguments -s -A "-*" \
'*::subcmd:->subcmd' \
':output file (*):_files -g "*"' \
"(--accuracy)-a[Select the level of accuracy (1-3)]:Accuracy'\`?:(1 2 3)" \
"(-a)--accuracy=[Select the level of accuracy (1-3)]:Accuracy'\`?:(1 2 3)" \
'(--another-param)-P[another-param]:another-param:_files' \
'(-P)--another-param=[another-param]:another-param:_files' \
'(--color --gray -g)-c[Color on]' \
'(--gray -c -g)--color[Color on]' \
'(--color --gray -c)-g[Turn on gray-scale output]' \
'(--color -c -g)--gray[Turn on gray-scale output]' \
'--help[Display this help and exit.]' \
'--optimization=[Optimization level]:Optimization?:(1 2 3 4 5)' \
'(--other-option)-o[other-option]' \
'(-o)--other-option[other-option]' \
'(--other-param)-p[other-param]:other-param:_files' \
'(-p)--other-param=[other-param]:other-param:_files' \
'--some-option[some-option]' \
'--some-param=[some-param]:some-param:_files' \
'*-v[Verbose logging (may be specified more than once)]' \
'*--verbose[Verbose logging (may be specified more than once)]' \
'--version[Display Twisted version and exit.]' \
&& return 0
local _zsh_subcmds_array
_zsh_subcmds_array=(
"sub1:Sub Command 1"
"sub2:Sub Command 2"
)

_describe "sub-command" _zsh_subcmds_array
)&r"Z
__future__rrrd�iorZ
twisted.trialrZtwisted.pythonrrrZtwisted.python.usager	r
rr
rr�objectr#rZTestCaser<r�r�r+r�r@r>r�rer�r�rjrfrkrrrr�<module>s2D/#