U
    >i                     @   s   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d	d	d
ddZd	d	dddeeedddZedddZee dddZd	S )    )Optional)settings)HttpResponseapp_settings)RateLimited)	ratelimit)Rate)import_callableN)keyuserc                C   s&   ddl m} tj| |j|||d d S )Nr   r   )requestconfigactionr   r   )allauth.accountr   _implclearRATE_LIMITS)r   r   r   r   r    r   :/tmp/pip-unpacked-wheel-upujnpc2/allauth/core/ratelimit.pyr      s    r   F)r   r   dry_runraise_exception)r   r   returnc             	   C   s2   ddl m} tj| |j|||||d}|s.dS dS )z
    TODO: We ened to deprecate this module and keep rate limiting internal
    to allauth. This method is using `allauth.account.app_settings` as a
    hard-coded source of settings, which is bad for reusability elsewhere.
    r   r   )r   r   r   r   r   r   r   FT)r   r   r   consumer   )r   r   r   r   r   r   r   usager   r   r   r      s    	r   )r   c              	   C   sh   t jr&t| jdr&ddlm} || S zttjd }t|}W n t	t
fk
r^   tj}Y nX || S )NZheadlessr   )RateLimitResponsez.handler429)r   ZHEADLESS_ENABLEDhasattrallauthZallauth.headless.base.responser   r
   r   ZROOT_URLCONFImportErrorAttributeErrorr   
handler429)r   r   r    r   r   r   respond_4297   s    r!   c                 O   s   t | f||st| S d S )N)r   r!   )r   argskwargsr   r   r   consume_or_429E   s    r$   )typingr   Zdjango.confr   Zdjango.httpr   r   r   Zallauth.core.exceptionsr   Zallauth.core.internalr   r   Zallauth.core.internal.ratelimitr	   Zallauth.utilsr
   r   boolr   r!   r$   r   r   r   r   <module>   s&   