a
    xd                     @   s$   G d d de ZG dd de ZdS )c                   @   sP   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 Z
dd ZdS )YadisServiceManagerzHolds the state of a list of selected Yadis services, managing
    storing it in a session and iterating over the services in order.c                 C   s&   || _ || _t|| _|| _d | _d S N)starting_url	yadis_urllistservicessession_key_current)selfr   r   r   r    r
   L/var/www/html/Ranjet/env/lib/python3.9/site-packages/openid/yadis/manager.py__init__   s
    
zYadisServiceManager.__init__c                 C   s
   t | jS )z!How many untried services remain?)lenr   r	   r
   r
   r   __len__   s    zYadisServiceManager.__len__c                 C   s   | S r   r
   r   r
   r
   r   __iter__   s    zYadisServiceManager.__iter__c                 C   s4   z| j d| _W n ty(   tY n0 | jS dS )zReturn the next service

        self.current() will continue to return that service until the
        next call to this method.    N)r   popr   
IndexErrorStopIterationr   r
   r
   r   __next__   s
    
zYadisServiceManager.__next__c                 C   s   | j S )zYReturn the current service.

        Returns None if there are no services left.
        r   r   r
   r
   r   current'   s    zYadisServiceManager.currentc                 C   s   || j | jfv S r   )r   r   )r	   urlr
   r
   r   forURL.   s    zYadisServiceManager.forURLc                 C   s
   | j duS )z$Has the first service been returned?Nr   r   r
   r
   r   started1   s    zYadisServiceManager.startedc                 C   s   | || j < dS )z5Store this object in the session, by its session key.N)r   )r	   sessionr
   r
   r   store5   s    zYadisServiceManager.storeN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r
   r
   r
   r   r      s   r   c                   @   sZ   e Zd ZdZdZdZdddZdd Zdd
dZdd Z	dddZ
dddZdddZdS )	Discoveryac  State management for discovery.

    High-level usage pattern is to call .getNextService(discover) in
    order to find the next available service for this user for this
    session. Once a request completes, call .finish() to clean up the
    session state.

    @ivar session: a dict-like object that stores state unique to the
        requesting user-agent. This object must be able to store
        serializable objects.

    @ivar url: the URL that is used to make the discovery request

    @ivar session_key_suffix: The suffix that will be used to identify
        this object in the session object.
    authZ_yadis_services_Nc                 C   s$   || _ || _|du r| j}|| _dS )zInitialize a discovery objectN)r   r   DEFAULT_SUFFIXsession_key_suffix)r	   r   r   r$   r
   r
   r   r   O   s
    zDiscovery.__init__c                 C   s\   |   }|dur|s|   |s:|| j\}}| ||}|rTt|}|| j nd}|S )a:  Return the next authentication service for the pair of
        user_input and session.  This function handles fallback.


        @param discover: a callable that takes a URL and returns a
            list of services

        @type discover: str -> [service]


        @return: the next available service
        N)
getManagerdestroyManagerr   createManagernextr   r   )r	   Zdiscovermanagerr   r   servicer
   r
   r   getNextServiceX   s    zDiscovery.getNextServiceFc                 C   s2   | j |d}|dur*| }| j|d nd}|S )at  Clean up Yadis-related services in the session and return
        the most-recently-attempted service from the manager, if one
        exists.

        @param force: True if the manager should be deleted regardless
        of whether it's a manager for self.url.

        @return: current service endpoint object or None if there is
            no current service
        forceN)r%   r   r&   )r	   r-   r)   r*   r
   r
   r   cleanupu   s    zDiscovery.cleanupc                 C   s   | j | j S )zsGet the session key for this starting URL and suffix

        @return: The session key
        @rtype: str
        )PREFIXr$   r   r
   r
   r   getSessionKey   s    zDiscovery.getSessionKeyc                 C   s4   | j |  }|dur,|| js(|r,|S dS dS )a>  Extract the YadisServiceManager for this object's URL and
        suffix from the session.

        @param force: True if the manager should be returned
        regardless of whether it's a manager for self.url.

        @return: The current YadisServiceManager, if it's for this
            URL, or else None
        N)r   getr0   r   r   )r	   r-   r)   r
   r
   r   r%      s    
zDiscovery.getManagerc                 C   sJ   |   }|  r"td|| jf |s*dS t| j|||}|| j |S )zCreate a new YadisService Manager for this starting URL and
        suffix, and store it in the session.

        @raises KeyError: When I already have a manager.

        @return: A new YadisServiceManager or None
        z$There is already a %r manager for %rN)r0   r%   KeyErrorr   r   r   r   )r	   r   r   keyr)   r
   r
   r   r'      s    zDiscovery.createManagerc                 C   s$   | j |ddur |  }| j|= dS )aT  Delete any YadisServiceManager with this starting URL and
        suffix from the session.

        If there is no service manager or the service manager is for a
        different URL, it silently does nothing.

        @param force: True if the manager should be deleted regardless
        of whether it's a manager for self.url.
        r,   N)r%   r0   r   )r	   r-   r3   r
   r
   r   r&      s    
zDiscovery.destroyManager)N)F)F)N)F)r   r   r   r    r#   r/   r   r+   r.   r0   r%   r'   r&   r
   r
   r
   r   r!   :   s   
	


r!   N)objectr   r!   r
   r
   r
   r   <module>   s   9