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/buyercall/buyercall/lib/__pycache__/util_rest.cpython-310.pyc
o

we��@s�ddlmZddlmZmZmZmZddlm	Z	ddl
mZmZe�Z
edd��Zedd��Zedd��Zed	d��Zed
d��Zgd�Zdd
�Zdd�Zdd�Zdd�Zidddfdd�Zdd�Zdd�ZGdd�d�ZdS) ���wraps)�
make_response�request�jsonify�current_app)�current_user)�Local�
LocalProxycC�tjS�N)�_local�partnership_account�rr�9/home/arjun/projects/buyercall/buyercall/lib/util_rest.py�<lambda>
�rcCrr)r
�is_partnership_accountrrrrrrcCrr)r
�is_partnershiprrrrrrcCrr)r
�partnershiprrrrrrcCrr)r
�api_token_idrrrrrr)�DELETE�POST�PUTcsdd����fdd�}|S)NcSs$t|dd�}d�||�|jd<|S)Nz
��<Bearer realm="buyercall", error="{}", error_description="{}"�WWW-Authenticate)r�format�headers)�text�code�responserrr�
make_errors
�zrest_method.<locals>.make_errorc
s�ddlm}m}m}tj�dd��d�}t|�dks |ddkr%�dd	�S|d
�	�}|�
|�}|rR|�|�}|t_
|r@|t_n|�|�}	|	durM|	t_n
�dd�S�dd�S�|i|��S)
Nr��PartnershipAccount�ApiToken�Partnership�	Authorize�� ��BearerzInvalid authorization method�invalid_request�zInvalid credentials�
invalid_token)�'buyercall.blueprints.partnership.modelsr$r%r&rr�get�split�len�strip�check_token� get_partnership_account_by_tokenr
rr�get_partnership_by_tokenr)
�args�kwargsr$r%r&�header�tokenrrr�r"�wrappedrr�wrappers.�


��zrest_method.<locals>.wrapperr)r<r=rr;r�rest_methodsr>cCs,ddi}t|�}d|_d�||�|jd<|S)N�messagezAuthentication error.rrr)r�status_coderr)rr r?�resprrr�authenticate@s�rBcCsddi}t|�}d|_|S)Nr?zSError processing request. POST, PUT and DELETE requests are disabled in DEBUG mode.r)rr@)r?rArrr�unsupported_in_debug_modeLsrCc�t���fdd��}|S)Ncsddlm}m}m}dt_dt_tj�	dd��
d�}tj�	dd���}tj
�	dd�dur8tjtvr8|d	kr8t�St|�d
ksD|ddkrItdd
�S|d��}|�|�}|dur{|�|�}	|t_|	durk|	t_dt_n|�|�}
|
durz|
t_dt_ntdd�S�|i|��S)Nrr#Fr'r(r)�
Documentation�DEBUG�truer*r+zInvalid authorization method.r,r-TzInvalid credentials.r.)r/r$r%r&r
rrrrr0r1�lower�app�config�method�blocked_debug_request_methodsrCr2rBr3r4r5rrr6r)r7r8r$r%r&r9�
api_doc_debugr:r�retrieved_partnership_account�retrieved_partnership��frr�	decoratedUs4




�
z requires_auth.<locals>.decoratedr)rQrRrrPr�
requires_authTs#rS��r(TcCst||||d��S)N��datar@r?�success)rrUrrr�api_jsonify|s�rXcrD)Ncs"tjs
tdddd�S�|i|��S)Nr�UnauthorizedF�r@r?rW�r�is_authenticatedrX)r7r8rPrr�decorated_function�sz)auth_required.<locals>.decorated_functionr)rQr]rrPr�
auth_required�sr^crD)z
    is there a valid user logged in?

    :param *func: The function which the decorator being used
    :return: Function
    cs.tjsd}d}d}t|||d�S�|i|��S)Ni�Fz3You do not have permission to access this resource.rZr[)r7r8r@rWr?��funcrrr]�sz.api_login_required.<locals>.decorated_functionr)r`r]rr_r�api_login_required�srac@seZdZddd�ZdS)�BlueprintMixinFNcKs�z3|r|dvr|j�tj��d��|��d�dd|i|��WS|j�tj��|jd�dd|i|��WS|jdd|i|��YS)N)�in�outr0rc�many�defaultr)�serializersr0rrKrH)�selfre�keyr8rrr�get_serializer_class�s0*z#BlueprintMixin.get_serializer_class)FN)�__name__�
__module__�__qualname__rjrrrrrb�srbN)�	functoolsr�flaskrrrrrI�flask_loginr�werkzeug.localr	r
r
�rest_partnership_account�rest_is_partnership_account�rest_is_partnership�rest_partnership�rest_api_token_idrLr>rBrCrSrXr^rarbrrrr�<module>s&*(