
    (Xc                        d dl Z d dlZd dlZd dlZd dlmZ ej                  rd dl	m
Z
 dedej                  ej                     fdZ	 ddedej                  e   defdZd	adefd
ZdeddfdZdej(                  ej*                  eef   ej*                  eef   f   dej(                  eef   fdZej                  dej0                  dddej2                  dej2                  dej                  e   f
d       Zej                  dej0                  dddej2                  dej2                  dej2                  f
d       Z G d de      Zy)    N)GSSError)SecurityContextnamereturnc                     	 dj                  |       }t        |       t        j                  |   S # t        $ r Y yw xY w)aa  Import a GSSAPI extension module

    This method imports a GSSAPI extension module based
    on the name of the extension (not including the
    'ext_' prefix).  If the extension is not available,
    the method retuns None.

    Args:
        name (str): the name of the extension

    Returns:
        module: Either the extension module or None
    zgssapi.raw.ext_{0}N)format
__import__sysmodulesImportError)r   paths     //usr/lib/python3/dist-packages/gssapi/_utils.pyimport_gssapi_extensionr      s@    "#**404{{4   s   .1 	==docc                 N     dddt         j                  f fd}t        ||      S )a<  Creates a property based on an inquire result

    This method creates a property that calls the
    :python:`_inquire` method, and return the value of the
    requested information.

    Args:
        name (str): the name of the 'inquire' result information

    Returns:
        property: the created property
    selfr   r   c                 z    | j                   sd d}t        |      t         | j                  di di      S )NzCannot read zF from a security context whose establishment has not yet been started.T )_startedAttributeErrorgetattr_inquire)r   msgr   s     r   inquire_propertyz*inquire_property.<locals>.inquire_property7   sG    }}!$ (= =C %%}t}}4d|4d;;    )r   )tAnyproperty)r   r   r   s   `  r   r   r   &   s+    "<0 <QUU < $#..r   zUTF-8c                      t         S )zGets the current encoding used for strings.

    This value is used to encode and decode string
    values like names.

    Returns:
        str: the current encoding
    	_ENCODINGr   r   r   _get_encodingr"   F   s
     r   encc                     | a y)zSets the current encoding used for strings

    This value is used to encode and decode string
    values like names.

    Args:
        enc: the encoding to use
    Nr    )r#   s    r   set_encodingr%   R   s	     Ir   dc                     dt         j                  t        t        f   dt        fd}| j	                         D ci c]  \  }} ||       ||       c}}S c c}}w )z&Encodes any relevant strings in a dictxr   c                 P    t        | t              r| j                  t              S | S N)
isinstancestrencoder!   )r(   s    r   r#   z_encode_dict.<locals>.encf   s     a88I&&Hr   )r   Unionbytesr,   items)r&   r#   kvs       r   _encode_dictr3   b   sN    qwwucz" u  ()wwy1tq!CFCFN111s   Afuncr   r   argskwargsc                     	  | |g|i |S # t         $ r`}t        |dd      }|j                  A|r?||_        |j                  j
                  }||j                  _        |j                  cY d}~S  d}~ww xY w)a  Optionally defer exceptions and return a token instead

    When `__DEFER_STEP_ERRORS__` is set on the implementing class
    or instance, methods wrapped with this wrapper will
    catch and save their :python:`GSSError` exceptions and
    instead return the result token attached to the exception.

    The exception can be later retrived through :python:`_last_err`
    (and :python:`_last_tb` when Python 2 is in use).
    __DEFER_STEP_ERRORS__FN)r   r   token	_last_err__traceback__tb_next)r4   r   r5   r6   edefer_step_errorstbs          r   catch_and_return_tokenr@   p   sw    $D*4*6** 
#D*A5I77#4DN((B+-DNN(77N
s!    	A7AA2+A71A22A7c                 d    |j                   	 |j                    | |g|i |S # d|_         w xY w)zCheck and raise deferred errors before running the function

    This method checks :python:`_last_err` before running the wrapped
    function.  If present and not None, the exception will be raised
    with its original traceback.
    N)r:   )r4   r   r5   r6   s       r   check_last_errrB      s?     ~~!	"..  D*4*6** "DNs   & 	/c                        e Zd ZdZdedej                  ej                     dej                  eej                  f   dd f fdZ
 xZS )CheckLastErrorzCheck for a deferred error on all methods

    This metaclass applies the :python:`check_last_err` decorator
    to all methods not prefixed by '_'.

    Additionally, it enabled `__DEFER_STEP_ERRORS__` by default.
    r   parentsattrsr   c                     d|d<   |D ]9  }||   }t        |t        j                        s#|d   dk7  s,t        |      ||<   ; t        t
        |   | |||      S )NTr8   r   _)r+   typesFunctionTyperB   superrD   __new__)clsr   rE   rF   	attr_nameattr	__class__s         r   rL   zCheckLastError.__new__   ss     *.%& 	8I#D dE$6$67|s"#1$#7i 	8 ^S1#tWeLLr   )__name__
__module____qualname____doc__r,   r   TupleTypeDictr   rL   __classcell__)rP   s   @r   rD   rD      s[    MM M vvc155j!	M
 
M Mr   rD   r*   )r
   rI   typingr   	decoratordecogssapi.raw.miscr   TYPE_CHECKINGgssapi.sec_contextsr   r,   Optional
ModuleTyper   r   r   r!   r"   r%   rW   r.   r/   r3   Callabler   r@   rB   typerD   r   r   r   <module>rc      s   
    $??3
ZZ  !6  /
/	
C/ /: 		s 			 
2vvaggeSj!1775#:#667
2VVE5L
2 
**
 55 ee	
 ZZ @ +
**+
+ 55+ ee	+
 UU+ +,MT Mr   