
    )Jf                     >     G d  de           Z G d de           ZdS )c                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
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                 f    || _         || _        t          |          | _        || _        d | _        d S N)starting_url	yadis_urllistservicessession_key_current)selfr   r   r	   r
   s        W/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/openid/yadis/manager.py__init__zYadisServiceManager.__init__   s7    ( # X&     c                 *    t          | j                  S )z!How many untried services remain?)lenr	   r   s    r   __len__zYadisServiceManager.__len__   s    4=!!!r   c                     | S r    r   s    r   __iter__zYadisServiceManager.__iter__   s    r   c                 z    	 | j                             d          | _        | j        S # t          $ r t          w xY w)zReturn the next service

        self.current() will continue to return that service until the
        next call to this method.    )r	   popr   
IndexErrorStopIterationr   s    r   __next__zYadisServiceManager.__next__   sK    
	! M--a00DM =   	  	  	 	 s   ( :c                     | j         S )zYReturn the current service.

        Returns None if there are no services left.
        r   r   s    r   currentzYadisServiceManager.current'   s    
 }r   c                 "    || j         | j        fv S r   )r   r   )r   urls     r   forURLzYadisServiceManager.forURL.   s    t($.999r   c                     | j         duS )z$Has the first service been returned?Nr   r   s    r   startedzYadisServiceManager.started1   s    }D((r   c                     | || j         <   dS )z5Store this object in the session, by its session key.N)r
   )r   sessions     r   storezYadisServiceManager.store5   s    $( !!!r   N)__name__
__module____qualname____doc__r   r   r   r   r   r"   r$   r'   r   r   r   r   r      s        I I  " " "  
! 
! 
!  : : :) ) )) ) ) ) )r   r   c                   N    e Zd ZdZdZdZddZd ZddZd	 Z	dd
Z
ddZ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.
    auth_yadis_services_Nc                 B    || _         || _        || j        }|| _        dS )zInitialize a discovery objectN)r&   r!   DEFAULT_SUFFIXsession_key_suffix)r   r&   r!   r2   s       r   r   zDiscovery.__init__O   s-    %!%!4"4r   c                    |                                  }||s|                                  |s) || j                  \  }}|                     ||          }|r*t	          |          }|                    | 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   discovermanagerr   r	   services         r   getNextServicezDiscovery.getNextServiceX   s     //##w!!! 	>"*(48"4"4Ix((9==G 	7mmGMM$,''''Gr   Fc                     |                      |          }|+|                                }|                     |           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)r4   r   r5   )r   r>   r9   r:   s       r   cleanupzDiscovery.cleanupu   sP     ///..oo''Ge,,,,Gr   c                      | j         | j        z   S )zsGet the session key for this starting URL and suffix

        @return: The session key
        @rtype: str
        )PREFIXr2   r   s    r   getSessionKeyzDiscovery.getSessionKey   s     {T444r   c                     | j                             |                                           }||                    | j                  s|r|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&   getrB   r"   r!   )r   r>   r9   s      r   r4   zDiscovery.getManager   sM     ,""4#5#5#7#788W^^DH%=%=N4r   c                     |                                  }|                                 rt          d|d| j                  |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 z manager for N)rB   r4   KeyErrorr!   r   r'   r&   )r   r	   r   keyr9   s        r   r6   zDiscovery.createManager   s       ""?? 	,(CC+ , , ,  	4%dh	8SIIdl###r   c                 n    |                      |          |                                 }| j        |= dS 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)r4   rB   r&   )r   r>   rG   s      r   r5   zDiscovery.destroyManager   sA     ???''3$$&&CS!!! 43r   r   )F)r(   r)   r*   r+   r1   rA   r   r;   r?   rB   r4   r6   r5   r   r   r   r-   r-   :   s         " NF5 5 5 5  :   ,5 5 5       (" " " " " "r   r-   N)objectr   r-   r   r   r   <module>rJ      sn   6) 6) 6) 6) 6)& 6) 6) 6)rI" I" I" I" I" I" I" I" I" I"r   