
    (Xc                         d dl Zd dlmZ d dlmZ d dlmZ d dlm	Z
 d dlmZ d dlmZ  ed      Z ed	      Z G d
 dej"                        Zy)    N)import_gssapi_extension)oids)misc)named_tuples)names)_utilsrfc5587rfc5801c                   z    e Zd ZdZ	 	 ddej
                  ej                     dej
                  e   dd f fdZ	e
dej                  ej                     fd       Ze
dej                  fd       Ze
dej                   fd       Zdefd	Zdefd
ZdefdZdefdZe
defd       Ze
defd       Ze
dej                  ej                     fd       Ze
dej                  ej                     fd       Zedej8                  d    fd       Zedej>                  dej8                  d    fd       Z e	 ddej
                  ejB                  eef      dd fd       Z"e	 	 	 ddej
                  ejB                  ej                  ejF                  ej                     f      dej
                  ejB                  ej                  ejF                  ej                     f      dej
                  ejB                  ej                  ejF                  ej                     f      dej8                  d    fd       Z$ xZ%S )	Mechanisma0  
    A GSSAPI Mechanism

    This class represents a mechanism and centralizes functions dealing with
    mechanisms and can be used with any calls.

    It inherits from the low-level GSSAPI :class:`~gssapi.raw.oids.OID` class,
    and thus can be used with both low-level and high-level API calls.
    cpyelementsreturnc                 V    t        j                  dt        t        |   | ||            S )Nr   )tcastsuperr   __new__)clsr   r   	__class__s      ./usr/lib/python3/dist-packages/gssapi/mechs.pyr   zMechanism.__new__   s-    
 vvkIs3ChGI 	I    c                 ,    t        j                  |       S )zH
        Get the set of name types supported by this mechanism.
        )rmiscinquire_names_for_mechselfs    r   
name_typeszMechanism.name_types    s    
 ++D11r   c                 N    t         t        d      t         j                  |       S )N=Your GSSAPI implementation does not have support for RFC 5801)r
   NotImplementedErrorinquire_saslname_for_mechr   s    r   	_saslnamezMechanism._saslname'   s-    ?% 'B C C0066r   c                 N    t         t        d      t         j                  |       S )N=Your GSSAPI implementation does not have support for RFC 5587)r	   r!   inquire_attrs_for_mechr   s    r   _attrszMechanism._attrs.   s/    ?% 'B C C --d33r   c                 d    | j                         j                  t        j                               S N_bytes_descdecoder   _get_encodingr   s    r   __str__zMechanism.__str__6   %    !(()=)=)?@@r   c                 d    | j                         j                  t        j                               S r)   r*   r   s    r   __unicode__zMechanism.__unicode__9   r/   r   c                     | j                   }t        8| j                  r,| j                  j                  r| j                  j                  }t	        |t
              r#|j                  t        j                               }|S r)   )	dotted_formr
   r#   	mech_name
isinstancestrencoder   r-   r   bases     r   r+   zMechanism._bytes_desc<   sZ    $($4$44>>dnn6N6N>>++DdC ;;v3356Dr   c                     d| j                   z  }t        6d| j                  j                  j	                  d      d| j                   d}|S )zL
        Get a name representing the mechanism; always safe to call
        z<Mechanism (%s)>z<Mechanism UTF-8z (z)>)r3   r
   r#   r4   r,   r8   s     r   __repr__zMechanism.__repr__F   sI     "D$4$44((//8  D
 r   c                 L    | j                   j                  j                  d      S )zV
        Get the SASL name for the mechanism

        :requires-ext:`rfc5801`
        r;   )r#   sasl_mech_namer,   r   s    r   	sasl_namezMechanism.sasl_nameS   s     ~~,,33G<<r   c                 L    | j                   j                  j                  d      S )zW
        Get the description of the mechanism

        :requires-ext:`rfc5801`
        r;   )r#   mech_descriptionr,   r   s    r   descriptionzMechanism.description\   s     ~~..55g>>r   c                 .    | j                   j                  S )z
        Get the known attributes of the mechanism; returns a set of OIDs
        ([OID])

        :requires-ext:`rfc5587`
        )r'   known_mech_attrsr   s    r   known_attrszMechanism.known_attrse   s     {{+++r   c                 .    | j                   j                  S )zu
        Get the attributes of the mechanism; returns a set of OIDs ([OID])

        :requires-ext:`rfc5587`
        )r'   
mech_attrsr   s    r   attrszMechanism.attrso   s     {{%%%r   c                 >      fdt        j                         D        S )zG
        Get a generator of all mechanisms supported by GSSAPI
        c              3   .   K   | ]  } |        y wr)    .0mechr   s     r   	<genexpr>z&Mechanism.all_mechs.<locals>.<genexpr>}   s     =dD	=   )r   indicate_mechs)r   s   `r   	all_mechszMechanism.all_mechsx   s    
 >e&:&:&<==r   namec                 @      fdt        j                  |      D        S )a2  
        Get a generator of mechanisms that may be able to process the name

        Args:
            name (~gssapi.names.Name): a name to inquire about

        Returns:
            [Mechanism]: a set of mechanisms which support this name

        Raises:
            ~gssapi.exceptions.GSSError
        c              3   .   K   | ]  } |        y wr)   rK   rL   s     r   rO   z&Mechanism.from_name.<locals>.<genexpr>   s     IdD	IrP   )r   inquire_mechs_for_name)r   rS   s   ` r   	from_namezMechanism.from_name   s    " Je&B&B4&HIIr   c                     t         t        d      t        |t              r#|j	                  t        j                               }t         j                  |      } | |      S )a  
        Create a Mechanism from its SASL name

        Args:
            name (str): SASL name of the desired mechanism

        Returns:
            Mechanism: the desired mechanism

        Raises:
            ~gssapi.exceptions.GSSError

        :requires-ext:`rfc5801`
        r    )r
   r!   r5   r6   r7   r   r-   inquire_mech_for_saslname)r   rS   ms      r   from_sasl_namezMechanism.from_sasl_name   sX    & ?% 'B C CdC ;;v3356D--d31vr   desired_attrsexcept_attrscritical_attrsc                 N    t        |t        j                        rt        |g      }t        |t        j                        rt        |g      }t        |t        j                        rt        |g      }t        t        d      t        j                  |||      } fd|D        S )a  
        Get a generator of mechanisms supporting the specified attributes. See
        RFC 5587's :func:`indicate_mechs_by_attrs` for more information.

        Args:
            desired_attrs ([OID]): Desired attributes
            except_attrs ([OID]): Except attributes
            critical_attrs ([OID]): Critical attributes

        Returns:
            [Mechanism]: A set of mechanisms having the desired features.

        Raises:
            ~gssapi.exceptions.GSSError

        :requires-ext:`rfc5587`
        r%   c              3   .   K   | ]  } |        y wr)   rK   rL   s     r   rO   z'Mechanism.from_attrs.<locals>.<genexpr>   s     ,dD	,rP   )r5   roidsOIDsetr	   r!   indicate_mechs_by_attrs)r   r\   r]   r^   mechss   `    r   
from_attrszMechanism.from_attrs   s    < mUYY/0MlEII.~.Lneii0 .!12N?% 'B C C //0<0>@ -e,,r   )NNr)   )NNN)&__name__
__module____qualname____doc__r   Optionalra   rb   bytesr   propertySetr   tuplesInquireSASLNameResultr#   InquireAttrsResultr'   r6   r.   r1   r+   r<   r?   rB   rE   rH   classmethodIteratorrR   rnamesNamerW   Unionr[   Iterablerf   __classcell__)r   s   @r   r   r      s    &*&*IZZ		"I **U#I 
	I 2AEE%)), 2 2 7677 7 7 411 4 4A AAS AU #  =3 = = ?S ? ? ,QUU599- , , &quuUYY' & & >!**[1 > > JkkJ 
K	 J J$  15jj,- 
 8 
   +-zzGGEIIqzz%))445
+-
 jjGGEIIqzz%))445
+- 

GGEIIqzz%))445
+- 
K	 +- +-r   r   )typingr   gssapi._utilsr   
gssapi.rawr   ra   r   r   r   ro   r   rt   gssapir   r	   r
   rb   r   rK   r   r   <module>r}      s@     1 $ $ - & 
!)
,
!)
,M-		 M-r   