HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/__pycache__/flask_bouncer.cpython-310.pyc
o

��!^��@s�ddlmZddlmZmZmZmZddlm	Z	ddl
mZddlm
Z
ddlTe	dd��Zd	d
�Zdd�ZeZGd
d�de�Zdd�Zdd�ZGdd�de�ZdS)���wraps)�request�g�current_app�_app_ctx_stack)�
LocalProxy)�	Forbidden)�Ability)�*cCs
tjdS)N�bouncer)r�
extensions�rr�F/home/arjun/projects/env/lib/python3.10/site-packages/flask_bouncer.py�<lambda>
s
rcCsNdt_t��}t|�}t��|_tj|_|�	||�r%d�
|||�}t|��dS)NTz#{0} does not have {1} access to {2})r�_authorized�_bouncer�get_current_userr
�get_authorization_method�authorization_method�
alias_actions�aliased_actions�cannot�formatr	)�action�subject�current_user�ability�msgrrr�ensures
�rcCs4dt_t��}t|�}t��|_tj|_|�	||�S�NT)
rrrrr
rrrr�can)rrrrrrrr!s
r!c@seZdZdd�Zdd�ZdS)�	ConditioncCs||_||_dS�N�rr)�selfrrrrr�__init__*s
zCondition.__init__cCst|j|j�dSr#)rrr�r%rrr�test.szCondition.testN)�__name__�
__module__�__qualname__r&r(rrrrr"(sr"cs��fdd�}|S)Ncs"d�_t�����fdd��}|S)NTcst������|i|��Sr#)r"r(��args�kwargs)r�frrr�decorated_function6sz7requires.<locals>.decorator.<locals>.decorated_function)�_explict_rule_setr�r/r0r$�r/r�	decorator3szrequires.<locals>.decoratorr)rrr4rr$r�requires2sr5cst���fdd��}|S)Ncsdt_�|i|��Sr )rrr,r3rrr0?sz.skip_authorization.<locals>.decorated_functionrr2rr3r�skip_authorization>sr6c@s�eZdZdZgd�Zd#dd�Zd#dd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zedd��Zejdd��Zdd�Zdd�Zdd �Zd!d"�ZdS)$�BouncerzYThis class is used to control the Abilities Integration to one or more Flask applications)�get�put�patch�post�delete�indexNcKsVd|_|��|_d|_t�|_t�|_|j|_d|_	|dur)|j
|fi|��dSdSr#)�authorization_method_callback�default_alias_actions�_alias_actions�_authorization_method�list�flask_classy_classes�
explict_rules�default_user_loaderr�app�init_app�r%rFr.rrrr&Ls
�zBouncer.__init__cCs8|dur|S|jdur|jStj}|dur|jStd��)zBHelper method that implements the logic to look up an application.NzZApplication not registered on Bouncer instance and no application bound to current context)rF�stack�top�RuntimeError)r%�
reference_app�ctxrrr�get_appZs
zBouncer.get_appcKs>||_|��|j�|j�|�dd�r|j�|j�dSdS)zv Initializes the Flask-Bouncer extension for the specified application.

        :param app: The application.
        �ensure_authorizationFN)rF�_init_extension�before_request�check_implicit_rulesr8�
after_request�check_authorizationrHrrrrGls�zBouncer.init_appcCs&t|jd�st�|j_||jjd<dS)Nr
r)�hasattrrF�dictr
r'rrrrPzs
zBouncer._init_extensioncCsttd�st�tjst�|S)zBchecks that an authorization call has been made during the requestr)rUrr	r)r%�responserrrrT�s

zBouncer.check_authorizationcsT|��sdS|��rdStj�d�\�}�fdd�|jD�d}t||j���dS)z� if you are using flask classy are using the standard index,new,put,post, etc ... type routes, we will
            automatically check the permissions for you
        N�:csg|]	}|j�kr|�qSr�r)��.0�classy_class��
class_namerr�
<listcomp>�sz0Bouncer.check_implicit_rules.<locals>.<listcomp>r)	�"request_is_managed_by_flask_classy�method_is_explictly_overwrittenr�endpoint�splitrCr"�__target_model__r()r%r�clazzrr]rrR�szBouncer.check_implicit_rulescCs tjtj}t|d�o|jduS)Nr1T)r�view_functionsrrbrUr1)r%�	view_funcrrrra�sz'Bouncer.method_is_explictly_overwrittencsNtjdurdSdtjvrdStj�d�\�}t�fdd�|jD��o&||jvS)NFrXc3s�|]}�|jkVqdSr#rYrZr]rr�	<genexpr>�s�z=Bouncer.request_is_managed_by_flask_classy.<locals>.<genexpr>)rrbrc�anyrC�special_methods)r%rrr]rr`�s

�z*Bouncer.request_is_managed_by_flask_classycCs(ttd�rtjSttd�rtjStd��)Nr�userz#Excepting current_user on flask's g)rUrrrk�	Exceptionr'rrrrE�s


zBouncer.default_user_loadercCs
||_|S)zP
        Use this method decorator to overwrite the default user loader
        )r�r%�valuerrr�user_loader�szBouncer.user_loadercCs|jSr#�r@r'rrrr�szBouncer.alias_actionscCs
||_dS)z$if you want to override your actionsNrprmrrrr�s
cCs ttttgttttgtt	t
giSr#)�READ�INDEX�SHOW�GET�CREATE�NEW�PUT�POST�UPDATE�EDIT�PATCHr'rrrr?�s

�zBouncer.default_alias_actionscGs|j�|�dSr#)rC�extend)r%�
classy_routesrrr�monitor�szBouncer.monitorcCs||_|jS)z:
        the callback for defining user abilities
        )rArmrrrr�szBouncer.authorization_methodcCs|jdur|jStd��)Nz'Expected authorication method to be set)rArlr'rrrr�s
z Bouncer.get_authorization_methodr#)r)r*r+�__doc__rjr&rNrGrPrTrRrar`rEro�propertyr�setterr?r~rrrrrrr7Fs*

	

r7N)�	functoolsr�flaskrrrrrI�werkzeug.localr�werkzeug.exceptionsr	rr
�bouncer.constantsrrr!�bounce�objectr"r5r6r7rrrr�<module>s