a
    Šxd˜X  ã                   @   s  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	 ze 
¡ ZW n eyf   dZY n0 dZdZdZd	ZeefZd
Ze d¡Ze d¡Ze d¡ZdZg d¢ZG dd„ deƒZG dd„ deƒZeƒ Zi aG dd„ deƒZ dd„ Z!G dd„ deƒZ"G d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ÚerrorZ	return_toÚcontactÚ	referenceÚsignedZ
assoc_typeZsession_typeZ
dh_modulusZdh_genZdh_consumer_publicZ
claimed_idÚidentityÚrealmZinvalidate_handleZop_endpointZresponse_nonceÚsigZassoc_handleZ
trust_rootÚopenidc                   @   s   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__© r   r   úF/var/www/html/Ranjet/env/lib/python3.9/site-packages/openid/message.pyr   Q   s   r   c                   @   s   e Zd ZdZdd„ ZdS )ÚInvalidOpenIDNamespacezxRaised if openid.ns is not a recognized value.

    For recognized values, see L{Message.allowed_openid_namespaces}
    c                 C   s"   d}| j r|d| j d f 7 }|S )NzInvalid OpenID Namespacez %rr   ©Úargs)ÚselfÚsr   r   r   Ú__str__\   s    zInvalidOpenIDNamespace.__str__N)r   r   r   r   r%   r   r   r   r   r    V   s   r    c                   @   s   e Zd ZdZdS )ÚNamespaceAliasRegistrationErrorzL
    Raised when an alias or namespace URI has already been registered.
    Nr   r   r   r   r   r&   l   s   r&   c                 C   sR   t  |¡| krdS | tt  ¡ ƒv r0td| f ƒ‚|t v rFtd|f ƒ‚| 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 %r already registeredzAlias %r already registered)Úregistered_aliasesÚgetÚlistÚvaluesr&   )Únamespace_uriÚaliasr   r   r   r   s   s    
ÿÿr   c                   @   s  e Zd ZdZeeegZd>dd„Ze	dd„ ƒZ
e	dd„ ƒZd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze	eƒZdd„ Zdd„ Zdd„ Zd?dd„Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd@d,d-„Zd.d/„ Zd0d1„ Zd2d3„ Z d4d5„ Z!d6d7„ Z"d8d9„ Z#d:d;„ Z$dAd<d=„Z%dS )Br   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                 C   s6   i | _ tƒ | _|du rd| _n|tv }|  ||¡ dS )z™Create an empty Message.

        @raises InvalidOpenIDNamespace: if openid_namespace is not in
            L{Message.allowed_openid_namespaces}
        N)r"   r   Ú
namespacesÚ_openid_ns_uriÚOPENID1_NAMESPACESÚsetOpenIDNamespace)r#   Zopenid_namespaceÚimplicitr   r   r   Ú__init__›   s    zMessage.__init__c              	   C   sŽ   | ƒ }i }|  ¡ D ]l\}}t|tƒr2td|f ƒ‚z| dd¡\}}W n ty\   d}Y n0 |dkrv||jt|f< q|||< q| |¡ |S )zAConstruct a Message containing a set of POST arguments.

        zNquery dict must have one value for each key, not lists of values.  Query is %rÚ.é   Nr   )	ÚitemsÚ
isinstancer)   Ú	TypeErrorÚsplitÚ
ValueErrorr"   r   Ú_fromOpenIDArgs)Úclsr"   r#   Úopenid_argsÚkeyÚvalueÚprefixÚrestr   r   r   ÚfromPostArgs©   s     
ÿ


zMessage.fromPostArgsc                 C   s   | ƒ }|  |¡ |S )z«Construct a Message from a parsed KVForm message.

        @raises InvalidOpenIDNamespace: if openid.ns is not in
            L{Message.allowed_openid_namespaces}
        )r:   )r;   r<   r#   r   r   r   ÚfromOpenIDArgsÅ   s    
zMessage.fromOpenIDArgsc              	   C   s  g }|  ¡ D ]~\}}z| dd¡\}}W n tyB   t}|}Y n0 |dkr\| j ||¡ q|tkrz|dkrz|  |d¡ q| |||f¡ q|  ¡ s |  t	d¡ |D ]f\}}}| j 
|¡}|d u rü|  |¡}|d u rê|  ¡ }d||f }n| jj||dd |  |||¡ q¤d S )Nr3   r4   r   FTú%s.%s)r1   )r5   r8   r9   ÚNULL_NAMESPACEr-   ÚaddAliasr0   ÚappendÚgetOpenIDNamespacer   ÚgetNamespaceURIÚ_getDefaultNamespaceÚsetArg)r#   r<   Zns_argsr@   r>   Úns_aliasÚns_keyÚns_urir   r   r   r:   Ð   s.    

zMessage._fromOpenIDArgsc                 C   s   |   ¡ rt |¡S dS dS )zWOpenID 1 compatibility: look for a default namespace URI to
        use for this alias.N)Ú	isOpenID1r'   r(   )r#   Zmystery_aliasr   r   r   rI   õ   s    
zMessage._getDefaultNamespacec                 C   sB   t |tƒrt|dd}|| jvr(t|ƒ‚| j |t|¡ || _dS )z°Set the OpenID namespace URI used in this message.

        @raises InvalidOpenIDNamespace: if the namespace is not in
            L{Message.allowed_openid_namespaces}
        úutf-8©ÚencodingN)	r6   ÚbytesÚstrÚallowed_openid_namespacesr    r-   rE   rD   r.   )r#   Zopenid_ns_urir1   r   r   r   r0      s    

zMessage.setOpenIDNamespacec                 C   s   | j S ©N)r.   ©r#   r   r   r   rG     s    zMessage.getOpenIDNamespacec                 C   s   |   ¡ tv S rU   )rG   r/   rV   r   r   r   rN     s    zMessage.isOpenID1c                 C   s   |   ¡ tkS rU   )rG   r   rV   r   r   r   Ú	isOpenID2  s    zMessage.isOpenID2c                 C   s   |   t |¡¡S )z%Create a Message from a KVForm string)rB   r   ZkvToDict)r;   Zkvform_stringr   r   r   Ú
fromKVForm  s    zMessage.fromKVFormc                 C   s
   t  | ¡S rU   )ÚcopyÚdeepcopyrV   r   r   r   rY     s    zMessage.copyc                 C   s€   i }| j  ¡ D ]:\}}| j  |¡r$q|tkr2d}nd| }t |¡||< q| j ¡ D ]&\\}}}|  ||¡}t |¡||< qT|S )zk
        Return all arguments with openid. in front of namespaced arguments.
        @return bytes
        z	openid.nsz
openid.ns.)r-   r5   Ú
isImplicitrD   r   Ú	toUnicoder"   ÚgetKey)r#   r"   rM   r,   rL   r>   r=   r   r   r   Ú
toPostArgs   s    zMessage.toPostArgsc                 C   sF   |   ¡ }i }| ¡ D ],\}}| d¡s0tdƒ‚q|||dd… < q|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^   r5   Ú
startswithr9   )r#   Z	post_argsZkvargsÚkÚvr   r   r   ÚtoArgs8  s    
ÿzMessage.toArgsÚContinuec           
      C   sì   t du rtdƒ‚|dusJ ‚t  d¡}|rF| ¡ D ]\}}||j|< q2t |¡|jd< d|jd< d|jd< d	|jd
< |  ¡  ¡ D ]2\}}dt |¡t |¡dœ}| t  d|¡¡ q€t  ddt |¡dœ¡}	| |	¡ t	t j
|dd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-urlencodedZenctypeÚhidden)ÚtypeÚnamer>   ÚinputÚsubmit)rk   r>   rO   rP   )ÚElementTreeÚRuntimeErrorÚElementr5   Úattribr   r\   r^   rF   rS   Útostring)
r#   Z
action_urlZform_tag_attrsZsubmit_textrf   rl   Úattrr>   Úattrsrn   r   r   r   ÚtoFormMarkupH  s6    



ýÿþ
ÿzMessage.toFormMarkupc                 C   s   t  ||  ¡ ¡S )z\Generate a GET URL with the parameters in this message
        attached as query parameters.)r   Z
appendArgsr^   )r#   Úbase_urlr   r   r   ÚtoURL  s    zMessage.toURLc                 C   s   t  |  ¡ ¡S )z±Generate a KVForm string that contains the parameters in
        this message. This will fail if the message contains arguments
        outside of the 'openid.' prefix.
        )r   ZdictToKVrd   rV   r   r   r   ÚtoKVForm†  s    zMessage.toKVFormc                 C   s   t |  ¡  ¡ ƒ}tj |¡S )z#Generate an x-www-urlencoded string)Úsortedr^   r5   ÚurllibÚparseÚ	urlencode)r#   r"   r   r   r   ÚtoURLEncoded  s    zMessage.toURLEncodedc                 C   s¤   t |tƒrt|dd}|tkr8| jdu r2tdƒ‚n| j}|tkrXt |tƒsXtd|f ƒ‚|tkr d|vr d}t 	||f t
¡ |dkr d	}t 	|tf t
¡ tS |S )
zÓConvert 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
        rO   rP   NzOpenID namespace not setz8Namespace must be BARE_NS, OPENID_NS or a string. got %rú:z7OpenID 2.0 namespace identifiers SHOULD be URIs. Got %rZsregz'Using %r instead of "sreg" as namespace)r6   rR   rS   r   r.   r   r   r7   ÚwarningsÚwarnÚDeprecationWarningr	   )r#   Ú	namespaceÚfmtr   r   r   Ú_fixNS’  s.    


ÿÿþzMessage._fixNSc                 C   s   |   |¡}||f| jv S rU   ©r…   r"   )r#   rƒ   rL   r   r   r   ÚhasKey´  s    
zMessage.hasKeyc                 C   sP   |   |¡}|tkr|S | j |¡}|du r.dS |tkr<|}nd||f }d| S )z0Get the key for a particular namespaced argumentNrC   r_   )r…   r   r-   ÚgetAliasrD   )r#   rƒ   rL   rK   Útailr   r   r   r]   ¸  s    
zMessage.getKeyc                 C   sT   |   |¡}||f}z| j| W S  tyN   |tu rBt||fƒ‚n| Y S Y n0 dS )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
        N)r…   r"   ÚKeyErrorr   )r#   rƒ   r=   ÚdefaultZargs_keyr   r   r   ÚgetArgË  s    
zMessage.getArgc                 C   s|   |   |¡}g }| j ¡ D ]Z\\}}}||krt|tƒrDt|dd}n|}t|tƒr`t|dd}n|}| ||f¡ qt|ƒS )z¥Get the arguments that are defined for this namespace URI

        @returns: mapping from namespaced keys to values
        @returntype: dict of {str:bytes}
        rO   rP   )r…   r"   r5   r6   rR   rS   rF   Údict)r#   rƒ   r"   Zpair_nsrL   r>   rb   rc   r   r   r   ÚgetArgsè  s    


zMessage.getArgsc                 C   s.   |   |¡}| ¡ D ]\}}|  |||¡ qdS )z…Set multiple key/value pairs in one call

        @param updates: The values to set
        @type updates: {unicode:unicode}
        N)r…   r5   rJ   )r#   rƒ   Zupdatesrb   rc   r   r   r   Ú
updateArgsý  s    
zMessage.updateArgsc                 C   s^   |dusJ ‚|dusJ ‚|   |¡}t|tƒr8t|dd}|| j||f< |turZ| j |¡ dS )z'Set a single argument in this namespaceNrO   rP   )r…   r6   rR   rS   r"   r   r-   Úadd)r#   rƒ   r=   r>   r   r   r   rJ     s    

zMessage.setArgc                 C   s   |   |¡}| j||f= d S rU   r†   )r#   rƒ   r=   r   r   r   ÚdelArg  s    
zMessage.delArgc                 C   s   d| j j| j j| jf S )Nz
<%s.%s %r>)Ú	__class__r   r   r"   rV   r   r   r   Ú__repr__  s    
ÿzMessage.__repr__c                 C   s   | j |j kS rU   r!   ©r#   Úotherr   r   r   Ú__eq__  s    zMessage.__eq__c                 C   s
   | |k S rU   r   r”   r   r   r   Ú__ne__  s    zMessage.__ne__c                 C   s¨   |dkr|   ¡ S | d¡rN| j |dd … ¡}|d u rJ|tkrDt‚qN|S n|S z| dd¡\}}W n tyx   d }Y n0 | j |¡}|d u rš|}|   ¡ }|  |||¡S )Nr   zns.é   r3   r4   )	rG   ra   r-   rH   r   rŠ   r8   r9   rŒ   )r#   Zaliased_keyr‹   Úurir,   r=   r   r   r   r   ÚgetAliasedArg!  s$    

zMessage.getAliasedArg)N)Nre   )N)N)&r   r   r   r   r   ÚTHE_OTHER_OPENID1_NSr   rT   r2   ÚclassmethodrA   rB   r:   rI   r0   rG   rN   rW   rX   rY   r^   rd   rv   rx   ry   r~   r…   r‡   r]   rŒ   rŽ   r   rJ   r‘   r“   r–   r—   rš   r   r   r   r   r   ‹   sH   




%  ý
9"

r   c                   @   sj   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	ddd„Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )r   zBMaintains a bijective map between namespace uris and aliases.
    c                 C   s   i | _ i | _g | _d S rU   )Úalias_to_namespaceÚnamespace_to_aliasÚimplicit_namespacesrV   r   r   r   r2   B  s    zNamespaceMap.__init__c                 C   s   | j  |¡S rU   )rž   r(   ©r#   r+   r   r   r   rˆ   G  s    zNamespaceMap.getAliasc                 C   s   | j  |¡S rU   )r   r(   )r#   r,   r   r   r   rH   J  s    zNamespaceMap.getNamespaceURIc                 C   s
   t | jƒS )z*Return an iterator over the namespace URIs)Úiterrž   rV   r   r   r   ÚiterNamespaceURIsM  s    zNamespaceMap.iterNamespaceURIsc                 C   s
   t | jƒS )z#Return an iterator over the aliases)r¡   r   rV   r   r   r   ÚiterAliasesQ  s    zNamespaceMap.iterAliasesc                 C   s
   | j  ¡ S )zWIterate over the mapping

        @returns: iterator of (namespace_uri, alias)
        )rž   r5   rV   r   r   r   r5   U  s    zNamespaceMap.itemsFc                 C   s  t |tƒrt|dd}|tvs,J d|f ƒ‚t |tƒrLd|vsLJ d|f ƒ‚| j |¡}|dur„||kr„d}|||||f }t|ƒ‚| j |¡}|dur¶||kr¶d}t||||f ƒ‚|tksÚt	|ƒ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
        rO   rP   z$%r is not an allowed namespace aliasr3   z%r 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)r6   rR   rS   ÚOPENID_PROTOCOL_FIELDSr   r(   rŠ   rž   rD   rk   ÚreprrŸ   rF   )r#   r+   Zdesired_aliasr1   Zcurrent_namespace_urir„   Úmsgr,   r   r   r   rE   \  sB    

ÿ

ÿÿÿÿÿ

zNamespaceMap.addAliasc                 C   sj   | j  |¡}|dur|S d}dt|ƒ }z|  ||¡ W n tyR   |d7 }Y q0 |S qdsfJ dƒ‚dS )zXAdd this namespace URI to the mapping, without caring what
        alias it ends up withNr   Úextr4   FzNot reached)rž   r(   rS   rE   rŠ   )r#   r+   r,   Úir   r   r   r   Š  s    zNamespaceMap.addc                 C   s
   || j v S rU   )rž   r    r   r   r   Ú	isDefinedŸ  s    zNamespaceMap.isDefinedc                 C   s
   |   |¡S rU   )r©   r    r   r   r   Ú__contains__¢  s    zNamespaceMap.__contains__c                 C   s
   || j v S rU   )rŸ   r    r   r   r   r[   ¥  s    zNamespaceMap.isImplicitN)F)r   r   r   r   r2   rˆ   rH   r¢   r£   r5   rE   r   r©   rª   r[   r   r   r   r   r   >  s   
.r   )$r   Ú__all__rY   r€   Úurllib.requestr{   Úurllib.errorr   r   r   ZimportElementTreero   ÚImportErrorr
   r	   r   r›   r/   r   ZSymbolrD   r   r   ZOPENID1_URL_LIMITr¤   r9   r   r    Úobjectr   r'   Ú	Exceptionr&   r   r   r   r   r   r   r   Ú<module>   sB   



   6