
    )JfX                        d Z g dZddlZddlZddlZddlZddlmZ ddlm	Z	 	  ej
                    Zn# e$ r dZY nw xY wdZdZdZd	ZeefZd
Z ej        d          Z ej        d          Z ej        d          ZdZg dZ G d de          Z G d de          Z e            Zi a G d de          Z d Z! G d de          Z" G d de          Z#dS )z#Extension argument processing code
)
MessageNamespaceMap
no_defaultregisterNamespaceAlias	OPENID_NSBARE_NS
OPENID1_NS
OPENID2_NSSREG_URIIDENTIFIER_SELECT    N)oidutil)kvformz2http://specs.openid.net/auth/2.0/identifier_selectzhttp://openid.net/sreg/1.0zhttp://openid.net/signon/1.0zhttp://openid.net/signon/1.1z http://specs.openid.net/auth/2.0zNull namespacezOpenID namespacezBare namespacei  )nsmodeerror	return_tocontact	referencesigned
assoc_typesession_type
dh_modulusdh_gendh_consumer_public
claimed_ididentityrealminvalidate_handleop_endpointresponse_noncesigassoc_handle
trust_rootopenidc                       e Zd ZdZdS )UndefinedOpenIDNamespaceznRaised if the generic OpenID namespace is accessed when there
    is no OpenID namespace set for this message.N__name__
__module____qualname____doc__     Q/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/openid/message.pyr&   r&   Q   s        4 4 4 4r-   r&   c                       e Zd ZdZd ZdS )InvalidOpenIDNamespacezxRaised if openid.ns is not a recognized value.

    For recognized values, see L{Message.allowed_openid_namespaces}
    c                 >    d}| j         r|d| j         d         z  }|S )NzInvalid OpenID Namespace r   args)selfss     r.   __str__zInvalidOpenIDNamespace.__str__\   s-    &9 	*A$)A,,))Ar-   N)r(   r)   r*   r+   r7   r,   r-   r.   r0   r0   V   s-         
    r-   r0   c                       e Zd ZdZdS )NamespaceAliasRegistrationErrorzL
    Raised when an alias or namespace URI has already been registered.
    Nr'   r,   r-   r.   r9   r9   l   s          	Dr-   r9   c                    t                               |          | k    rdS | t          t                                                     v rt	          d| d          |t           v rt	          d|d          | t           |<   dS )a:  
    Registers a (namespace URI, alias) mapping in a global namespace
    alias map.  Raises NamespaceAliasRegistrationError if either the
    namespace URI or alias has already been registered with a
    different value.  This function is required if you want to use a
    namespace with an OpenID 1 message.
    NzNamespace uri z already registeredzAlias )registered_aliasesgetlistvaluesr9   )namespace_urialiass     r.   r   r   s   s     e$$55/66889999--5B]]EG G 	G """--/4uu/8 9 9 	9 !.ur-   c                      e Zd ZdZeeegZd!dZe	d             Z
e	d             Zd Zd Zd Zd	 Zd
 Zd Zd Z e	e          Zd Zd Zd Z	 	 d"dZd Zd Zd Zd Zd Zd Zd!dZd Zd Zd Z d Z!d Z"d Z#d Z$d!d Z%dS )#r   a  
    In the implementation of this object, None represents the global
    namespace as well as a namespace with no key.

    @cvar namespaces: A dictionary specifying specific
        namespace-URI to alias mappings that should be used when
        generating namespace aliases.

    @ivar ns_args: two-level dictionary of the values in this message,
        grouped by namespace URI. The first level is the namespace
        URI.
    Nc                     i | _         t                      | _        |	d| _        dS |t          v }|                     ||           dS )zCreate an empty Message.

        @raises InvalidOpenIDNamespace: if openid_namespace is not in
            L{Message.allowed_openid_namespaces}
        N)r4   r   
namespaces_openid_ns_uriOPENID1_NAMESPACESsetOpenIDNamespace)r5   openid_namespaceimplicits      r.   __init__zMessage.__init__   sR     	&..#"&D'+==H##$4h?????r-   c                 ^    |             }i }|                                 D ]v\  }}t          |t                    rt          d|          	 |                    dd          \  }}n# t
          $ r d}Y nw xY w|dk    r||j        t          |f<   q|||<   w|                    |           |S )zAConstruct a Message containing a set of POST arguments.

        zLquery dict must have one value for each key, not lists of values.  Query is .   Nr$   )	items
isinstancer=   	TypeErrorsplit
ValueErrorr4   r   _fromOpenIDArgs)clsr4   r5   openid_argskeyvalueprefixrests           r.   fromPostArgszMessage.fromPostArgs   s    
 suu **,, 	* 	*JC%&& PiGKt!O P P P"yya00    !!,1	7C.))$)D!![)))s   A((A76A7c                 D     |             }|                     |           |S )zConstruct a Message from a parsed KVForm message.

        @raises InvalidOpenIDNamespace: if openid.ns is not in
            L{Message.allowed_openid_namespaces}
        )rR   )rS   rT   r5   s      r.   fromOpenIDArgszMessage.fromOpenIDArgs   s(     suu[)))r-   c                    g }|                                 D ]\  }}	 |                    dd          \  }}n# t          $ r t          }|}Y nw xY w|dk    r| j                            ||           [|t          k    r|dk    r|                     |d           |                    |||f           |                                 s|                     t          d           |D ]\  }}}| j        
                    |          }|P|                     |          }||                                 }|d|}n| j                            ||d           |                     |||           d S )NrK   rL   r   FT)rH   )rM   rP   rQ   NULL_NAMESPACErC   addAliasrF   appendgetOpenIDNamespacer   getNamespaceURI_getDefaultNamespacesetArg)r5   rT   ns_argsrX   rV   ns_aliasns_keyns_uris           r.   rR   zMessage._fromOpenIDArgs   s    ',,.. 	: 	:KD%#'::c1#5#5 &&   ) 4((7777^++$''u5555&%89999 &&(( 	6##J555 *1 	/ 	/%Xvu_44X>>F~228<<>!4466F(0&&9FFO,,VX,MMMKK....	/ 	/s   7AAc                 b    |                                  rt                              |          S dS )zWOpenID 1 compatibility: look for a default namespace URI to
        use for this alias.N)	isOpenID1r;   r<   )r5   mystery_aliass     r.   rb   zMessage._getDefaultNamespace   s/     >> 	%))-8884r-   c                     t          |t                    rt          |d          }|| j        vrt	          |          | j                            |t          |           || _        dS )zSet the OpenID namespace URI used in this message.

        @raises InvalidOpenIDNamespace: if the namespace is not in
            L{Message.allowed_openid_namespaces}
        utf-8encodingN)	rN   bytesstrallowed_openid_namespacesr0   rC   r^   r]   rD   )r5   openid_ns_urirH   s      r.   rF   zMessage.setOpenIDNamespace   sm     mU++ 	A@@@M >>>(777  III+r-   c                     | j         S N)rD   r5   s    r.   r`   zMessage.getOpenIDNamespace  s    ""r-   c                 8    |                                  t          v S rt   )r`   rE   ru   s    r.   ri   zMessage.isOpenID1  s    &&((,>>>r-   c                 <    |                                  t          k    S rt   )r`   r	   ru   s    r.   	isOpenID2zMessage.isOpenID2  s    &&((J66r-   c                 P    |                      t          j        |                    S )z%Create a Message from a KVForm string)r[   r   kvToDict)rS   kvform_strings     r.   
fromKVFormzMessage.fromKVForm  s     !!&/-"@"@AAAr-   c                 *    t          j        |           S rt   )copydeepcopyru   s    r.   r~   zMessage.copy  s    }T"""r-   c                 p   i }| j                                         D ]J\  }}| j                             |          r |t          k    rd}nd|z   }t	          j        |          ||<   K| j                                        D ]5\  \  }}}|                     ||          }t	          j        |          ||<   6|S )zk
        Return all arguments with openid. in front of namespaced arguments.
        @return bytes
        z	openid.nsz
openid.ns.)rC   rM   
isImplicitr]   r   	toUnicoder4   getKey)r5   r4   rg   r@   rf   rV   rU   s          r.   
toPostArgszMessage.toPostArgs   s    
  "_2244 	5 	5MFE))&11 &&$%-",V44DLL'+y'8'8 	1 	1#VVe++ff--C)%00DIIr-   c                     |                                  }i }|                                D ]6\  }}|                    d          st          d          |||dd         <   7|S )zWReturn all namespaced arguments, failing if any
        non-namespaced arguments exist.openid.znThis message can only be encoded as a POST, because it contains arguments that are not prefixed with "openid."   N)r   rM   
startswithrQ   )r5   	post_argskvargskvs        r.   toArgszMessage.toArgs8  s~     OO%%	OO%% 	" 	"DAq<<	** " NO O O !"qur-   Continuec                    t           t          d          |J t                               d          }|r$|                                D ]\  }}||j        |<   t          j        |          |j        d<   d|j        d<   d|j        d<   d	|j        d
<   |                                                                 D ]]\  }}dt          j        |          t          j        |          d}|                    t                               d|                     ^t                               ddt          j        |          d          }	|                    |	           t          t           
                    |d          d          S )a:  Generate HTML form markup that contains the values in this
        message, to be HTTP POSTed as x-www-form-urlencoded UTF-8.

        @param action_url: The URL to which the form will be POSTed
        @type action_url: str

        @param form_tag_attrs: Dictionary of attributes to be added to
            the form tag. 'accept-charset' and 'enctype' have defaults
            that can be overridden. If a value is supplied for
            'action' or 'method', it will be replaced.
        @type form_tag_attrs: {unicode: unicode}

        @param submit_text: The text that will appear on the submit
            button for this form.
        @type submit_text: unicode

        @returns: A string containing (X)HTML markup for a form that
            encodes the values in this Message object.
        @rtype: str
        Nz#This function requires ElementTree.formactionpostmethodzUTF-8zaccept-charsetz!application/x-www-form-urlencodedenctypehidden)typenamerV   inputsubmit)r   rV   rl   rm   )ElementTreeRuntimeErrorElementrM   attribr   r   r   r_   rp   tostring)
r5   
action_urlform_tag_attrssubmit_textr   r   attrrV   attrsr   s
             r.   toFormMarkupzMessage.toFormMarkupH  s   0 DEEE%%%""6** 	),2244 ) )
d$(D!! ' 1* = =H &H(/$%!DI??,,2244 	= 	=KD% )$// *511 E
 KK++GU;;<<<<$$'446 67 7 	F;''w'??#% % % 	%r-   c                 P    t          j        ||                                           S )z\Generate a GET URL with the parameters in this message
        attached as query parameters.)r   
appendArgsr   )r5   base_urls     r.   toURLzMessage.toURL  s!     !(DOO,=,=>>>r-   c                 N    t          j        |                                           S )zGenerate a KVForm string that contains the parameters in
        this message. This will fail if the message contains arguments
        outside of the 'openid.' prefix.
        )r   dictToKVr   ru   s    r.   toKVFormzMessage.toKVForm  s    
 t{{}}---r-   c                     t          |                                                                           }t          j                            |          S )z#Generate an x-www-urlencoded string)sortedr   rM   urllibparse	urlencode)r5   r4   s     r.   toURLEncodedzMessage.toURLEncoded  s;    doo''--//00|%%d+++r-   c                    t          |t                    rt          |d          }|t          k    r| j        t          d          | j        }|t          k    r't          |t                    st          d|          |t          k    rVd|vrRd}t          j	        ||fz  t                     |dk    r,d	}t          j	        |t          fz  t                     t          S |S )
zConvert an input value into the internally used values of
        this object

        @param namespace: The string or constant to convert
        @type namespace: str or unicode or BARE_NS or OPENID_NS
        rl   rm   NzOpenID namespace not setz6Namespace must be BARE_NS, OPENID_NS or a string. got :z7OpenID 2.0 namespace identifiers SHOULD be URIs. Got %rsregz'Using %r instead of "sreg" as namespace)rN   ro   rp   r   rD   r&   r   rO   warningswarnDeprecationWarningr
   )r5   	namespacefmts      r.   _fixNSzMessage._fixNS  s     i'' 	9I888I	!!"*./IJJJ /	
9c(B(B)   Cy$8$8KCM#-/ABBBF""?8,&&* * *  r-   c                 B    |                      |          }||f| j        v S rt   r   r4   )r5   r   rf   s      r.   hasKeyzMessage.hasKey  s%    KK	**	6"di//r-   c                     |                      |          }|t          k    r|S | j                            |          }|dS |t          k    r|}n|d|}d|z   S )z0Get the key for a particular namespaced argumentNrK   r   )r   r   rC   getAliasr]   )r5   r   rf   re   tails        r.   r   zMessage.getKey  sr    KK	**	M?++I66 4~%%DD&hh/D4r-   c                     |                      |          }||f}	 | j        |         S # t          $ r |t          u rt          ||f          |cY S w xY w)a  Get a value for a namespaced key.

        @param namespace: The namespace in the message for this key
        @type namespace: str

        @param key: The key to get within this namespace
        @type key: str

        @param default: The value to use if this key is absent from
            this message. Using the special value
            openid.message.no_default will result in this method
            raising a KeyError instead of returning the default.

        @rtype: str or the type of default
        @raises KeyError: if default is no_default
        @raises UndefinedOpenIDNamespace: if the message has not yet
            had an OpenID namespace set
        )r   r4   KeyErrorr   )r5   r   rU   defaultargs_keys        r.   getArgzMessage.getArg  ss    & KK	**	s#	9X&& 	 	 	*$$	3/000		s   ( &AAc                 p   |                      |          }g }| j                                        D ]w\  \  }}}||k    rit          |t                    rt          |d          }n|}t          |t                    rt          |d          }n|}|                    ||f           xt          |          S )zGet the arguments that are defined for this namespace URI

        @returns: mapping from namespaced keys to values
        @returntype: dict of {str:bytes}
        rl   rm   )r   r4   rM   rN   ro   rp   r_   dict)r5   r   r4   pair_nsrf   rV   r   r   s           r.   getArgszMessage.getArgs  s     KK	**	*.)//*;*; 
	$ 
	$&gv)##fe,, FW555AAAeU++ EG444AAAQF###Dzzr-   c                     |                      |          }|                                D ]\  }}|                     |||           dS )zSet multiple key/value pairs in one call

        @param updates: The values to set
        @type updates: {unicode:unicode}
        N)r   rM   rc   )r5   r   updatesr   r   s        r.   
updateArgszMessage.updateArgs  sS     KK	**	MMOO 	) 	)DAqKK	1a((((	) 	)r-   c                     |J |J |                      |          }t          |t                    rt          |d          }|| j        ||f<   |t
          ur| j                            |           dS dS )z'Set a single argument in this namespaceNrl   rm   )r   rN   ro   rp   r4   r   rC   add)r5   r   rU   rV   s       r.   rc   zMessage.setArg  s       KK	**	eU## 	1000E&+	9c"#W$$O	***** %$r-   c                 D    |                      |          }| j        ||f= d S rt   r   )r5   r   rU   s      r.   delArgzMessage.delArg  s(    KK	**	Iy#&'''r-   c                 L    d| j         j        d| j         j        d| j        dS )N<rK   r2   >)	__class__r)   r(   r4   ru   s    r.   __repr__zMessage.__repr__  s4     #~888#~666			C 	Cr-   c                 "    | j         |j         k    S rt   r3   r5   others     r.   __eq__zMessage.__eq__  s    yEJ&&r-   c                     | |k     S rt   r,   r   s     r.   __ne__zMessage.__ne__  s    EM""r-   c                    |dk    r|                                  S |                    d          r:| j                            |dd                    }||t          k    rt
          |S |S 	 |                    dd          \  }}| j                            |          }n# t          $ r d }Y nw xY w||}|                                  }|                     |||          S )Nr   zns.   rK   rL   )	r`   r   rC   ra   r   r   rP   rQ   r   )r5   aliased_keyr   urir@   rU   r   s          r.   getAliasedArgzMessage.getAliasedArg!  s   $**,,,!!%(( 	/11+abb/BBC{j(("N"N
	8$**322JE3
 0077BB	  	 	 	BBB	 :C((**B{{2sG,,,s   +B B.-B.rt   )Nr   )&r(   r)   r*   r+   r   THE_OTHER_OPENID1_NSr	   rq   rI   classmethodrY   r[   rR   rb   rF   r`   ri   rx   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   rc   r   r   r   r   r   r,   r-   r.   r   r      s3         ",-A: N@ @ @ @   [6   [#/ #/ #/J	 	 	, , ,# # #? ? ?7 7 7B B B Z((J# # #  0  $ %)!+7% 7% 7% 7%r? ? ?
. . ., , ,
     D0 0 0     &   :  *) ) )
+ 
+ 
+( ( (C C C' ' '# # #- - - - - -r-   r   c                   V    e Zd ZdZd Zd Zd Zd Zd Zd Z	dd	Z
d
 Zd Zd Zd ZdS )r   zBMaintains a bijective map between namespace uris and aliases.
    c                 0    i | _         i | _        g | _        d S rt   )alias_to_namespacenamespace_to_aliasimplicit_namespacesru   s    r.   rI   zNamespaceMap.__init__B  s     "$"$#%   r-   c                 6    | j                             |          S rt   )r   r<   r5   r?   s     r.   r   zNamespaceMap.getAliasG  s    &**=999r-   c                 6    | j                             |          S rt   )r   r<   )r5   r@   s     r.   ra   zNamespaceMap.getNamespaceURIJ  s    &**5111r-   c                 *    t          | j                  S )z*Return an iterator over the namespace URIs)iterr   ru   s    r.   iterNamespaceURIszNamespaceMap.iterNamespaceURIsM      D+,,,r-   c                 *    t          | j                  S )z#Return an iterator over the aliases)r   r   ru   s    r.   iterAliaseszNamespaceMap.iterAliasesQ  r   r-   c                 4    | j                                         S )zWIterate over the mapping

        @returns: iterator of (namespace_uri, alias)
        )r   rM   ru   s    r.   rM   zNamespaceMap.itemsU  s    
 &,,...r-   Fc                    t          |t                    rt          |d          }|t          vsJ |d            t          |t                    rd|vsJ |d            | j                            |          }| ||k    rd}|||||fz  }t          |          | j                            |          }|||k    rd}t          ||||fz            |t          k    s4t          |          t          t          fv sJ t          |                      || j        vsJ || j        |<   || j        |<   |r| j                            |           |S )	zBAdd an alias from this namespace URI to the desired alias
        rl   rm   z" is not an allowed namespace aliasrK   z must not contain a dotNz;Cannot map %r to alias %r. %r is already mapped to alias %rz;Cannot map %r to alias %r. It is already mapped to alias %r)rN   ro   rp   OPENID_PROTOCOL_FIELDSr   r<   r   r   r]   r   reprr   r_   )r5   r?   desired_aliasrH   current_namespace_urir   msgr@   s           r.   r^   zNamespaceMap.addAlias\  s    mU++ 	A@@@M $::::9FH ;::
 mS)) 	Bm+++2?--A ,++
 !% 7 ; ;M J J!-%666C 7L&( (C3-- '++M::-!7!76C3-!FFGGG//]##Sz111D4G4G111D$<<<<<1>.1>. 	;$++M:::r-   c                     | j                             |          }||S d}	 dt          |          z   }	 |                     ||           |S # t          $ r |dz  }Y nw xY wA)zXAdd this namespace URI to the mapping, without caring what
        alias it ends up withNr   TextrL   )r   r<   rp   r^   r   )r5   r?   r@   is       r.   r   zNamespaceMap.add  s     '++M::L 	CFFNEmU333     Q		s   A AAc                     || j         v S rt   )r   r   s     r.   	isDefinedzNamespaceMap.isDefined  s     777r-   c                 ,    |                      |          S rt   )r   r   s     r.   __contains__zNamespaceMap.__contains__  s    ~~m,,,r-   c                     || j         v S rt   )r   r   s     r.   r   zNamespaceMap.isImplicit  s     888r-   N)F)r(   r)   r*   r+   rI   r   ra   r   r   rM   r^   r   r   r   r   r,   r-   r.   r   r   >  s         & & &
: : :2 2 2- - -- - -/ / /, , , ,\$ $ $*8 8 8- - -9 9 9 9 9r-   r   )$r+   __all__r~   r   urllib.requestr   urllib.errorr$   r   r   importElementTreer   ImportErrorr   r
   r   r   rE   r	   Symbolr]   r   r   OPENID1_URL_LIMITr   rQ   r&   r0   objectr   r;   	Exceptionr9   r   r   r   r,   r-   r.   <module>r	     sF                           +'+--KK    KKK I  ( ,
5 !55  0
   011 GN-..	 '.)
*
*     44 4 4 4 4z 4 4 4

 
 
 
 
Z 
 
 
 VXX
  	 	 	 	 	i 	 	 	. . .0p- p- p- p- p-f p- p- p-fh9 h9 h9 h9 h96 h9 h9 h9 h9 h9s   4 >>