
    f                     0     G d  de       Z G d de       Zy)c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)YadisServiceManagerzHolds the state of a list of selected Yadis services, managing
    storing it in a session and iterating over the services in order.c                 \    || _         || _        t        |      | _        || _        d | _        y N)starting_url	yadis_urllistservicessession_key_current)selfr   r   r	   r
   s        O/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/openid/yadis/manager.py__init__zYadisServiceManager.__init__   s1    ( # 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                     	 | j                   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__   s@    
	! MM--a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                 6    || 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                   <   y)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      s0    I"
!:))r   r   c                   L    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y)	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                 J    || _         || _        || j                  }|| _        y)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"4r   c                     | j                         }||s| j                          |s' || j                        \  }}| j                  ||      }|r(t	        |      }|j                  | j                         |S 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!"*488"4Ix((9=G7mGMM$,,'  Gr   c                 z    | j                  |      }|$|j                         }| j                  |       |S 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   sJ     ///.oo'Ge,  Gr   c                 4    | 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44r   c                     | j                   j                  | j                               }||j                  | j                        s|r|S y)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   s@     ,,""4#5#5#78W^^DHH%=Nr   c                     | j                         }| j                         rt        d|d| j                        |syt	        | j                  |||      }|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   sh       "??+ , , %dhh	8SIdll#r   c                 d    | j                  |      | j                         }| j                  |= yy)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   s4     ???'3$$&CS! 4r   r   )F)r(   r)   r*   r+   r1   rA   r   r;   r?   rB   r4   r6   r5   r   r   r   r-   r-   :   s6    " NF5:,5 ("r   r-   N)objectr   r-   r   r   r   <module>rJ      s    6)& 6)rI" I"r   