CasperSecurity
o
_�Kj� � @ sR d dl mZ d dlZd dlmZ d dlZd dlZd dl Z d dl
Z
d dlZd dlZd dl
Z
d dlZd dlmZ d dlmZ d dlmZ d dlZd dlmZ d dlmZ d dlmZ d d lmZ d
dlm Z d
dl!m"Z" d
d
l!m#Z# ej$r�d dl%Z%d dl&m'Z' d dl&m(Z( d dl&m)Z) d
dl*m+Z+ G dd� dej,�Z-d�dd�Z.d�dd�Z/d�d!d"�Z0d�d$d%�Z1ej2 &d�d�d+d,��Z3ej2 -d�d�d0d,��Z3 &d�d�d1d,�Z3d�d9d:�Z4ej5d;gd<d=e4d&d&d>�Z6G d?d@� d@�Z7ej8e7d&dA�Z9ej:dBej;d-ej<f dC�Z=d�dDdE�Z>G dFdG� dGej?�Z@d�dIdJ�ZAej5dKdLgdMdNd&d=eAdO�ZBd�dQdR�ZCej5dSgdTd=eCdU�ZDd�dVdW�ZEej5dXdYgejFd&d=dZ�d[d&d=eEd\�ZGG d]d^� d^e@�ZHd�d`da�ZId�d�dcdd�ZJd�dgdh�ZKG didj� djejL�ZMd�dkdl�ZNG dmdn� dnejF�ZOejPdodpdq�ejQdrdsdtdudv�ejQdwdxdydzdv�ejQd{eM� d|d&d}�ejQd~ejFd&d=d&d�eNd=d�d��ejQd�dd�dv�ejQd�dd�dv�ejQd�d&d�dv�ejQd�deO� d�e jRjS�d��d��ejQd�deO� d�e jRjS�d��d��e9d�d�d�������������ZTeTjU�Vd eD� ejPd�d�dq�e>d�d�d����ZWejPd�d�dq�ejQd�d�e�Xd��d�d�d��ejQd�d&d�d��e>d�d�d������ZYeHd�d�d��ZZd�d�d��Z[e\d�k�r'e[� dS dS )�� )�annotationsN)�update_wrapper)�
itemgetter)�
ModuleType)�ParameterSource)�
run_simple)�is_running_from_reloader)�
import_string� )�current_app)�get_debug_flag)�get_load_dotenv)�
StartResponse)�WSGIApplication)�WSGIEnvironment��Flaskc @ s e Zd ZdZdS )�NoAppExceptionz3Raised if an application cannot be found or loaded.N)�__name__�
__module__�__qualname__�__doc__� r r �</opt/hikvison/venv/lib/python3.10/site-packages/flask/cli.pyr % s r �moduler �returnr c s* ddl m� dD ]}t| |d�}t|� �r| S q� fdd�| j�� D �}t|�dkr0|d S t|�dkrCtd| j� d | j� d
���dD ]B}t| |d�}t �
|�r�z|� }t|� �r`|W S W qE ty� } zt|�sn� td|� d
| j� d| j� d|� d� �|�d}~ww qEtd| j� d | j� d���)zwGiven a module instance this tries to find the best possible
application in the module or raises an exception.
r
r )�app�applicationNc s g | ] }t |� �r|�qS r )�
isinstance)�.0�vr r r �
<listcomp>7 s z!find_best_app.<locals>.<listcomp>r z0Detected multiple Flask applications in module 'z'. Use 'z":name' to specify the correct one.)�
create_app�make_appzDetected factory 'z
' in module 'z1', but could not call it without arguments. Use '�:z(args)' to specify arguments.z7Failed to find Flask application or factory in module 'z:name' to specify one.)
� r �getattrr �__dict__�values�lenr r �inspect�
isfunction� TypeError�_called_with_wrong_args)r � attr_namer �matches�app_factory�er r r �
find_best_app) s^
����
�����������r2 �f�t.Callable[..., Flask]�boolc C sF t �� d }z|dur|jj| ju rW ~dS |j}|dusW ~dS ~w )z�Check whether calling a function raised a ``TypeError`` because
the call failed or because something in the factory raised the
error.
:param f: The function that was called.
:return: ``True`` if the call failed.
� NFT)�sys�exc_info�tb_frame�f_code�__code__�tb_next)r3 �tbr r r r- ^ s ��
r- �app_name�strc
C s� ddl m} ztj|�� dd�j}W n ty" td|�d��d�w t|tj �r1|j
}g }i }nDt|tj�rmt|jtj �sFtd|�d ���|jj
}zd
d� |j
D �}dd
� |jD �}W n tyl td|�d ��d�w td|�d���zt| |�}W n ty� } z
td|�d| j�d ��|�d}~ww t�|�r�z ||i |��} W n ty� } zt|�s�� td|�d| j�d��|�d}~ww |} t| |�r�| S td| j� d|� d���)z�Check if the given string is a variable name or a function. Call
a function to get the app instance, or return the variable directly.
r
r �eval)�modezFailed to parse z' as an attribute name or function call.Nz*Function reference must be a simple name: �.c S s g | ]}t �|��qS r )�ast�literal_eval)r �argr r r r! � s z&find_app_by_string.<locals>.<listcomp>c S s&