U a$}@sddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddl mZddlZddlmZddlmZdd lmZdd lmZdd lmZz ddlZWnek rdZYnXz ddlZWnek rdZYnXGd d d ejZddZdwddZddZddZ ddZ!dxddZ"ddZ#ej$dgdde#ddd Z%Gd!d"d"Z&Gd#d$d$Z'ej(e'dd%Z)d&d'Z*Gd(d)d)ej+Z,Gd*d+d+e,Z-d,d-Z.dyd.d/Z/d0d1Z0Gd2d3d3ej1Z2d4d5Z3Gd6d7d7ej4Z5ej6d8d9d:ej7d;dd?ej7d@dAdBdCd?ej7dDe2dEdFej7dGej4ddddHe3ddIdJej7dKddLd?ej7dMddNd?ej7dOddPd?ej7dQddRd?ej7dSde5dTej8j9dUdVe)dWdXZ:ej6dYdZd:e*dd[d\d]Z;ej6d^d_d:ej7d`daeddidjdkZ?e-dlj@ejAdmkrTdnndoejAdmkrfdpndqdrdsZBdd[dtduZCeDdvkreCdS)zN)update_wrapper) attrgetter)Lock)Thread) import_string) current_app)get_debug_flag)get_env)get_load_dotenvc@seZdZdZdS)NoAppExceptionz3Raised if an application cannot be found or loaded.N)__name__ __module__ __qualname____doc__rrJC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-e702oxwa\flask\cli.pyr !sr cs.ddlmdD]"}t||d}t|r|Sqfdd|jD}t|dkr`|dSt|dkrtd|jd |jd d D]}t||d}t |rz"t ||}t|r|WSWqt k r t |std |d |jd|jd|d YqXqtd|jd |jddS)zwGiven a module instance this tries to find the best possible application in the module or raises an exception. rFlask)appZ applicationNcsg|]}t|r|qSr) isinstance).0vrrr 3s z!find_best_app..rz/Detected multiple Flask applications in module z. Use 'FLASK_APP=z":name' to specify the correct one.) create_appZmake_appzDetected factory in module z;, but could not call it without arguments. Use "FLASK_APP=':z(args)'" to specify arguments.z6Failed to find Flask application or factory in module z:name' to specify one.)rgetattrr__dict__valueslenr r inspect isfunction call_factory TypeError_called_with_wrong_args) script_infomodule attr_namermatches app_factoryrrr find_best_app%s8           r,cCst|}|dkrgn|}|dkr&in|}d|jkrHtdt||d<|st|jdkrtt|j j tj j krtdt| ||||S)zTakes an app factory, a ``script_info` object and optionally a tuple of arguments. Checks for the existence of a script_info argument and calls the app_factory depending on that and the arguments provided. Nr'ziThe 'script_info' argument is deprecated and will not be passed to the app factory function in Flask 2.1.rzqScript info is deprecated and will not be passed as the single argument to the app factory function in Flask 2.1.)r" signature parameterswarningswarnDeprecationWarningr!nextiterr default Parameteremptyappend)r'r+argskwargssigrrrr$Ys*    r$cCsDtd}z.|dk r4|jj|jkr,WdS|j}qWdS~XdS)zCheck 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)sysexc_infotb_framef_code__code__tb_next)ftbrrrr&zs r&c Csddlm}ztj|ddj}Wn$tk rHtd|dYnXt|tj rf|j }d}}nt|tj rt|j tj std|d |j j }z$d d |j D}d d |jD}Wqtk rtd|d YqXntd|dzt||}Wn.tk r0td|d|jd YnXt|rzt||||} Wn:tk rt|sntd|d|jdYnXn|} t| |r| Std|jd|ddS)zCheck if the given string is a variable name or a function. Call a function to get the app instance, or return the variable directly. rreval)modezFailed to parse z' as an attribute name or function call.Nz*Function reference must be a simple name: .cSsg|]}t|qSr)ast literal_eval)rargrrrrsz&find_app_by_string..cSsi|]}|jt|jqSr)rIrGrHvalue)rkwrrr sz&find_app_by_string..z-Failed to parse arguments as literal values: zFailed to find attribute z in z The factory rz2 could not be called with the specified arguments.z1A valid Flask application was not obtained from 'rz'.)rrrGparsestripbody SyntaxErrorr rNameidZCallfuncr8keywords ValueErrorrAttributeErrorr r"r#r$r%r&) r'r(app_namerexprnamer8r9attrrrrrfind_app_by_strings^             r[cCstj|}tj|\}}|dkr(|}tj|dkrDtj|}g}tj|\}}||tjtj |dsHq|qHt jd|krt j d|d |dddS)zGiven a filename this will try to calculate the python path, add it to the search path and return the actual module name that is expected. z.py__init__z __init__.pyrrFN) ospathrealpathsplitextbasenamedirnamesplitr7existsjoinr<insert)r_fnameext module_namerYrrrprepare_imports   rkTc Csd}z t|WnXtk rhtdjrHtd|dtn|r^td|dnYdSYnXtj|}|dkrt ||St |||SdS)NTr;zWhile importing z, an ImportError was raised: zCould not import rF) __import__ ImportErrorr<r=rAr traceback format_excmodulesr,r[)r'rjrWraise_if_not_found__traceback_hide__r(rrr locate_apps    rscCsV|r |jrdSddl}ddlm}tjdtd|d|j|jd| dS)Nrr) __version__Python z Flask z Werkzeug )color) Zresilient_parsingwerkzeugrrtclickechoplatformpython_versionrvexit)ctxparamrJrwrtrrr get_versions  rz --versionzShow the flask versionF)help expose_valuecallbackis_flagZis_eagerc@s:eZdZdZd ddZddZddZd d Zd d ZdS)DispatchingAppaSpecial application that dispatches to a Flask application which is imported by name in a background thread. If an error happens it is recorded and shown as part of the WSGI handling which in case of the Werkzeug debugger means that it shows up in the browser. NcCsL||_d|_t|_d|_|dkr2tjddk}|r@|n| dS)NWERKZEUG_RUN_MAINtrue) loader_appr_lock_bg_loading_exc_infor^environget_load_unlocked_load_in_background)selfruse_eager_loadingrrrr\7s zDispatchingApp.__init__cs$fdd}t|dd}|dS)Nc sFd}j2z Wntk r6t_YnXW5QRXdSNT)rr Exceptionr<r=r)rrrrr _load_appFs  z5DispatchingApp._load_in_background.._load_appr)targetr8)rstart)rrtrrrrEs  z"DispatchingApp._load_in_backgroundcCs d}|j}|dk rd|_|dSr)r)rrrr=rrr_flush_bg_loading_exceptionQs z*DispatchingApp._flush_bg_loading_exceptioncCsd}||_}d|_|Sr)rrr)rrrrvrrrrXszDispatchingApp._load_unlockedc Csdd}|jdk r|||S||j2|jdk r<|j}n|}|||W5QRSQRXdSr)rrrr)rrZstart_responserrrrrr__call__^s   zDispatchingApp.__call__)N) r rrrr\rrrrrrrrr0s   rc@s"eZdZdZdddZddZdS) ScriptInfoaHelper object to deal with Flask applications. This is usually not necessary to interface with as it's used internally in the dispatching to click. In future versions of Flask this object will most likely play a bigger role. Typically it's created automatically by the :class:`FlaskGroup` but you can also manually create it and pass it onwards as click object. NTcCs.|ptjd|_||_i|_||_d|_dS)NZ FLASK_APP)r^rrapp_import_pathrdataset_debug_flag _loaded_app)rrrrrrrr\ts zScriptInfo.__init__cCsd}|jdk r|jS|jdk r,t||j}nh|jrjtd|jddgdd\}}t|}t|||}n*dD]$}t|}t||ddd}|rnqqn|std |j rt |_ ||_|S) zLoads the Flask app (if not yet loaded) and returns it. Calling this multiple times will just result in the already loaded app to be returned. TNz :(?![\\/])rr;)zwsgi.pyzapp.pyF)rqzCould not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.) rrr$rrerdrkrsr rr debug)rrrrr_rY import_namerrrload_apps2   zScriptInfo.load_app)NNT)r rrrr\rrrrrrks r)Zensurecstjfdd}t|S)zWraps a callback so that it's guaranteed to be executed with the script's application context. If callbacks are registered directly to the ``app.cli`` object then they are wrapped with this function by default unless it's disabled. c s<|t |jf||W5QRSQRXdSN) ensure_objectrrZ app_contextZinvoke)Z__ctxr8r9rBrr decoratorsz"with_appcontext..decorator)rxZ pass_contextr)rBrrrrwith_appcontextsrc@s eZdZdZddZddZdS)AppGroupaThis works similar to a regular click :class:`~click.Group` but it changes the behavior of the :meth:`command` decorator so that it automatically wraps the functions in :func:`with_appcontext`. Not to be confused with :class:`FlaskGroup`. cs"ddfdd}|S)zThis works exactly like the method of the same name on a regular :class:`click.Group` but it wraps callbacks in :func:`with_appcontext` unless it's disabled by passing ``with_appcontext=False``. rTcs$r t|}tjjf|Sr)rrxGroupcommandrr8r9rZ wrap_for_ctxrrrsz#AppGroup.command..decorator)pop)rr8r9rrrrrs zAppGroup.commandcOs |dttjj|f||S)zThis works exactly like the method of the same name on a regular :class:`click.Group` but it defaults the group class to :class:`AppGroup`. cls) setdefaultrrxrgroup)rr8r9rrrrs zAppGroup.groupN)r rrrrrrrrrrsrcsJeZdZdZdddZddZfdd Zfd d Zfd d ZZ S) FlaskGroupa<Special subclass of the :class:`AppGroup` group that supports loading more commands from the configured Flask app. Normally a developer does not have to interface with this class but there are some very advanced use cases for which it makes sense to create an instance of this. see :ref:`custom-scripts`. :param add_default_commands: if this is True then the default run and shell commands will be added. :param add_version_option: adds the ``--version`` option. :param create_app: an optional callback that is passed the script info and returns the loaded app. :param load_dotenv: Load the nearest :file:`.env` and :file:`.flaskenv` files to set environment variables. Will also change the working directory to the directory containing the first file found. :param set_debug_flag: Set the app's debug flag based on the active environment .. versionchanged:: 1.0 If installed, python-dotenv will be used to load environment variables from :file:`.env` and :file:`.flaskenv` files. TNcKsvt|ddpd}|r"|ttj|fd|i|||_||_||_|rl| t | t | t d|_ dS)NparamsrF)listrr7version_optionrr\r load_dotenvr add_command run_command shell_commandroutes_command_loaded_plugin_commands)rZadd_default_commandsrZadd_version_optionrrextrarrrrr\s     zFlaskGroup.__init__cCs`|jr dSz ddl}Wntk r2d|_YdSX|dD]}|||jq>d|_dS)NrTzflask.commands)r pkg_resourcesrmiter_entry_pointsrloadrY)rreprrr_load_plugin_commands s z FlaskGroup._load_plugin_commandsc s|t||}|dk r"|S|t}z|j||WStk r~}z tj d| ddddW5d}~XYnXdSNzError:  Tred)errfg) rsuper get_commandrrrclir rxsechoformat_message)rr}rYrinfoe __class__rrrs zFlaskGroup.get_commandc s|tt|}|t}z||j|Wnjt k rz}z t j d| ddddW5d}~XYn.t k rt j tddddYnXt|Sr)rsetr list_commandsrrupdaterrr rxrrrrnrosorted)rr}rrrrrrr,s , zFlaskGroup.list_commandscs^dtjd<t|jrt|d}|dkrtd|||rPtd|||sbtd||||f|jd<n|r|s|std|||S)zThe ``--key`` option must be specified when ``--cert`` is a file. Modifies the ``cert`` param to be a ``(cert, key)`` pair if needed. certrNz.When "--cert" is "adhoc", "--key" is not used.z:When "--cert" is an SSLContext object, "--key is not used.z "--cert" must also be specified.zRequired when using "--cert".)rrrrrrxr)r}r~rJrZis_adhocZ is_contextrrr _validate_keys,  rcs eZdZdZfddZZS)SeparatedPathTypezClick option type that accepts a list of values separated by the OS's path separator (``:``, ``;`` on Windows). Each value is validated as a :class:`click.Path` type. cs(||}tjfdd|DS)Ncsg|]}|qSrr)ritemr}r~Z super_convertrrrsz-SeparatedPathType.convert..)Zsplit_envvar_valuerr)rrJr~r}itemsrrrrs zSeparatedPathType.convert)r rrrrrrrrrrsrrunzRun a development server.)Z short_helpz--hostz-hz 127.0.0.1zThe interface to bind to.)r4rz--portz-pizThe port to bind to.z--certz(Specify a certificate file to use HTTPS.)typerz--keyrz2The key file to use when specifying a certificate.)rrrrz--reload/--no-reloadzVEnable or disable the reloader. By default the reloader is active if debug is enabled.z--debugger/--no-debuggerzVEnable or disable the debugger. By default the debugger is active if debug is enabled.z--eager-loading/--lazy-loadingzaEnable or disable eager loading. By default eager loading is enabled if the reloader is disabled.z --with-threads/--without-threadsz!Enable or disable multithreading.z --extra-fileszMExtra files that trigger a reload on change. Multiple paths are separated by rF)r4rrc Csft} |dkr| }|dkr| }tt| |j|t|j|d} ddlm} | ||| |||||ddS)aRun a local development server. This server is for development purposes only. It does not provide the stability, security, or performance of production WSGI servers. The reloader and debugger are enabled by default if FLASK_ENV=development or FLASK_DEBUG=1. N)rr) run_simple)Z use_reloaderZ use_debuggerZthreaded ssl_context extra_files)r rr rrrZwerkzeug.servingr) rhostportreloadZdebuggerrZ with_threadsrrrrrrrrr s$9 rshellzRun a shell in the app context.)returnc Cs ddl}ddlm}|jj}dtjdtjd|jd|j d |j }i}t j d }|rt j|rt|}tt||d |W5QRX||ttd d}|dk rzddl}dd lm} Wntk rYnX|| |j||j||ddS)a:Run an interactive Python shell in the context of a given Flask application. The application will populate the default namespace of this shell according to its configuration. This is useful for executing small snippets of management code without having to manually configure the application. rNr)_app_ctx_stackruz on z App: z [z ] Instance: Z PYTHONSTARTUPexec__interactivehook__) Completer)bannerlocal)codeglobalsrtoprr<versionrzrrZ instance_pathr^rrr_ropenrDcompilereadrZmake_shell_contextrreadline rlcompleterrrmZ set_completerZcompleteZinteract) rrrrr}ZstartuprBZinteractive_hookrrrrrr]s*  *    rZrouteszShow the routes for the app.z--sortz-s)endpointmethodsrulematchrzgMethod to sort routes by. "match" is the order that Flask will match routes when dispatching a request.)rr4rz --all-methodszShow HEAD and OPTIONS methods.)rr)sort all_methodsrc s.ttj}|s tddSt|r*dnd|dkrJt|t|d}n|dkrbt|dd d}fd d |D}d }t d d|Dt dd|Dt dd|Df}dd t ||D}dj |}t|j | t|j dd|Dt ||D]&\}}t| |j ||jqdS)z6Show all registered routes with endpoints and methods.zNo routes were registered.Nr)HEADOPTIONS)rr)keyrcSs t|jSr)rr)rrrrz routes_command..cs g|]}dt|jqS)z, )rfrrrrZignored_methodsrrrsz"routes_command..)ZEndpointZMethodsZRulecss|]}t|jVqdSr)r!rrrrr sz!routes_command..css|]}t|VqdSr)r!)rrrrrrscss|]}t|jVqdSr)r!rrrrrrscSsg|]\}}tt||qSr)maxr!)rhwrrrrsz"{{0:<{0}}} {{1:<{1}}} {{2:<{2}}}css|]}d|VqdS)-Nr)rwidthrrrrs)rrZurl_mapZ iter_rulesrxryrrrrzipformatrNrrrstrip) rrrulesZ rule_methodsheadersZwidthsrowrrrrrrs.   raA general utility script for Flask applications. Provides commands from Flask, extensions, and the application. Loads the application defined in the FLASK_APP environment variable, or from a wsgi.py file. Setting the FLASK_ENV environment variable to 'development' will enable debug mode.  {prefix}{cmd} FLASK_APP=hello.py {prefix}{cmd} FLASK_ENV=development {prefix}flask run posixexportrz$ z> )cmdprefix)rcCs8ttjddkrtdttjtj ddddS)NrzUsing the `flask` cli with Click 7 is deprecated and will not be supported starting with Flask 2.1. Please upgrade to Click 8 as soon as possible.r)r8) intrxrtr/r0r1rrr<argvrrrrrs r__main__)NN)T)N)ErGr"r^rzrr<rnr/ functoolsroperatorr threadingrrrxZwerkzeug.utilsrr rZhelpersr r r rrmrZ UsageErrorr r,r$r&r[rkrsrOptionrrrZmake_pass_decoratorZpass_script_inforrrrrrrZ ParamTyperrrrroptionr_pathseprrZChoicestrboolrr%rYrrr rrrrs             4 !K  ;@{ 9,  $ 1  $