+
    DfjR                     $   R t ^ RIt^ RIHt ^ RIHtHt ^ RIHtH	t	H
t
 ^ RIHtHtHtHt ^ RIHt  ! R R]4      t ! R	 R
]R7      tR t ! R R]P,                  4      t ! R R]P,                  4      t ! R R]P,                  4      t ! R R]
P4                  4      t ! R R]
P4                  4      t ! R R]4      tR t ! R R]
P4                  4      t ! R R]
P4                  4      t  ! R R]
P4                  4      t! ! R  R!]4      t"R"t#R#t$R# )$z*
Test cases for twisted.python._shellcomp
N)BytesIO)ListOptional)
_shellcompreflectusage)CompleteFilesCompleteList	CompleterCompletions)unittestc                   *   a  ] tR t^t o RtR tRtV tR# )ZshScriptTestMetaz"
Metaclass of ZshScriptTestMixin.
c                    R  pRV9   d&   VR,           F  w  rVV! WV4      pWsRV,           &   K  	  \         P                  WW#4      # )c                    a a V V3R  lpV# )c                    < \        V SS4      # )N)test_genZshFunction)selfcmdNameoptionsFQPNs   &D/usr/lib/python3/dist-packages/twisted/python/test/test_shellcomp.pyrunTest<ZshScriptTestMeta.__new__.<locals>.makeTest.<locals>.runTest   s    *4+FF     )r   r   r   s   ff r   makeTest+ZshScriptTestMeta.__new__.<locals>.makeTest   s    G Nr   generateFortest_genZshFunction_)type__new__)clsnamebasesattrsr   r   r   tests   &&&&    r   r    ZshScriptTestMeta.__new__   sQ    	 E!(-m(<(<$5:>,w67 )= ||Cu44r   r   N)__name__
__module____qualname____firstlineno____doc__r    __static_attributes____classdictcell____classdict__s   @r   r   r      s     5 5r   r   c                       ] tR t^(tRtRtR# )ZshScriptTestMixinaw  
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.
r   N)r'   r(   r)   r*   r+   r,   r   r   r   r1   r1   (   s    r   r1   )	metaclassc           	     F   \        4       pV P                  \        P                  RV4        \        P
                  ! V4      ! 4       p TP                  . RO4       T P                  R4       TP                  ^ 4       T P                  ^\        TP!                  ^4      4      4       TP                  ^ 4       TP#                  4        \%        TR4      '       d   TP&                   F  w  rgr TP                  TRRR	.4       T P                  R4       TP                  ^ 4       T P                  ^\        TP!                  ^4      4      4       TP                  ^ 4       TP#                  4        K  	  T P)                  4        R#   \         d    p\        P                  ! RT: 24      hRp?ii ; i  \         d   p\        P                  ! RT34      hRp?i\         d     ELzi ; i  \         d   p\        P                  ! R
T34      hRp?i\         d     ELi ; i)a)  
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.
_shellCompFilez.Couldn't import or instantiate Options class: N --_shell-completionzSystemExit not raisedz&ImportError calling parseOptions(): %ssubCommandszzsh:3z4ImportError calling parseOptions() on subcommand: %sr5   r6   zsh:2)r   patchr   Optionsr   namedAny	Exceptionr   SkipTestparseOptionsfailImportError
SystemExitseekassertEquallenreadtruncatehasattrr7   flushWarnings)
r   r   r   
outputFileoecmdshortparserdocs
   &&&       r   r   r   ;   s    JJJu}}.
;
[)+
+	;< 			)*OOAQJOOA./0OOA q-  '(}}#C3R)>HI 		12OOAQJOOA$6 78OOA!% (5, 	]  
EFH
 	

  P  H1$OO    ''MPQt   s_   F 	F3 .G+F0F++F03G(>GG(#G('G(+H 6HH H H c                   r   a  ] tR t^t o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tRtV tR# )ZshTestsz
Tests for zsh completion code
c                X   \        4       p\        P                  ! VR\        4       4      p\        P
                  P                  P                  4       pVP                  \         P
                  P                  4       V P                  VP                  V4       V P                  VP                  \        \        P
                  P                  4      4       V P                  VP                  \        P
                  P                  4       \        P
                  P                  P                  4       pVP                  \         P
                  P                  4       V P                  VP                  V4       V P                  VP                  \        P
                  P                  4       R# )zQ
Are `compData' attributes you can place on Options classes
picked up correctly?
aceN)FighterAceExtendedOptionsr   ZshArgumentsGeneratorr   FighterAceOptionscompDatadescriptionscopyupdaterD   multiUsesetmutuallyExclusive
optActionsextraActions)r   optsagrY   r_   s   &    r   test_accumulateMetadata ZshTests.test_accumulateMetadata   s#   
 )*--dE79E(11>>CCE5>>KKL,7c*;*D*D*M*M&NO  "3"<"<"N"N	
 '//::??A
3<<GGH
3*;*D*D*Q*QRr   c                     ! R R\         4      pV! 4       p\        P                  ! VR\        4       4      pR0 R
mR0 RmR0 RmR0 RmR0 Rm/pV P	                  VP
                  V4       R	# )z
Exercise a corner-case of ZshArgumentsGenerator.makeExcludesDict()
where the long option name already exists in the `excludes` dict being
built.
c                   8    ] tR t^t. RO.t]! . RO.R7      tRtR# )GZshTests.test_mutuallyExclusiveCornerCase.<locals>.OddFighterAceOptionsNr^   r   )anatraNz0Select the Anatra DS as your dogfighter aircraft)ri   fokkeralbatrosspadbristol)r'   r(   r)   r*   optFlagsr   rX   r,   r   r   r   OddFighterAceOptionsrg      s!    
 UH ##V"WHr   ro   rT   rk   ri   rm   rj   rl   N>   bfsrl   ri   rj   rm   >   arp   rq   rr   rl   rj   rm   rk   >   rs   rq   rr   rl   ri   rj   rk   >   rs   rp   rr   rl   ri   rm   rk   >   rs   rp   rq   ri   rj   rm   rk   )rU   r   rV   r   rD   excludes)r   ro   ra   rb   expecteds   &    r    test_mutuallyExclusiveCornerCase)ZshTests.test_mutuallyExclusiveCornerCase   sl    		#< 		 $%--dE79E NSNNN
 	h/r   c                :   \        4       p\        P                  ! VR\        4       4      pV P	                  RVP
                  4       V P	                  RVP                  4       V P	                  RVP                  4       V P	                  RVP                  4       R# )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)
rT   nocrash
difficultyN)rU   r   rV   r   assertInflagNameToDefinitionallOptionsNameToDefinitionparamNameToDefinition)r   ra   rb   s   &  r    test_accumulateAdditionalOptions)ZshTests.test_accumulateAdditionalOptions   sr     )*--dE79Ei!8!89i!>!>?lB$<$<=lB$A$ABr   c                    ! R R\         4      pV P                  \        \        P                  V! 4       R\        4       4        ! R R\         4      pV P                  \        \        P                  V! 4       R\        4       4       R# )zD
Using a parameter/flag name that doesn't exist
will raise an error
c                   ,    ] tR t^t]! RR/R7      tRtR# )0ZshTests.test_verifyZshNames.<locals>.TmpOptionsdetaillN)r_   r   r'   r(   r)   r*   r   rX   r,   r   r   r   
TmpOptionsr      s    "y$.?@Hr   r   rT   c                   *    ] tR t^t]! R.R7      tRtR# )1ZshTests.test_verifyZshNames.<locals>.TmpOptions2rh   r   N)foobarr   r   r   r   TmpOptions2r      s     #n5EFHr   r   N)rU   assertRaises
ValueErrorr   rV   r   )r   r   r   s   &  r   test_verifyZshNamesZshTests.test_verifyZshNames   sn    	A2 	A 	
88*,wy	
	G3 	G
 	,,MI	
r   c                *   \        4       pV P                  \        P                  RV4       V P                  \        R. RO4       \        4       pV P                  \        VP                  4       V P                  \        VP                  4       4       R# )z\
Generate a completion function, and test the textual output
against a known correct output
r4   argvN)sillyr5   r6   r9   )r   r:   r   r;   sysSimpleProgOptionsr   rB   r?   rD   testOutput1getvaluer   rJ   ra   s   &  r   test_zshCodeZshTests.test_zshCode   sh    
 Y


5=="2J?

3 MN "*d&7&78j&9&9&;<r   c                *   \        4       pV P                  \        P                  RV4       V P                  \        R. RO4       \        4       pV P                  \        VP                  4       V P                  \        VP                  4       4       R# )zm
Generate a completion function with subcommands,
and test the textual output against a known correct output
r4   r   N)silly2r5   r6   r9   )r   r:   r   r;   r   SimpleProgWithSubcommandsr   rB   r?   rD   testOutput2r   r   s   &  r   test_zshCodeWithSubsZshTests.test_zshCodeWithSubs   sh    
 Y


5=="2J?

3 NO(**d&7&78j&9&9&;<r   c                ,   \        4       pV P                  \        P                  RV4       \	        4       pV P                  \        VP                  . RO4       VP                  ^ 4       V P                  ^\        VP                  ^4      4      4       R# )z`
Completion still happens even if a command-line is given
that would normally throw UsageError.
r4   N)--fokkerserver--unknown-optionz--unknown-option2r6   zsh:5r   r:   r   r;   rW   r   rB   r?   rC   rD   rE   rF   r   s   &  r   test_incompleteCommandLine#ZshTests.test_incompleteCommandLine   ss    
 Y


5=="2J? "	
 	C
 234r   c                n   \        4       pV P                  \        P                  RV4       \	        4       pV P                  \        VP                  . RO4       VP                  ^ 4       V P                  ^\        VP                  ^4      4      4       VP                  ^ 4       VP                  4        R# )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
r4   N)r   r   r   --list-serverr6   r   )r   r:   r   r;   rW   r   rB   r?   rC   rD   rE   rF   rG   r   s   &  r    test_incompleteCommandLine_case2)ZshTests.test_incompleteCommandLine_case2  s     Y


5=="2J? "	
 	C
 234r   c                ,   \        4       pV P                  \        P                  RV4       \	        4       pV P                  \        VP                  . RO4       VP                  ^ 4       V P                  ^\        VP                  ^4      4      4       R# )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.
r4   N)r   zunknown-subcommandr   r6   zzsh:4r   r   s   &  r    test_incompleteCommandLine_case3)ZshTests.test_incompleteCommandLine_case34  ss     Y


5=="2J? "
	
 	C
 234r   c                ,   \        4       pV P                  \        P                  RV4       \	        4       pV P                  \        VP                  . RO4       VP                  ^ 4       V P                  ^\        VP                  ^4      4      4       R# )zi
Ensure the optimization which skips building the subcommand list
under certain conditions isn't broken.
r4   N)z--albar6   r9   r   r   s   &  r   test_skipSubcommandList ZshTests.test_skipSubcommandListO  sp    
 Y


5=="2J? "))+U	
 	C
 234r   c                    \        4       p\        P                  ! VRR4      pVP                  R4      pV P	                  VR4       R# )zI
Test corner case fetching an option description from a method docstring
rT   Nr   )rW   r   rV   getDescriptionrD   )r   ra   argGendescrs   &   r   test_poorlyDescribedOptMethod&ZshTests.test_poorlyDescribedOptMethod_  sB     !"11$tD%%g. 	(r   c                     ! R R\         P                  4      p\        4       pV! 4       pV P                  VRV4       V P	                  \
        VP                  . RO4       R# )z]
A C{Completer} with repeat=True may only be used as the
last item in the extraActions list.
c                       ] tR tRt]P
                  ! ]P                  ! RR7      ]P                  ! 4       .R7      tRtR# )2ZshTests.test_brokenActions.<locals>.BrokenActionsir  T)repeat)r`   r   N)	r'   r(   r)   r*   r   r   r
   rX   r,   r   r   r   BrokenActionsr   r  s*    ((#ooT:EOO<MNHr   r   r4   Nr8   )r   r;   r   r:   r   r   r?   )r   r   rJ   ra   s   &   r   test_brokenActionsZshTests.test_brokenActionsl  sO    	EMM 	
 Y


4):6))+O	
r   c                     ! R R\         P                  4      pV! 4       p\        P                  ! VRR4      pV P	                  VP                  R4      R4       V P	                  VP                  R4      R4       R# )	zf
opt_* methods on Options classes should not override the
data provided in optFlags or optParameters.
c                   @   a  ] tR tRt o . RO.t. RO.tR tR tRtV t	R# )5ZshTests.test_optMethodsDontOverride.<locals>.Optionsi  Nc                    R# zjunk descriptionNr   r   s   &r   opt_flag>ZshTests.test_optMethodsDontOverride.<locals>.Options.opt_flag      r   c                    R# r   r   )r   params   &&r   	opt_param?ZshTests.test_optMethodsDontOverride.<locals>.Options.opt_param  r   r   r   )flagrq   A flag)r   pNA param)
r'   r(   r)   r*   rn   optParametersr   r   r,   r-   r.   s   @r   r;   r     s$     /0H<=M'' 'r   r;   rT   Nr   r   r   r   )r   r;   r   rV   rD   r   )r   r;   ra   r   s   &   r   test_optMethodsDontOverride$ZshTests.test_optMethodsDontOverride~  se    	'emm 	' y11$tD..v6A..w7Cr   r   N)r'   r(   r)   r*   r+   rc   rv   r   r   r   r   r   r   r   r   r   r   r   r,   r-   r.   s   @r   rR   rR      sT     S.0>C
6
=
=52>565 )
$D Dr   rR   c                   &   a  ] tR tRt o R tRtV tR# )EscapeTestsi  c                    \         P                  pRpV P                  V! V4      R4       RpV P                  V! V4      R4       R# )z%
Verify _shellcomp.escape() function
$z'$'zA--'$"\`--Bz"A--'\$\"\\\`--B"N)r   escaperD   )r   escr%   s   &  r   test_escapeEscapeTests.test_escape  sB     TE*T$=>r   r   N)r'   r(   r)   r*   r   r,   r-   r.   s   @r   r   r     s     
? 
?r   r   c                   *   a  ] tR tRt o RtR tRtV tR# )CompleterNotImplementedTestsi  z
Test that using an unknown shell constant with SubcommandAction
raises NotImplementedError

The other Completer() subclasses are tested in test_usage.py
c                t    \         P                  ! 4       pV P                  \        VP                  RR4       R# )z=
Using an unknown shellType should raise NotImplementedError
Nbad_shell_type)r   SubcommandActionr   NotImplementedError
_shellCode)r   actions   & r   test_unknownShell.CompleterNotImplementedTests.test_unknownShell  s0     ,,.!2!2D:J	
r   r   N)r'   r(   r)   r*   r+   r   r,   r-   r.   s   @r   r   r     s     
 
r   r   c                   .    ] tR tRtRt. RO.t. RO.tRtR# )FighterAceServerOptionsi  z,
Options for FighterAce 'server' subcommand
Nr   )zlist-serverNz3List this server with the online FighterAce network)zpackets-per-secondNz+Number of update packets to send per second20)r'   r(   r)   r*   r+   rn   r   r,   r   r   r   r   r     s     
 	UH	
Mr   r   c            
          a  ] tR tRt o Rt. RO. RO. RO. RO. RO. RO. RO.t. RO. RO.tRR]R..t]	! RR	RR
/R.. RO.R]
! R.4      /]! RR7      .R7      tR tV 3R ltRtV tR# )rW   i  z:
Command-line options for an imaginary `Fighter Ace` game
physicsverboseNdetailr   zStart FighterAce game-server.zTwisted-PhysicszRendering detail level12345zsaved game file to loadr   rY   r\   r^   r_   r`   c                    R# )r5   Nr   r   s   &r   	opt_sillyFighterAceOptions.opt_silly  r   r   c                   < V ^8  d   Qh/ S[ S[ S[S[,          ,          ,          ;R&   S[ S[ S[S[,          ,          ,          ;R&   # )   rn   r   )r   r   str)formatr/   s   "r   __annotate__FighterAceOptions.__annotate__  s?     
 4&'   Xc]+,  r   r   )rj   rq   z2Select the Fokker Dr.I as your dogfighter aircraft)rk   rs   z5Select the Albatros D-III as your dogfighter aircraft)rl   rr   z1Select the SPAD S.VII as your dogfighter aircraft)rm   rp   z4Select the Bristol Scout as your dogfighter aircraft)r   r   z$Enable secret Twisted physics engine)jamjz6Enable a small chance that your machine guns will jam!r   vz1Verbose logging (may be specified more than once))z
pilot-nameNzWhat's your name, Ace?zManfred von Richthofen)r   dz*Select the level of rendering detail (1-5)3)rj   rk   rl   rm   )r'   r(   r)   r*   r+   rn   r   r   r7   r   r	   r   rX   r   __annotate_func__r,   r-   r.   s   @r   rW   rW     s     
 	NRJP@NM+H 	QJ0M 
402QRK !2H>VWDEl,?+@AB#*CDEHA  r   rW   c                   n   a  ] tR tRt o Rt. RO.t. RO.t]! RR/R]! RR7      /R	7      t	R
 t
R tRtV tR# )rU   i  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.
	no-stallsNreality-levelzCan't stall your planezPhysics reality levelr   )rY   r_   c                    R# )z(
Select that you can't crash your plane
Nr   r   s   &r   opt_nocrash%FighterAceExtendedOptions.opt_nocrash  r   r   c                    R# )z
How tough are you? (1-10)
Nr   )r   rz   s   &&r   opt_difficulty(FighterAceExtendedOptions.opt_difficulty  r   r   r   )r   Nz+Turn off the ability to stall your aircraft)r  Nz)Select the level of physics reality (1-5)5)r'   r(   r)   r*   r+   rn   r   r   r
   rX   r  r  r,   r-   r.   s   @r   rU   rU     sQ      SSHQM !#;<#Y5L%MNH

 r   rU   c                       \        . RORR7      # )1zAccuracy'`?r   )r
  2r   )r	   r   r   r   _accuracyActionr  	  s    }==r   c                      a  ] tR tRt o Rt. RO. RO. RO.t. RO. RO.t]! RR	RR
/R.RR..R]! . RORR7      R]	/]
! RR7      .R7      tR tRtV tR# )r   i  z6
Command-line options for a `Silly` imaginary program
colorgrayr   optimizationNaccuracyzColor onzOptimization levelzOptimization?r   zoutput filer   c                    R# )z=
usage.Options does not recognize single-letter opt_ methods
Nr   r   s   &r   opt_XSimpleProgOptions.opt_X+  r   r   r   )r  czTurn on color output)r  gzTurn on gray-scale outputr   )r  Nr  z&Select the level of optimization (1-5))r  rs   r   z"Select the level of accuracy (1-3))r
  r  r   4r  )r'   r(   r)   r*   r+   rn   r   r   r	   r  r   rX   r  r,   r-   r.   s   @r   r   r     s     
 	/2MH 	NDM
 z>;OP#V,-L) 	
 $-89H r   r   c                        ] tR tRt. RO.tRtR# )SimpleProgSub1i1  r   N)sub-optrr   zSub Opt Oner'   r(   r)   r*   rn   r,   r   r   r   r  r  1  
    /0Hr   r  c                        ] tR tRt. RO.tRtR# )SimpleProgSub2i5  r   N)r  rr   zSub Opt Twor  r   r   r   r  r  5  r  r   r  c                   P    ] tR tRtR.RR..tR.RR.. RO.tRR	]R
.RR	]R..tRt	R	# )r   i9  zsome-optionzother-optionrK   z
some-paramzother-paramr   sub1NzSub Command 1sub2zSub Command 2r   )zanother-paramPzYet Another Param)
r'   r(   r)   r*   rn   r   r  r  r7   r,   r   r   r   r   r   9  sM    .#!67H 
	3M 
~7	~7Kr   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+   r   ior   typingr   r   twisted.pythonr   r   r   twisted.python.usager   r	   r
   r   twisted.trialr   r   r   r1   r   TestCaserR   r   r   r;   r   rW   rU   r  r   r  r  r   r   r   r   r   r   <module>r)     s   
   ! 5 5 T T "5 5,#4 &AHSDx   SDl?(## ?
8#4#4 
&emm $" "J 1 8>
   F1U]] 11U]] 1 1 & r   