a
    Šxd  ã                   @   sD   d Z ddlmZ ddlZddlZG dd„ deƒZG dd„ deƒZdS )z,A simple store using only in-process memory.é    )ÚnonceNc                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚServerAssocsc                 C   s
   i | _ d S ©N)Úassocs©Úself© r   úM/var/www/html/Ranjet/env/lib/python3.9/site-packages/openid/store/memstore.pyÚ__init__
   s    zServerAssocs.__init__c                 C   s   || j |j< d S r   )r   Úhandle)r   Úassocr   r   r	   Úset   s    zServerAssocs.setc                 C   s   | j  |¡S r   )r   Úget©r   r   r   r   r	   r      s    zServerAssocs.getc                 C   s*   z| j |= W n ty    Y dS 0 dS d S ©NFT)r   ÚKeyErrorr   r   r   r	   Úremove   s
    zServerAssocs.removec                 C   s4   d}t | j ¡ ƒD ]}|du s*|j|jk r|}q|S )zhReturns association with the oldest issued date.

        or None if there are no associations.
        N)Úlistr   ÚvaluesZissued)r   Úbestr   r   r   r	   r      s
    zServerAssocs.bestc                 C   sP   g }| j  ¡ D ]\}}|jdkr| |¡ q|D ]}| j |= q0t|ƒt| j ƒfS )zoRemove expired associations.

        @return: tuple of (removed associations, remaining associations)
        r   )r   ÚitemsZ	expiresInÚappendÚlen)r   r   r   r   r   r   r	   Úcleanup&   s    

zServerAssocs.cleanupN)	Ú__name__Ú
__module__Ú__qualname__r
   r   r   r   r   r   r   r   r   r	   r   	   s   r   c                   @   sb   e Zd Z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d„ Zdd„ ZdS )ÚMemoryStorezcIn-process memory store.

    Use for single long-running processes.  No persistence supplied.
    c                 C   s   i | _ i | _d S r   ©Úserver_assocsÚnoncesr   r   r   r	   r
   :   s    zMemoryStore.__init__c                 C   s8   z| j | W S  ty2   tƒ  }| j |< | Y S 0 d S r   )r   r   r   )r   Ú
server_urlr   r   r   r	   Ú_getServerAssocs>   s
    zMemoryStore._getServerAssocsc                 C   s   |   |¡}| t |¡¡ d S r   )r"   r   ÚcopyÚdeepcopy)r   r!   r   r   r   r   r	   ÚstoreAssociationE   s    
zMemoryStore.storeAssociationNc                 C   s(   |   |¡}|d u r| ¡ S | |¡S d S r   )r"   r   r   ©r   r!   r   r   r   r   r	   ÚgetAssociationI   s    
zMemoryStore.getAssociationc                 C   s   |   |¡}| |¡S r   )r"   r   r&   r   r   r	   ÚremoveAssociationP   s    
zMemoryStore.removeAssociationc                 C   sP   t |t ¡  ƒtjkrdS t|ƒt|ƒt|ƒf}|| jv r>dS d | j|< dS d S r   )ÚabsÚtimer   ÚSKEWÚstrÚintr    )r   r!   Ú	timestampZsaltÚanoncer   r   r	   ÚuseNonceT   s    

zMemoryStore.useNoncec                 C   sV   t   ¡ }g }| j ¡ D ]$}t|d | ƒtjkr| |¡ q|D ]}| j|= q@t|ƒS )Né   )r*   r    Úkeysr)   r   r+   r   r   )r   ÚnowZexpiredr/   r   r   r	   ÚcleanupNonces_   s    
zMemoryStore.cleanupNoncesc                 C   sT   g }d}| j  ¡ D ]*\}}| ¡ \}}||7 }|s| |¡ q|D ]}| j |= qB|S )Nr   )r   r   r   r   )r   Zremove_urlsZremoved_assocsr!   r   ÚremovedÚ	remainingr   r   r	   ÚcleanupAssociationsk   s    
zMemoryStore.cleanupAssociationsc                 C   s   | j |j ko| j|jkS r   r   ©r   Úotherr   r   r	   Ú__eq__y   s    
ÿzMemoryStore.__eq__c                 C   s
   | |k S r   r   r8   r   r   r	   Ú__ne__}   s    zMemoryStore.__ne__)N)r   r   r   Ú__doc__r
   r"   r%   r'   r(   r0   r4   r7   r:   r;   r   r   r   r	   r   4   s   
r   )r<   Zopenid.storer   r#   r*   Úobjectr   r   r   r   r   r	   Ú<module>   s
   +