CasperSecurity

Current Path : /usr/lib/python3/dist-packages/twisted/python/test/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/twisted/python/test/__pycache__/test_shellcomp.cpython-310.pyc

o

�b�R�@sNdZddlZddlmZddlmZmZddlmZm	Z	m
Z
ddlmZm
Z
mZmZddlmZGdd	�d	e�ZGd
d�ded�Zd
d�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�de
j�ZGdd�de
j�ZGdd�de�Zdd�ZGdd�de
j�ZGdd �d e
j�Z Gd!d"�d"e
j�Z!Gd#d$�d$e�Z"d%Z#d&Z$dS)'z*
Test cases for twisted.python._shellcomp
�N)�BytesIO)�List�Optional)�
_shellcomp�reflect�usage)�
CompleteFiles�CompleteList�	Completer�Completions)�unittestc@�eZdZdZdd�ZdS)�ZshScriptTestMetaz*
    Metaclass of ZshScriptTestMixin.
    cCsHdd�}d|vr|dD]\}}|||�}||d|<qt�||||�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�runTestsz<ZshScriptTestMeta.__new__.<locals>.makeTest.<locals>.runTestr)rrrrrr�makeTestsz+ZshScriptTestMeta.__new__.<locals>.makeTest�generateFor�test_genZshFunction_)�type�__new__)�cls�name�bases�attrsrrr�testrrrrs
zZshScriptTestMeta.__new__N)�__name__�
__module__�__qualname__�__doc__rrrrrrsrc@seZdZdZdS)�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)r"r#r$r%rrrrr&(sr&)�	metaclassc
Cs�t�}|�tjd|�zt�|��}Wnty'}zt�d|f��d}~wwz	|�	gd��Wnt
yD}zt�d|f��d}~wtyLYnw|�d�|�
d�|�dt|�d���|�
d�|��t|d	�r�|jD]K\}}}}	z|�	|d
ddg�Wnt
y�}zt�d
|f��d}~wty�Ynw|�d�|�
d�|�dt|�d���|�
d�|��qs|��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��subCommandsr*r+zzsh:3z4ImportError calling parseOptions() on subcommand: %s)r�patchr�Optionsr�namedAny�	Exceptionr�SkipTest�parseOptions�ImportError�
SystemExit�fail�seek�assertEqual�len�read�truncate�hasattrr.�
flushWarnings)
rrr�
outputFile�o�e�cmd�short�parser�docrrrr;sR�����



���



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�updater9�multiUse�set�mutuallyExclusive�
optActions�extraActions)r�opts�agrLrRrrr�test_accumulateMetadata�s
�z ZshTests.test_accumulateMetadatacCs\Gdd�dt�}|�}t�|dt��}hd�hd�hd�hd�hd�d	�}|�|j|�d
S)z�
        Exercise a corner-case of ZshArgumentsGenerator.makeExcludesDict()
        where the long option name already exists in the `excludes` dict being
        built.
        c@s&eZdZgd�gZegd�gd�ZdS)zGZshTests.test_mutuallyExclusiveCornerCase.<locals>.OddFighterAceOptions)�anatraNz0Select the Anatra DS as your dogfighter aircraft)rW�fokker�albatros�spad�bristol�rQN)r"r#r$�optFlagsrrKrrrr�OddFighterAceOptions�s�
�r^rG>�b�f�srZrWrXr[>�ar_r`rarZrXr[rY>rbr`rarZrWrXrY>rbr_rarZrWr[rY>rbr_r`rWrXr[rY)rYrWr[rXrZN)rHrrIrr9�excludes)rr^rTrU�expectedrrr� 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)
        rG�nocrash�
difficultyN)rHrrIr�assertIn�flagNameToDefinition�allOptionsNameToDefinition�paramNameToDefinition)rrTrUrrr� 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>.TmpOptions�detaillN)rR�r"r#r$rrKrrrr�
TmpOptions�srorGc@seZdZedgd�ZdS)z1ZshTests.test_verifyZshNames.<locals>.TmpOptions2)�foo�barr\Nrnrrrr�TmpOptions2�srrN)rH�assertRaises�
ValueErrorrrIr)rrorrrrr�test_verifyZshNames�s��zZshTests.test_verifyZshNamescC�Pt�}|�tjd|�|�tdgd��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/rr0�sys�SimpleProgOptionsrsr6r4r9�testOutput1�getvalue�rr?rTrrr�test_zshCode��zZshTests.test_zshCodecCrv)z�
        Generate a completion function with subcommands,
        and test the textual output against a known correct output
        r(rw)�silly2r*r+r,N)rr/rr0ry�SimpleProgWithSubcommandsrsr6r4r9�testOutput2r|r}rrr�test_zshCodeWithSubs�rzZshTests.test_zshCodeWithSubscC�Tt�}|�tjd|�t�}|�t|jgd��|�d�|�	dt
|�d���dS)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/rr0rJrsr6r4r8r9r:r;r}rrr�test_incompleteCommandLine�s�
z#ZshTests.test_incompleteCommandLinecCsft�}|�tjd|�t�}|�t|jgd��|�d�|�	dt
|�d���|�d�|��dS)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()r�r�r��
--list-serverr+r�rr-N)
rr/rr0rJrsr6r4r8r9r:r;r<r}rrr� test_incompleteCommandLine_case2s�

z)ZshTests.test_incompleteCommandLine_case2cCr�)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()r�zunknown-subcommandr�r+zzsh:4rr-Nr�r}rrr� test_incompleteCommandLine_case34s�
z)ZshTests.test_incompleteCommandLine_case3cCr�)z�
        Ensure the optimization which skips building the subcommand list
        under certain conditions isn't broken.
        r()z--albar+r,rr-Nr�r}rrr�test_skipSubcommandListOs�
z ZshTests.test_skipSubcommandListcCs.t�}t�|dd�}|�d�}|�|d�dS)zY
        Test corner case fetching an option description from a method docstring
        rGNrx)rJrrI�getDescriptionr9)rrT�argGen�descrrrr�test_poorlyDescribedOptMethod_s
z&ZshTests.test_poorlyDescribedOptMethodcCsDGdd�dtj�}t�}|�}|�|d|�|�t|jgd��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)rSN)r"r#r$rrr
rKrrrr�
BrokenActionsrs
�r�r(r)N)rr0rr/rsrtr4)rr�r?rTrrr�test_brokenActionsls�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@s0eZdZgd�gZgd�gZdd�Zdd�ZdS)z5ZshTests.test_optMethodsDontOverride.<locals>.Options)�flagr`�A flag)�param�pN�A paramcS�dS�zjunk descriptionNrrrrr�opt_flag��z>ZshTests.test_optMethodsDontOverride.<locals>.Options.opt_flagcSr�r�r)rr�rrr�	opt_param�r�z?ZshTests.test_optMethodsDontOverride.<locals>.Options.opt_paramN)r"r#r$r]�
optParametersr�r�rrrrr0�s


r0rGNr�r�r�r�)rr0rrIr9r�)rr0rTr�rrr�test_optMethodsDontOverride~s

z$ZshTests.test_optMethodsDontOverrideN)r"r#r$r%rVrerlrur~r�r�r�r�r�r�r�r�rrrrrFs
rFc@seZdZdd�ZdS)�EscapeTestscCs2tj}d}|�||�d�d}|�||�d�dS)z5
        Verify _shellcomp.escape() function
        �$z'$'zA--'$"\`--Bz"A--'\$\"\\\`--B"N)r�escaper9)r�escr!rrr�test_escape�s
zEscapeTests.test_escapeN)r"r#r$r�rrrrr��sr�c@r
)�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
        N�bad_shell_type)r�SubcommandActionrs�NotImplementedError�
_shellCode)r�actionrrr�test_unknownShell�s
�z.CompleterNotImplementedTests.test_unknownShellN)r"r#r$r%r�rrrrr��sr�c@s$eZdZdZgd�gZgd�gZdS)�FighterAceServerOptionsz4
    Options for FighterAce 'server' subcommand
    )zlist-serverNz3List this server with the online FighterAce network)zpackets-per-secondNz+Number of update packets to send per second�20N)r"r#r$r%r]r�rrrrr��s��r�c@s�eZdZUdZgd�gd�gd�gd�gd�gd�gd�gZeeeeed	<gd
�gd�gZ	eeeeed<d
de
dggZeddd�dggd�gde
dg�iedd�gd�Zdd�ZdS)rJzB
    Command-line options for an imaginary `Fighter Ace` game
    )rXr`z2Select the Fokker Dr.I as your dogfighter aircraft)rYrbz5Select the Albatros D-III as your dogfighter aircraft)rZraz1Select the SPAD S.VII as your dogfighter aircraft)r[r_z4Select the Bristol Scout as your dogfighter aircraft)�physicsr�z$Enable secret Twisted physics engine)�jam�jz6Enable a small chance that your machine guns will jam!��verbose�vz1Verbose logging (may be specified more than once)r])z
pilot-nameNzWhat's your name, Ace?zManfred von Richthofen)�detail�dz*Select the level of rendering detail (1-5)�3r�r�NzStart FighterAce game-server.zTwisted-PhysicszRendering detail level)r�r�r�)rXrYrZr[r��12345zsaved game file to load�r��rLrOrQrRrScCr�)� Nrrrrr�	opt_silly�r�zFighterAceOptions.opt_silly)r"r#r$r%r]rr�str�__annotations__r�r�r.rr	rrKr�rrrrrJ�s.
��
�
�rJc@sNeZdZdZgd�gZgd�gZeddidedd�id	�Zd
d�Z	dd
�Z
dS)rHz�
    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.
    )�	no-stallsNz+Turn off the ability to stall your aircraft)�
reality-levelNz)Select the level of physics reality (1-5)�5r�zCan't stall your planer�zPhysics reality levelr�)rLrRcCr�)z8
        Select that you can't crash your plane
        Nrrrrr�opt_nocrash�r�z%FighterAceExtendedOptions.opt_nocrashcCr�)z+
        How tough are you? (1-10)
        Nr)rrgrrr�opt_difficultyr�z(FighterAceExtendedOptions.opt_difficultyN)r"r#r$r%r]r�rr
rKr�r�rrrrrH�s
��rHcCstgd�dd�S)N)�1�2r�zAccuracy'`?r�)r	rrrr�_accuracyAction	sr�c@sxeZdZdZgd�gd�gd�gZgd�gd�gZeddd	�d
gddggegd
�dd�ed�e	dd�gd�Z
dd�ZdS)rzz>
    Command-line options for a `Silly` imaginary program
    )�color�czTurn on color output)�gray�gzTurn on gray-scale outputr�)�optimizationNr�z&Select the level of optimization (1-5))�accuracyrbr�z"Select the level of accuracy (1-3)zColor onzOptimization level)r�r�r�r�r�)r�r�r��4r�z
Optimization?r�)r�r�zoutput filer�cCr�)zM
        usage.Options does not recognize single-letter opt_ methods
        Nrrrrr�opt_X+r�zSimpleProgOptions.opt_XN)r"r#r$r%r]r�rr	r�rrKr�rrrrrzs*����
�
rzc@�eZdZgd�gZdS)�SimpleProgSub1)�sub-optrazSub Opt OneN�r"r#r$r]rrrrr�1�r�c@r�)�SimpleProgSub2)r�razSub Opt TwoNr�rrrrr�5r�r�c@sFeZdZdgddggZdgddggd�gZdd	ed
gdd	edggZd	S)
r�zsome-optionzother-optionr@z
some-paramzother-paramr�)z
another-param�PzYet Another Param�sub1Nz
Sub Command 1�sub2z
Sub Command 2)r"r#r$r]r�r�r�r.rrrrr�9s�

�r�s�#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%ry�ior�typingrr�twisted.pythonrrr�twisted.python.usagerr	r
r�
twisted.trialrrrr&r�TestCaserFr�r�r0r�rJrHr�rzr�r�r�r{r�rrrr�<module>s2D%#
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY