U
    [eX                     @   sN  d Z ddddddddd	d
g
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k
rx   dZY nX 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ddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-gZG d.d/ d/eZG d0d1 d1eZe Zi aG d2d3 d3eZ d4d Z!G d5d deZ"G d6d deZ#dS )7z#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   P/var/www/html/services/stratfitenv/lib/python3.8/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  kr0td| f |t k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    
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krd| _n|tk}| || dS )zCreate 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 ]n\}}t|tr2td|f z|dd\}}W n tk
r^   d}Y nX |dkrx||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 )zConstruct 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k
rD   t}|}Y nX |dkr^| j|| q|tkr||dkr|| |d q||||f q|  s| t	d |D ]f\}}}| j
|}|d kr| |}|d kr|  }d||f }n| jj||dd | ||| qd 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k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)	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k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krtd|dk	st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| qt 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enctypeZhidden)typenamer>   inputsubmit)rj   r>   rO   rP   )ElementTreeRuntimeErrorAssertionErrorZElementr5   Zattribr   r\   r^   rF   rS   tostring)
r#   Z
action_urlZform_tag_attrsZsubmit_textrf   rk   attrr>   attrsrm   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 )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   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kr2tdn| j}|tkrXt |tsXtd|f |tkrd|krd}t	||f t
 |dkrd	}t	|tf 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
        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kS rU   r   r"   )r#   r   rL   r   r   r   hasKey  s    
zMessage.hasKeyc                 C   sP   |  |}|tkr|S | j|}|dk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   sV   |  |}||f}z| j| W S  tk
rP   |tkrDt||fn| Y S Y nX 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 )zGet 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 )zSet 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k	st |dk	st | |}t|tr8t|dd}|| j||f< |tk	rZ| j| dS )z'Set a single argument in this namespaceNrO   rP   )	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 krJ|tkrDtqN|S n|S z|dd\}}W n tk
rz   d }Y nX | j|}|d k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   rt   rv   rw   r|   r   r   r]   r   r   r   rJ   r   r   r   r   r   r   r   r   r   r      sH   




%  
9"

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ks,td|f t |trLd|ksLtd|f | j|}|dk	r||krd}|||||f }t|| j|}|dk	r||krd}t||||f |t	kst
|ttfkstt||| jkst|| 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_FIELDSrp   r   r(   r   r   rD   rj   reprr   rF   )r#   r+   Zdesired_aliasr1   Zcurrent_namespace_urir   msgr,   r   r   r   rE   \  sB    





zNamespaceMap.addAliasc                 C   sl   | j |}|dk	r|S d}dt| }z| || W n tk
rT   |d7 }Y qX |S qdsht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   rp   )r#   r+   r,   ir   r   r   r     s    zNamespaceMap.addc                 C   s
   || j k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 k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   __all__rY   r~   urllib.requestry   urllib.errorr   r   r   ZimportElementTreern   ImportErrorr
   r	   r   r   r/   r   SymbolrD   r   r   ZOPENID1_URL_LIMITr   r9   r   r    objectr   r'   	Exceptionr&   r   r   r   r   r   r   r   <module>   s          



   6