o
    gëf  ã                   @   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   úV/var/www/html/humari/django-venv/lib/python3.10/site-packages/openid/store/memstore.pyÚ__init__	   ó   
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 dS  ty   Y dS w ©NFT)r   ÚKeyErrorr   r   r   r	   Úremove   s   
ýÿzServerAssocs.removec                 C   s0   d}| 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)r   ÚvaluesÚissued)r   Úbestr   r   r   r	   r      s   €zServerAssocs.bestc                 C   sR   g }| j  ¡ D ]\}}| ¡ dkr| |¡ q|D ]}| j |= qt|ƒt| j ƒfS )zoRemove expired associations.

        @return: tuple of (removed associations, remaining associations)
        r   )r   Ú	iteritemsÚgetExpiresInÚ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
   9   s   
zMemoryStore.__init__c                 C   s4   z| j | W S  ty   tƒ  }| j |< | Y S w 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	   ÚstoreAssociationD   s   
zMemoryStore.storeAssociationNc                 C   s$   |   |¡}|d u r| ¡ S | |¡S r   )r$   r   r   ©r   r#   r   r   r   r   r	   ÚgetAssociationH   s   

zMemoryStore.getAssociationc                 C   s   |   |¡}| |¡S r   )r$   r   r(   r   r   r	   ÚremoveAssociationO   s   

zMemoryStore.removeAssociationc                 C   sL   t |t ¡  ƒtjkrdS t|ƒt|ƒt|ƒf}|| jv rdS d | j|< dS r   )ÚabsÚtimer   ÚSKEWÚstrÚintr"   )r   r#   Ú	timestampÚsaltÚanoncer   r   r	   ÚuseNonceS   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"   Úiterkeysr+   r   r-   r   r   )r   ÚnowÚexpiredr2   r   r   r	   ÚcleanupNonces^   s   
€
zMemoryStore.cleanupNoncesc                 C   sT   g }d}| j  ¡ D ]\}}| ¡ \}}||7 }|s| |¡ q	|D ]}| j |= q!|S )Nr   )r!   r   r   r   )r   Úremove_urlsÚremoved_assocsr#   r   ÚremovedÚ	remainingr   r   r	   ÚcleanupAssociationsj   s   
€
zMemoryStore.cleanupAssociationsc                 C   s   | j |j ko| j|jkS r   r    ©r   Úotherr   r   r	   Ú__eq__x   s   
ÿzMemoryStore.__eq__c                 C   s
   | |k S r   r   r>   r   r   r	   Ú__ne__|   r   zMemoryStore.__ne__r   )r   r   r   Ú__doc__r
   r$   r'   r)   r*   r3   r8   r=   r@   rA   r   r   r   r	   r   4   s    
r   )rB   Úopenid.storer   r%   r,   Úobjectr   r   r   r   r   r	   Ú<module>   s    ,