
    (Xc8                         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mZ  ej                  d      Z ej                  d	      Z G d
 dej$                        Z G d de      Zy)    N)names)NameType)named_tuples)oids)_utils)MutableMappingIterablerfc6680rfc6680_comp_oidc                   \    e Zd ZdZdZ	 	 	 	 ddej                  ej                  ej                  e
ef      dej                  ej                     dej                  e
   dedd f
 fd	Z	 	 	 	 ddej                  ej                  ej                  e
ef      dej                  ej                     dej                  e
   deddf
d
ZdefdZdefdZde
fdZdej                  defdZedej                  ej                     fd       ZdedefdZdedefdZdefdZ	 d dede
fdZdej                  dd fdZd!dZdej<                  dd fdZdej@                  de!jD                  fdZ#edefd       Z$edej                  fd       Z%edej                  e&   fd       Z' xZ(S )"Namea  A GSSAPI Name

    This class represents a GSSAPI name which may be used with and/or returned
    by other GSSAPI methods.

    It inherits from the low-level GSSAPI :class:`~gssapi.raw.names.Name`
    class, and thus may used with both low-level and high-level API methods.

    This class may be pickled and unpickled, as well as copied.

    The :class:`str` and :class:`bytes` methods may be used to retrieve the
    text of the name.

    Note:
        Name strings will be automatically converted to and from unicode
        strings as appropriate.  If a method is listed as returning a
        :class:`str` object, it will return a unicode string.

        The encoding used will be python-gssapi's current encoding, which
        defaults to UTF-8.
    	_attr_objNbase	name_typetoken	compositereturnc                    ||rt         t        d      t        }t        j                  |t
        j                        }t        j                  |d      }|j                  t
        j                  k(  rt        j                  |t
        j                        }nt        j                  |t
        j                        }nt        j                  |t
        j                        }nft        |t        j                        r|}nIt        |t              r#|j                  t        j                               }t        j                  ||      }t!        j"                  dt$        t        | O  | |            S )NSYour GSSAPI implementation does not support RFC 6680 (the GSSAPI naming extensions)Tr   r   )rname_rfc6680NotImplementedErrorrname_rfc6680_comp_oidrnameimport_namer   composite_exportdisplay_namer   export
isinstancer   strencoder   _get_encodingtcastsuper__new__)clsr   r   r   r   	base_name
displ_name	__class__s          ./usr/lib/python3/dist-packages/gssapi/names.pyr&   zName.__new__)   s!     (-9: : *5 % 1 1%2:2K2K!MI!&!3!3I!NJ!++x/H/HH
 %*$5$5eX__$M	
 !& 1 1% II!--eX__E	ejj)I$${{6#7#7#9:))I vvfeD#6sIFGG    c                 D    |  t         t        |       | _        yd| _        y)a  
        The constructor can be used to "import" a name from a human readable
        representation, or from a token, and can also be used to convert a
        low-level :class:`gssapi.raw.names.Name` object into a high-level
        object.

        If a :class:`~gssapi.raw.names.Name` object from the low-level API
        is passed as the `base` argument, it will be converted into a
        high-level object.

        If the `token` argument is used, the name will be imported using
        the token.  If the token was exported as a composite token,
        pass `composite=True`.

        Otherwise, a new name will be created, using the `base` argument as
        the human-readable string and the `name_type` argument to denote the
        name type.

        Raises:
            ~gssapi.exceptions.BadNameTypeError
            ~gssapi.exceptions.BadNameError
            ~gssapi.exceptions.BadMechanismError
        N)r   _NameAttributeMappingr   )selfr   r   r   r   s        r+   __init__zName.__init__T   s     > 	$248DN!DNr,   c                 Z    t        |       j                  t        j                               S N)bytesdecoder   r"   r/   s    r+   __str__zName.__str__z   s     T{!!&"6"6"899r,   c                 d    | j                         j                  t        j                               S r2   )	__bytes__r4   r   r"   r5   s    r+   __unicode__zName.__unicode__}   s#    ~~&&v';';'=>>r,   c                 D    t        j                  | d      j                  S )NFr   )r   r   namer5   s    r+   r8   zName.__bytes__   s    !!$%8===r,   c                     t         t        d      t         j                  | |      j                  t	        j
                               S )a  
        Display this name as the given name type.

        This method attempts to display the current :class:`Name`
        using the syntax of the given :class:`~gssapi.raw.types.NameType`, if
        possible.

        Warning:

            In MIT krb5 versions below 1.13.3, this method can segfault if
            the name was not *originally* created with a `name_type` that was
            not ``None`` (even in cases when a ``name_type``
            is later "added", such as via :meth:`canonicalize`).
            **Do not use this method unless you are sure the above
            conditions can never happen in your code.**

        Warning:

            In addition to the above warning, current versions of MIT krb5 do
            not actually fully implement this method, and it may return
            incorrect results in the case of canonicalized names.

        :requires-ext:`rfc6680`

        Args:
            name_type (~gssapi.OID): the :class:`~gssapi.raw.types.NameType` to
                use to display the given name

        Returns:
            str: the displayed name

        Raises:
            ~gssapi.exceptions.OperationUnavailableError
        r   )r   r   display_name_extr4   r   r"   )r/   r   s     r+   
display_aszName.display_as   sK    N  % '4 5 5 --dI>EE  "$ 	$r,   c                 D    t        j                  | d      j                  S )z4The :class:`~gssapi.raw.types.NameType` of this nameTr   )r   r   r   r5   s    r+   r   zName.name_type   s     !!$$7AAAr,   otherc                 n    t        |t        j                        st        S t        j                  | |      S r2   )r   r   r   NotImplementedcompare_namer/   r@   s     r+   __eq__zName.__eq__   s-     %, "!%%dE22r,   c                 &    | j                  |       S r2   )rE   rD   s     r+   __ne__zName.__ne__   s     ;;u%%%r,   c                 ~    t        j                  | d      }dj                  |j                  |j                        S )NTr   zName({name!r}, {name_type}))r;   r   )r   r   formatr;   r   )r/   disp_ress     r+   __repr__zName.__repr__   s;    %%dd;,33(*<*< 4 > 	>r,   c                 |    |r&t         t        d      t         j                  |       S t        j                  |       S )a  Export this name as a token.

        This method exports the name into a byte string which can then be
        imported by using the `token` argument of the constructor.

        Args:
            composite (bool): whether or not use to a composite token --
                :requires-ext:`rfc6680`

        Returns:
            bytes: the exported name in token form

        Raises:
            ~gssapi.exceptions.MechanismNameRequiredError
            ~gssapi.exceptions.BadNameTypeError
            ~gssapi.exceptions.BadNameError
        r   )r   r   export_name_compositer   export_name)r/   r   s     r+   r   zName.export   sE    , $) +? @ @ !66t<<$$T**r,   mechc                 L     t        |       t        j                  | |            S )a  Canonicalize a name with respect to a mechanism.

        This method returns a new :class:`Name` that is canonicalized according
        to the given mechanism.

        Args:
            mech (~gssapi.OID): the :class:`MechType` to use

        Returns:
            Name: the canonicalized name

        Raises:
            ~gssapi.exceptions.BadMechanismError
            ~gssapi.exceptions.BadNameTypeError
            ~gssapi.exceptions.BadNameError
        )typer   canonicalize_name)r/   rO   s     r+   canonicalizezName.canonicalize   s"    * tDz%11$=>>r,   c                 J     t        |       t        j                  |             S r2   rQ   r   duplicate_namer5   s    r+   __copy__zName.__copy__  s    tDz%..t455r,   memoc                 J     t        |       t        j                  |             S r2   rU   )r/   rX   s     r+   __deepcopy__zName.__deepcopy__  s      tDz%..t455r,   kwargsc                     t         t        d      |sd}nd}|j                  d|      }|j                  d|      }t         j                  | ||      S )a  Inspect this name for information.

        This method inspects the name for information.

        If no keyword arguments are passed, all available information
        is returned.  Otherwise, only the keyword arguments that
        are passed and set to `True` are returned.

        Args:
            mech_name (bool): get whether this is a mechanism name,
                and, if so, the associated mechanism
            attrs (bool): get the attributes names for this name

        Returns:
            InquireNameResult: the results of the inquiry, with unused
                fields set to None

        Raises:
            ~gssapi.exceptions.GSSError
        r   TFattrs	mech_name)r^   r]   )r   r   getinquire_name)r/   r[   default_valr]   r^   s        r+   _inquirezName._inquire  sj    2  % '4 5 5 KK

7K0JJ{K8	))$)05 * 7 	7r,   c                 :    | j                  d      j                  S )zWWhether or not this name is a mechanism name
        (:requires-ext:`rfc6680`)
        Tr^   )rb   is_mech_namer5   s    r+   re   zName.is_mech_name7  s    
 }}t},999r,   c                 :    | j                  d      j                  S )zJThe mechanism associated with this name (:requires-ext:`rfc6680`)
        Trd   )rb   rO   r5   s    r+   rO   z	Name.mech>  s     }}t},111r,   c                 H    | j                   t        d      | j                   S )a  The attributes of this name (:requires-ext:`rfc6680`)

        The attributes are presenting in the form of a
        :class:`~collections.abc.MutableMapping` (a dict-like object).

        Retrieved values will always be in the form of :class:`frozenset`.

        When assigning values, if iterables are used, they be considered to be
        the set of values for the given attribute.  If a non-iterable is used,
        it will be considered a single value, and automatically wrapped in an
        iterable.

        Note:
            String types (includes :class:`bytes`) are not considered to
            be iterables in this case.
        r   )r   r   r5   s    r+   
attributeszName.attributesD  s,    $ >>!% '4 5 5 ~~r,   )NNNF)F)r   r   ))__name__
__module____qualname____doc__	__slots__r#   OptionalUnionr   r   r3   r    roidsOIDboolr&   r0   r6   r9   r8   r>   propertyr   objectrE   rG   rK   r   rS   rW   DictrZ   AnytuplesInquireNameResultrb   re   rO   r   rh   __classcell__)r*   s   @r+   r   r      s   , I =A+/#')HjjUC!789)H ::eii()H zz% 	)H
 )H 
)HZ =A+/#'$"jjUC!789$" ::eii($" zz% 	$"
 $" 
$"L: :?S ?>5 >,$99,$ 
,$\ B1::eii0 B B	3	3 
	3&& 
&># >  ++ 
+@?ii? 
?.66ff6 
6'7%%'7 
	!	!'7R :d : : 2eii 2 2
 AJJ~6  r,   r   c                   F   e Zd ZdZdeddfdZdej                  ee	f   de
j                  fdZdej                  ee	f   dej                  e
j                  ej                  eef   ef   ddfd	Zdej                  ee	f   ddfd
Zdej"                  e   fdZdefdZy)r.   z6Provides dict-like access to RFC 6680 Name attributes.r;   r   Nc                     || _         y r2   )_name)r/   r;   s     r+   r0   z_NameAttributeMapping.__init__a  s     
r,   keyc                    t        |t              r#|j                  t        j                               }t
        j                  | j                  |      }t        j                  t        j                  |      }t        j                  t        |j                        t        |j                        |j                  |j                         S r2   )r   r    r!   r   r"   r   get_name_attributer|   r#   r$   rw   GetNameAttributeResultlistvaluesdisplay_valuesauthenticatedcomplete)r/   r}   ress      r+   __getitem__z!_NameAttributeMapping.__getitem__g  s     c3**V1134C..JJffV22C8,,T#**-=-1#2D2D-E-0->->-0\\; 	;r,   valuec                 `   t        |t              r#|j                  t        j                               }t
        j                  | j                  |       t        |t        j                        r|j                  }|j                  }n\t        |t              rJt        |      dk(  r<t        j                  t         |d         }t        j                  t"        |d         g}nd}t        |t        t"        f      st        |t$              s|g}t
        j'                  | j                  ||       y )N      r   F)r   )r   r    r!   r   r"   r   delete_name_attributer|   rw   r   r   r   tuplelenr#   r$   rr   r3   r	   set_name_attribute)r/   r}   r   r   
attr_values        r+   __setitem__z!_NameAttributeMapping.__setitem__w  s     c3**V1134C++JJ	 eV::;~~HJu%#e*/vvdE!H-H&&a12JHusEl+uh/  J((JJZ( 	) 	<r,   c                     t        |t              r#|j                  t        j                               }t
        j                  | j                  |       y r2   )r   r    r!   r   r"   r   r   r|   )r/   r}   s     r+   __delitem__z!_NameAttributeMapping.__delitem__  s<     c3**V1134C++JJ	r,   c                 `    t        | j                  j                  d      j                        S NT)r]   )iterr|   rb   r]   r5   s    r+   __iter__z_NameAttributeMapping.__iter__  s%    DJJ''d'399::r,   c                 `    t        | j                  j                  d      j                        S r   )r   r|   rb   r]   r5   s    r+   __len__z_NameAttributeMapping.__len__  s%    4::&&T&28899r,   )ri   rj   rk   rl   r   r0   r#   ro   r3   r    rw   r   r   Tuplerr   r   r   Iteratorr   intr    r,   r+   r.   r.   ^  s    @ 
;WWUCZ ; 
	&	&; <WWUCZ < ww))1775$;+?F
< 
<@WWUCZ  
;!**U+ ;: :r,   r.   )typingr#   
gssapi.rawr   r   r   r   rw   r   rp   gssapir   collections.abcr   r	   import_gssapi_extensionr   r   r   r.   r   r,   r+   <module>r      sa     %  - $  4...y97778JK K5:: K\
G:N G:r,   