ó
[³XMc           @   sî   d  Z  d d l Z d d l m Z m Z d d l m Z d d l m Z d e f d „  ƒ  YZ	 d e
 f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d Z d „  Z d „  Z d „  Z d d d „  ƒ  YZ d S(   s¨   
Support for resolving command-line strings that represent different
checkers available to cred.

Examples:
 - passwd:/etc/passwd
 - memory:admin:asdf:user:lkj
 - unix
iÿÿÿÿN(   t	   Interfacet	   Attribute(   t
   getPlugins(   t   usaget   ICheckerFactoryc           B   sG   e  Z d  Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z d „  Z RS(   sš   
    A factory for objects which provide
    L{twisted.cred.checkers.ICredentialsChecker}.

    It's implemented by twistd plugins creating checkers.
    s0   A tag that identifies the authentication method.sm   A detailed (potentially multi-line) description of precisely what functionality this CheckerFactory provides.s=   A short (one-line) description of the argument string format.s@   A list of credentials interfaces that this factory will support.c         C   s   d S(   sf   
        Return an L{ICredentialChecker} provider using the supplied
        argument string.
        N(    (   t	   argstring(    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyt   generateChecker3   s    (	   t   __name__t
   __module__t   __doc__R   t   authTypet   authHelpt   argStringFormatt   credentialInterfacesR   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyR      s   				t   StrcredExceptionc           B   s   e  Z d  Z RS(   s+   
    Base exception class for strcred.
    (   R   R   R	   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyR   ;   s   t   InvalidAuthTypec           B   s   e  Z d  Z RS(   sv   
    Raised when a user provides an invalid identifier for the
    authentication plugin (known as the authType).
    (   R   R   R	   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyR   B   s   t   InvalidAuthArgumentStringc           B   s   e  Z d  Z RS(   sl   
    Raised by an authentication plugin when the argument string
    provided is formatted incorrectly.
    (   R   R   R	   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyR   J   s   t   UnsupportedInterfacesc           B   s   e  Z d  Z RS(   s“   
    Raised when an application is given a checker to use that does not
    provide any of the application's supported credentials interfaces.
    (   R   R   R	   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyR   R   s   s<   WARNING: This authType is not supported by this application.c           C   s
   t  t ƒ S(   s=   
    Find all objects that implement L{ICheckerFactory}.
    (   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyt   findCheckerFactoriesa   s    c         C   s7   x$ t  ƒ  D] } | j |  k r
 | Sq
 Wt |  ƒ ‚ d S(   sJ   
    Find the first checker factory that supports the given authType.
    N(   R   R
   R   (   R
   t   factory(    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyt   findCheckerFactoryi   s    c         C   sF   d |  k r' |  j  d d ƒ \ } } n |  } d } t | ƒ j | ƒ S(   s¤   
    Returns an L{twisted.cred.checkers.ICredentialsChecker} based on the
    contents of a descriptive string. Similar to
    L{twisted.application.strports}.
    t   :i   t    (   t   splitR   R   (   t   descriptionR
   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyt   makeCheckert   s
    t   AuthOptionMixinc           B   s\   e  Z d  Z d Z e j Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z RS(	   sk  
    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}
    c         C   s   |  j  d k p | |  j  k S(   sR   
        Returns whether a particular credentials interface is supported.
        N(   t   supportedInterfacest   None(   t   selft	   interface(    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyt   supportsInterface    s    c         C   s+   x$ | j  D] } |  j | ƒ r
 t Sq
 Wt S(   s‡   
        Returns whether a checker factory will provide at least one of
        the credentials interfaces that we care about.
        (   R   R   t   Truet   False(   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyt   supportsCheckerFactory¨   s    c         C   sá   g  } |  j  d k r! | j } n3 x0 | j D]% } |  j | ƒ r+ | j | ƒ q+ q+ W| sl t | j ƒ ‚ n  d |  k r… i  |  d <n  d |  k rž g  |  d <n  |  d j | ƒ x+ | D]# } |  d j | g  ƒ j | ƒ q¶ Wd S(   sM   
        Supply a supplied credentials checker to the Options class.
        t   credInterfacest   credCheckersN(   R   R   R   R   t   appendR   t
   setdefault(   R   t   checkert	   supportedR   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyt
   addChecker³   s    c         C   sœ   y |  j  t | ƒ ƒ Wn~ t k
 rF } t j d | j d ƒ ‚ nR t k
 rr } t j d | j d ƒ ‚ n& t k
 r— } t j d | ƒ ‚ n Xd S(   sB   
        Specify an authentication method for the server.
        s   Auth plugin not supported: %si    s   Auth plugin not recognized: %ss   Unexpected error: %sN(   R)   R   R   R   t
   UsageErrort   argsR   t	   Exception(   R   R   t   e(    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyt   opt_authË   s    c         c   sD   x= t  ƒ  D]2 } x) | j D] } |  j | ƒ r | VPq q Wq
 Wd S(   sŒ   
        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   R   (   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyt   _checkerFactoriesForOptHelpAuthÛ   s
    c         C   sý   |  j  j d ƒ |  j  j d ƒ |  j  j d ƒ d } x; |  j ƒ  D]- } t | j ƒ | k rC t | j ƒ } qC qC Wd | } |  j  j | d ƒ |  j  j | d ƒ x4 |  j ƒ  D]& } |  j  j | | j | j f ƒ q³ W|  j  j d ƒ t d ƒ ‚ d
 S(   s<   
        Show all authentication methods available.
        s#   Usage: --auth AuthType[:ArgString]
s-   For detailed help: --help-auth-type AuthType
s   
i    s     %%-%is	%%s
t   AuthTypes   ArgString formats   ========s   ================N(   R0   s   ArgString format(   s   ========s   ================(   t
   authOutputt   writeR/   t   lenR
   R   t
   SystemExit(   R   t   firstLengthR   t   formatString(    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyt   opt_help_authç   s    
	c         C   s  y t  | ƒ } Wn$ t k
 r6 t j d | ƒ ‚ n X|  j j d | ƒ |  j j d | j ƒ |  j j d ƒ x7 | j j ƒ  j	 ƒ  D]  } |  j j d | j
 ƒ  ƒ qˆ W|  j j d ƒ |  j | ƒ sò |  j j d t ƒ |  j j d ƒ n  t d ƒ ‚ d S(   sA   
        Show help for a particular authentication type.
        s   Invalid auth type: %ss   Usage: --auth %s[:ArgString]
s   ArgString format: %s
s   
s     %s
i    N(   R   R   R   R*   R1   R2   R   R   t   stript
   splitlinest   rstripR"   t   notSupportedWarningR4   (   R   R
   t   cft   line(    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyt   opt_help_auth_typeý   s    N(   R   R   R	   R   R   t   syst   stdoutR1   R   R"   R)   R.   R/   R7   R>   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyR   ƒ   s   							(    (   R	   R?   t   zope.interfaceR    R   t   twisted.pluginR   t   twisted.pythonR   R   R,   R   R   R   R   R;   R   R   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/strcred.pyt   <module>   s   !
			