
    fX                        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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#y# e$ r dZY w xY w)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y)UndefinedOpenIDNamespaceznRaised if the generic OpenID namespace is accessed when there
    is no OpenID namespace set for this message.N__name__
__module____qualname____doc__     I/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/openid/message.pyr&   r&   Q   s    4r-   r&   c                       e Zd ZdZd Zy)InvalidOpenIDNamespacezxRaised if openid.ns is not a recognized value.

    For recognized values, see L{Message.allowed_openid_namespaces}
    c                 L    d}| j                   r|d| j                   d   z  }|S )NzInvalid OpenID Namespace r   args)selfss     r.   __str__zInvalidOpenIDNamespace.__str__\   s(    &99$))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y)NamespaceAliasRegistrationErrorzL
    Raised when an alias or namespace URI has already been registered.
    Nr'   r,   r-   r.   r9   r9   l   s     	r-   r9   c                     t         j                  |      | k(  ry| t        t         j                               v rt	        d| d      |t         v rt	        d|d      | t         |<   y)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   ss     e$5/66899-5BEG 	G ""-/4/8 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%y)"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                 x    i | _         t               | _        |d| _        y|t        v }| j                  ||       y)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__   s>     	&.#"&D'+==H##$4h?r-   c                 4    |        }i }|j                         D ]Y  \  }}t        |t              rt        d|      	 |j	                  dd      \  }}|dk7  r||j                  t        |f<   U||<   [ |j                  |       |S # t
        $ r d}Y Bw xY w)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    
 u **, 	*JC%&GK!O P P"yya0 !,1		7C.)$)D!	* 	[)  s   B		BBc                 6     |        }|j                  |       |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     u[)r-   c                    g }|j                         D ]r  \  }}	 |j                  dd      \  }}|dk(  r| j                  j                  ||       >|t        k(  r|dk(  r| j                  |d       _|j                  |||f       t | j                         s| j                  t        d       |D ]  \  }}}| j                  j                  |      }|I| j                  |      }|| j                         }|d|}n| j                  j                  ||d       | j                  |||        y # t        $ r t        }|}Y w xY w)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   sN    ',,. 	:KD%#'::c1#5 &
 4((7^+$''u5&%89	:  &&(##J5 *1 	/%Xvu__44X>F~228<>!446F(0&9FOO,,VX,MKK.	/#  )s   D33EEc                 N    | j                         rt        j                  |      S y)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r-   c                     t        |t              rt        |d      }|| j                  vrt	        |      | j
                  j                  |t        |       || _        y)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   sQ     mU+@M > >>(77  I+r-   c                     | j                   S N)rD   r5   s    r.   r`   zMessage.getOpenIDNamespace  s    """r-   c                 .    | j                         t        v S rt   )r`   rE   ru   s    r.   ri   zMessage.isOpenID1  s    &&(,>>>r-   c                 0    | j                         t        k(  S rt   )r`   r	   ru   s    r.   	isOpenID2zMessage.isOpenID2  s    &&(J66r-   c                 J    | j                  t        j                  |            S )z%Create a Message from a KVForm string)r[   r   kvToDict)rS   kvform_strings     r.   
fromKVFormzMessage.fromKVForm  s    !!&//-"@AAr-   c                 ,    t        j                  |       S rt   )copydeepcopyru   s    r.   r~   zMessage.copy  s    }}T""r-   c                 v   i }| j                   j                         D ]J  \  }}| j                   j                  |      r"|t        k(  rd}nd|z   }t	        j
                  |      ||<   L | j                  j                         D ]2  \  \  }}}| j                  ||      }t	        j
                  |      ||<   4 |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 	5MFE))&1&$%-",,V4DL	5 (,yy'8 	1#VVe++ff-C))%0DI	1
 r-   c                     | j                         }i }|j                         D ])  \  }}|j                  d      st        d      |||dd <   + |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  sh     OO%	OO% 	"DAq<<	* NO O !"qu	" r-   c                    t         t        d      |J t         j                  d      }|r'|j                         D ]  \  }}||j                  |<    t        j                  |      |j                  d<   d|j                  d<   d|j                  d<   d|j                  d	<   | j                         j                         D ]V  \  }}d
t        j                  |      t        j                  |      d}|j                  t         j                  d|             X t         j                  ddt        j                  |      d      }	|j                  |	       t        t         j                  |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
        z#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  sd   0 DEE%%%""6*,224 )
d$(D!) !( 1 1* =H &H(/$%!DI??,224 	=KD% ))$/ **51E
 KK++GU;<	= $$''467 	F;''w'?#% 	%r-   c                 J    t        j                  || 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                 H    t        j                  | 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        | j                         j                               }t        j                  j                  |      S )z#Generate an x-www-urlencoded string)sortedr   rM   urllibparse	urlencode)r5   r4   s     r.   toURLEncodedzMessage.toURLEncoded  s1    doo'--/0||%%d++r-   c                    t        |t              rt        |d      }|t        k(  r#| j                  t        d      | j                  }|t        k7  rt        |t              st        d|      |t        k7  rSd|vrOd}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   z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'I8I	!""*./IJJ //	
9c(B  Cy$8KCMM#-/ABF"?8,&&*  r-   c                 D    | j                  |      }||f| j                  v S rt   r   r4   )r5   r   rf   s      r.   hasKeyzMessage.hasKey  s$    KK	*	6"dii//r-   c                     | j                  |      }|t        k(  r|S | j                  j                  |      }|y|t        k(  r|}d|z   S |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  sm    KK	*	M??++I6 ~%D 4 '/D4r-   c                     | j                  |      }||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  s\    & KK	*	s#	99X&& 	*$	3/00		s   &  A	A	c                 :   | j                  |      }g }| j                  j                         D ]a  \  \  }}}||k(  st        |t              rt        |d      }n|}t        |t              rt        |d      }n|}|j                  ||f       c t        |      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5AAeU+EG4AAQF#
	$ Dzr-   c                 |    | j                  |      }|j                         D ]  \  }}| j                  |||        y)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  s;     KK	*	MMO 	)DAqKK	1a(	)r-   c                     |J |J | j                  |      }t        |t              rt        |d      }|| j                  ||f<   |t
        ur| j                  j                  |       yy)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  sn       KK	*	eU#0E&+		9c"#W$OO	* %r-   c                 D    | j                  |      }| j                  ||f= y rt   r   )r5   r   rU   s      r.   delArgzMessage.delArg  s!    KK	*	IIy#&'r-   c                 ~    d| j                   j                  d| j                   j                  d| j                  dS )N<rK   r2   >)	__class__r)   r(   r4   ru   s    r.   __repr__zMessage.__repr__  s.    #~~88#~~66		C 	Cr-   c                 4    | j                   |j                   k(  S rt   r3   r5   others     r.   __eq__zMessage.__eq__  s    yyEJJ&&r-   c                     | |k(   S rt   r,   r   s     r.   __ne__zMessage.__ne__  s    EM""r-   c                    |dk(  r| j                         S |j                  d      r3| j                  j                  |dd        }||t        k(  rt
        |S |S 	 |j                  dd      \  }}| j                  j                  |      }||}| j                         }| j                  ||      S # t        $ r d }Y 4w xY w)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+ab/BC{j("N"N
	8$**32JE3
 007B:C((*B{{2sG,,  	B	s   B2 2C ?C rt   )NContinue)&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      s     ",-A: N@  6  #/J	,#?7B Z(J#0$ %)!+7%r?
.,
 D0 &:*)
+(C'#-r-   r   c                   T    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y)r   zBMaintains a bijective map between namespace uris and aliases.
    c                 .    i | _         i | _        g | _        y rt   )alias_to_namespacenamespace_to_aliasimplicit_namespacesru   s    r.   rI   zNamespaceMap.__init__B  s    "$"$#% r-   c                 8    | j                   j                  |      S rt   )r   r<   r5   r?   s     r.   r   zNamespaceMap.getAliasG  s    &&**=99r-   c                 8    | j                   j                  |      S rt   )r   r<   )r5   r@   s     r.   ra   zNamespaceMap.getNamespaceURIJ  s    &&**5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                 6    | j                   j                         S )zWIterate over the mapping

        @returns: iterator of (namespace_uri, alias)
        )r   rM   ru   s    r.   rM   zNamespaceMap.itemsU  s    
 &&,,..r-   c                 p   t        |t              rt        |d      }|t        vs
J |d       t        |t              rd|vs
J |d       | j                  j                  |      }|||k7  rd}|||||fz  }t        |      | j                  j                  |      }|||k7  rd}t        ||||fz        |t        k(  s't        |      t        t        fv sJ t        |             || j                  vsJ || j                  |<   || j                  |<   |r| j                  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 dotz;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+@M $:: 	I9FH	I:
 mS)m+ B2?AB+
 !% 7 7 ; ;M J!-%66C 7L&( (C3- ''++M:-!76C3-!FFGG/]#Sz1	H484G	H 2D$<$<<<<1>.1>.$$++M:r-   c                     | j                   j                  |      }||S d}	 dt        |      z   }	 | j                  ||       |S # t        $ r |dz  }Y nw xY w8)zXAdd this namespace URI to the mapping, without caring what
        alias it ends up withr   extrL   )r   r<   rp   r^   r   )r5   r?   r@   is       r.   r   zNamespaceMap.add  su     ''++M:L CFNEmU3   Q	 s   A AAc                     || j                   v S rt   )r   r   s     r.   	isDefinedzNamespaceMap.isDefined  s     7 777r-   c                 $    | j                  |      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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--/,\$*8-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	     s#        +'++-K I  ( ,
5 !55  0
   01 GNN-.	 '..)
*   44z 4

Z 
 X
  	i 	.0p-f p-fh96 h9Y   Ks   C CC