
    \d                      
   d Z ddlZddlmZmZmZ ddlmZmZ ddl	m
Z
 ddlmZ  G d de          Z G d	 d
e          Z G d de          Z G d de          Z G d de          ZdZd Zd Zd Z G d d          ZdS )z
Support for resolving command-line strings that represent different
checkers available to cred.

Examples:
 - passwd:/etc/passwd
 - memory:admin:asdf:user:lkj
 - unix
    N)OptionalSequenceType)	Attribute	Interface)
getPlugins)usagec                   p    e Zd ZdZ ed          Z ed          Z ed          Z ed          Zd Z	dS )ICheckerFactoryz
    A factory for objects which provide
    L{twisted.cred.checkers.ICredentialsChecker}.

    It's implemented by twistd plugins creating checkers.
    z0A tag that identifies the authentication method.zmA detailed (potentially multi-line) description of precisely what functionality this CheckerFactory provides.z=A short (one-line) description of the argument string format.z@A list of credentials interfaces that this factory will support.c                     dS )z}
        Return an L{twisted.cred.checkers.ICredentialsChecker} provider using the supplied
        argument string.
        N )	argstrings    4lib/python3.11/site-packages/twisted/cred/strcred.pygenerateCheckerzICheckerFactory.generateChecker2   s          N)
__name__
__module____qualname____doc__r   authTypeauthHelpargStringFormatcredentialInterfacesr   r   r   r   r   r      s          yKLLHy	; H
  iG O %9J     r   r   c                       e Zd ZdZdS )StrcredExceptionz+
    Base exception class for strcred.
    Nr   r   r   r   r   r   r   r   r   9   s           r   r   c                       e Zd ZdZdS )InvalidAuthTypezv
    Raised when a user provides an invalid identifier for the
    authentication plugin (known as the authType).
    Nr   r   r   r   r   r   ?              r   r   c                       e Zd ZdZdS )InvalidAuthArgumentStringzl
    Raised by an authentication plugin when the argument string
    provided is formatted incorrectly.
    Nr   r   r   r   r!   r!   F   r   r   r!   c                       e Zd ZdZdS )UnsupportedInterfacesz
    Raised when an application is given a checker to use that does not
    provide any of the application's supported credentials interfaces.
    Nr   r   r   r   r#   r#   M   r   r   r#   z<WARNING: This authType is not supported by this application.c                  *    t          t                    S )z=
    Find all objects that implement L{ICheckerFactory}.
    )r   r   r   r   r   findCheckerFactoriesr%   Y   s     o&&&r   c                 `    t                      D ]}|j        | k    r|c S t          |           )zJ
    Find the first checker factory that supports the given authType.
    )r%   r   r   )r   factorys     r   findCheckerFactoryr(   `   sC     ())  x''NNN (
(
#
##r   c                     d| v r|                      dd          \  }}n| }d}t          |                              |          S )z
    Returns an L{twisted.cred.checkers.ICredentialsChecker} based on the
    contents of a descriptive string. Similar to
    L{twisted.application.strports}.
    :    )splitr(   r   )descriptionr   r   s      r   makeCheckerr/   j   sQ     k)//Q77))	h''77	BBBr   c                   ~    e Zd ZU dZdZeeee                           e	d<   e
j        Zd Zd Zd Zd Zd Zd	 Zd
 ZdS )AuthOptionMixinak  
    Defines helper methods that can be added on to any
    L{usage.Options} subclass that needs authentication.

    This mixin implements three new options methods:

    The opt_auth method (--auth) will write two new values to the
    'self' dictionary: C{credInterfaces} (a dict of lists) and
    C{credCheckers} (a list).

    The opt_help_auth method (--help-auth) will search for all
    available checker plugins and list them for the user; it will exit
    when finished.

    The opt_help_auth_type method (--help-auth-type) will display
    detailed help for a particular checker plugin.

    @cvar supportedInterfaces: An iterable object that returns
       credential interfaces which this application is able to support.

    @cvar authOutput: A writeable object to which this options class
        will send all help-related output. Default: L{sys.stdout}
    NsupportedInterfacesc                 &    | j         du p|| j         v S )zR
        Returns whether a particular credentials interface is supported.
        N)r2   )self	interfaces     r   supportsInterfacez!AuthOptionMixin.supportsInterface   s     '4/X9@X3XXr   c                 J    |j         D ]}|                     |          r dS dS )z
        Returns whether a checker factory will provide at least one of
        the credentials interfaces that we care about.
        TF)r   r6   r4   r'   r5   s      r   supportsCheckerFactoryz&AuthOptionMixin.supportsCheckerFactory   s=    
 !5 	 	I%%i00 ttur   c                 ~   g }| j         |j        }n4|j        D ],}|                     |          r|                    |           -|st	          |j                  d| vri | d<   d| vrg | d<   | d                             |           |D ]1}| d                             |g                               |           2dS )zM
        Supply a supplied credentials checker to the Options class.
        NcredInterfacescredCheckers)r2   r   r6   appendr#   
setdefault)r4   checker	supportedr5   s       r   
addCheckerzAuthOptionMixin.addChecker   s   
 	#+4II$9 0 0	)))44 0$$Y/// 	F'(DEEE4''%'D!"%%#%D ^##G,,," 	M 	MI!"--i<<CCGLLLL	M 	Mr   c                 Z   	 |                      t          |                     dS # t          $ r'}t          j        d|j        d         z            d}~wt          $ r'}t          j        d|j        d         z            d}~wt          $ r}t          j        d|z            d}~ww xY w)zB
        Specify an authentication method for the server.
        zAuth plugin not supported: %sr   NzAuth plugin not recognized: %szUnexpected error: %s)rA   r/   r#   r	   
UsageErrorargsr   	Exception)r4   r.   es      r   opt_authzAuthOptionMixin.opt_auth   s    	?OOK4455555$ 	P 	P 	P"#BQVAY#NOOO 	Q 	Q 	Q"#CafQi#OPPP 	? 	? 	?"#9A#=>>>	?s,   "& 
B*"AB*"BB*B%%B*c              #   v   K   t                      D ]'}|j        D ]}|                     |          r|V   n(dS )z
        Return a list of which authTypes will be displayed by --help-auth.
        This makes it a lot easier to test this module.
        N)r%   r   r6   r8   s      r   _checkerFactoriesForOptHelpAuthz/AuthOptionMixin._checkerFactoriesForOptHelpAuth   sc      
 ,-- 	 	G$9  	)))44 !MMME	 	r   c                 x   | j                             d           | j                             d           | j                             d           d}|                                 D ].}t          |j                  |k    rt          |j                  }/d|z  }| j                             |dz             | j                             |dz             |                                 D ]+}| j                             ||j        |j        fz             ,| j                             d           t          d          )z<
        Show all authentication methods available.
        z#Usage: --auth AuthType[:ArgString]
z-For detailed help: --help-auth-type AuthType

r   z  %%-%is	%%s
)AuthTypezArgString format)z========z================)
authOutputwriterI   lenr   r   
SystemExit)r4   firstLengthr'   formatStrings       r   opt_help_authzAuthOptionMixin.opt_help_auth   sB    	DEEENOOOd###;;== 	4 	4G7#$${22!'"233(;6l-MMNNNl-MMNNN;;== 	 	GO!! 0'2IJJ    	d###mmr   c                    	 t          |          }n%# t          $ r t          j        d|z            w xY w| j                            d|z             | j                            d|j        z             | j                            d           |j                                        	                                D ]1}| j                            d|
                                z             2| j                            d           |                     |          s<| j                            dt          z             | j                            d           t          d          )zA
        Show help for a particular authentication type.
        zInvalid auth type: %szUsage: --auth %s[:ArgString]
zArgString format: %s
rK   z  %s
r   )r(   r   r	   rC   rM   rN   r   r   strip
splitlinesrstripr9   notSupportedWarningrP   )r4   r   cflines       r   opt_help_auth_typez"AuthOptionMixin.opt_help_auth_type   sW   	G#H--BB 	G 	G 	G"#:X#EFFF	G>IJJJ69KKLLLd###K%%''2244 	< 	<DO!!(T[[]]":;;;;d###**2.. 	(O!!(-@"@AAAO!!$'''mms    "4)r   r   r   r   r2   r   r   r   r   __annotations__sysstdoutrM   r6   r9   rA   rG   rI   rS   r[   r   r   r   r1   r1   x   s          0 @D(4	?";<CCCJY Y Y  M M M.? ? ?	 	 	  ,    r   r1   )r   r]   typingr   r   r   zope.interfacer   r   twisted.pluginr   twisted.pythonr	   r   rE   r   r   r!   r#   rX   r%   r(   r/   r1   r   r   r   <module>rc      s    


 + + + + + + + + + + / / / / / / / / % % % % % %                i   <    y       &        0       ,    X ' ' '$ $ $C C CB B B B B B B B B Br   