U )._;y@sdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddlmZddlmZddlZddlmZd d lmZd d lmZd d lmZd d lmZd dlmZd dlmZd dlmZd dlmZz ddlZWne k rdZYnXz ddl!Z!Wne k r:dZ!YnXGdddej"Z#ddZ$d|ddZ%ddZ&ddZ'ddZ(d}d d!Z)d"d#Z*ej+d$gd%d&e*ddd'Z,Gd(d)d)e-Z.Gd*d+d+e-Z/ej0e/dd,Z1d-d.Z2Gd/d0d0ej3Z4Gd1d2d2e4Z5d3d4Z6d~d5d6Z7d7d8Z8Gd9d:d:ej9Z:d;d<Z;Gd=d>d>ej<Z=ej>d?d@dAej?dBdCdDdEdFej?dGdHdIdJdFej?dKe:dLdMej?dNejd_d`dAe2dadbZDej>dcdddAej?dedfeEdgdhdidjej?dkddldme2dndoZFe5dpj@ejGdqkrdrndsejGdqkrdtndudvdwZHddxdyZIeJdzkreIdd{dS)z flask.cli ~~~~~~~~~ A simple command line application to run flask apps. :copyright: 2010 Pallets :license: BSD-3-Clause )print_functionN)update_wrapper) attrgetter)Lock)Thread) import_string) getargspec) itervalues)reraise) text_type) 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__rrC:\Users\Miouzora\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\flask/cli.pyr0src s ddlmdD]"}t||d}t|r|Sqfddt|jD}t|dkr`|dSt|dkr~tdj|j d d D]p}t||d}t |rz"t ||}t|r|WSWqt k rt|s؂td j||j d YqXqtd j|j d dS)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 Bs z!find_best_app..rztDetected multiple Flask applications in module "{module}". Use "FLASK_APP={module}:name" to specify the correct one.)module) create_appZmake_appzDetected factory "{factory}" in module "{module}", but could not call it without arguments. Use "FLASK_APP='{module}:{factory}(args)'" to specify arguments.)factoryrznFailed to find Flask application or factory in module "{module}". Use "FLASK_APP={module}:name to specify one.)rgetattrrr __dict__lenrformatrinspect isfunction call_factory TypeError_called_with_wrong_args) script_infor attr_namermatches app_factoryrrr find_best_app4sF           r0rcCs\t|}|j}|j}d|kr*||d|iS|r6||S|sVt|dkrV|dkrV||S|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. r,rN)r argsdefaultsr%)r,r/ argumentsZ args_spec arg_namesZ arg_defaultsrrrr)gsr)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 factory: the factory function that was called :return: true if the call failed NFT)sysexc_infotb_framef_code__code__tb_next)r!tbrrrr+zs r+c Csdddlm}td|}|s,tdj|d|\}}zt||}Wn0tk rv}zt|j dW5d}~XYnXt |r8|rzt dj|d }Wqttfk r}ztd j||d W5d}~XYqXnd }zt|||} WnFtk r4}z&t|std j|||jdW5d}~XYnXn|} t| |rL| Stdj|j|ddS)zChecks if the given string is a variable name or a function. If it is a function, it checks for specified arguments and whether it takes a ``script_info`` argument and calls the function with the appropriate arguments. rrz%^ *([^ ()]+) *(?:\((.*?) *,? *\))? *$z="{name}" is not a valid variable name or function expression.namerNz ({args},))r1z.Could not parse the arguments in "{app_name}".)eapp_namerzc{e} The factory "{app_name}" in module "{module}" could not be called with the specified arguments.)r?r@rzFA valid Flask application was not obtained from "{module}:{app_name}".)rr@)r"rrematchrr&groupsr#AttributeErrorr1r'r(ast literal_eval ValueError SyntaxErrorr)r*r+rr) r,rr@rrBr>r1attrr?rrrrfind_app_by_strings\       rJcCstj|}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__.pyr.N) ospathrealpathsplitextbasenamedirnamesplitappendexistsjoinr6insert)rOfnameext module_namer>rrrprepare_imports   r\TcCsd}z t|WnVtk rftdjrFtdj|tdn|r\tdj|dnYdSYnXtj |}|dkrt ||St |||SdS)NTrMz:While importing "{name}", an ImportError was raised: {tb})r>r<zCould not import "{name}".r=) __import__ ImportErrorr6r7r;rr& traceback format_excmodulesr0rJ)r,r[r@raise_if_not_found__traceback_hide__rrrr locate_apps$    rdcCsT|r |jrdSddl}ddlm}d}tj|t||jd|jd| dS)Nrr) __version__z7Python %(python)s Flask %(flask)s Werkzeug %(werkzeug)s)pythonZflaskwerkzeug)color) Zresilient_parsingrgr"reclickechoplatformpython_versionrhexit)ctxparamvaluergremessagerrr get_versions   rrz --versionzShow the flask versionF)help expose_valuecallbackis_flagZis_eagerc@s:eZdZdZdddZddZddZd d Zd d Zd S)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. FcCs4||_d|_t|_d|_|r(|n|dSN)loader_appr_lock_bg_loading_exc_info_load_unlocked_load_in_background)selfryuse_eager_loadingrrrrK+s zDispatchingApp.__init__cs$fdd}t|dd}|dS)Nc sFd}j2z Wntk r6t_YnXW5QRXdSNT)r{r} Exceptionr6r7r|)rcrrr _load_app6s  z5DispatchingApp._load_in_background.._load_appr)targetr1)rstart)rrtrrrr~5s  z"DispatchingApp._load_in_backgroundcCs$d}|j}|dk r d|_t|dSr)r|r )rrcr7rrr_flush_bg_loading_exceptionAs z*DispatchingApp._flush_bg_loading_exceptioncCsd}||_}d|_|Sr)ryrzr|)rrcrvrrrr}HszDispatchingApp._load_unlockedc Csdd}|jdk r|||S||j2|jdk r<|j}n|}|||W5QRSQRXdSr)rzrr{r})renvironZstart_responsercrrrr__call__Ns   zDispatchingApp.__call__N)F) rrrrrKr~rr}rrrrrrw$s   rwc@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)rNrgetapp_import_pathr dataset_debug_flag _loaded_app)rrr rrrrrKds zScriptInfo.__init__cCsd}|jdk r|jSd}|jdk r0t||j}nh|jrntd|jddgdd\}}t|}t|||}n*dD]$}t|}t||ddd}|rrqqr|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 :(?![\\/])rr5)zwsgi.pyzapp.pyF)rbzCould 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.) rr r)rrArTr\rdrrrdebug)rrcrrOr> import_namerrrload_appps4   zScriptInfo.load_app)NNT)rrrrrKrrrrrr[s 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||W5QRSQRXdSrx) ensure_objectrrZ app_contextZinvoke)Z__ctxr1kwargsfrr decoratorsz"with_appcontext..decorator)riZ pass_contextr)rrrrrwith_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|Srx)rriGroupcommandrr1rrZ wrap_for_ctxrrrsz#AppGroup.command..decorator)pop)rr1rrrrrrs 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) setdefaultrrirgroup)rr1rrrrrs zAppGroup.groupN)rrrrrrrrrrrsrcsBeZdZdZdddZddZdd Zd d Zfd d ZZ S) FlaskGroupajSpecial 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. For information as of why this is useful 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)listrrUversion_optionrrKr load_dotenvr add_command run_command shell_commandroutes_command_loaded_plugin_commands)rZadd_default_commandsr Zadd_version_optionrrextrarrrrrKs     zFlaskGroup.__init__cCs`|jr dSz ddl}Wntk r2d|_YdSX|dD]}|||jq>d|_dS)NrTzflask.commands)r pkg_resourcesr^iter_entry_pointsrloadr>)rreprrr_load_plugin_commandss z FlaskGroup._load_plugin_commandscCsj|t|||}|dk r"|S|t}z$|j||}|dk rN|WSWntk rdYnXdSrx)rr get_commandrrrclir)rrnr>rinforrrrs   zFlaskGroup.get_commandcCsd|ttj||}|t}z||j |Wnt k rZt YnXt |Srx)rsetrir list_commandsrrupdaterrrr_ print_excsorted)rrnrrrrrr$s zFlaskGroup.list_commandscsbdtjd<t|jrt|d}|dkrrrrrTs.     rcCstjddkrdS|dk rrKrrrrrrsrcCs|jd}|dk}tjdkr4|o0t|ttf }n t|tj}|dk r|rZt d|||rlt d|||s~t d||||f|jd<n|r|s|st d|||S) zThe ``--key`` option must be specified when ``--cert`` is a file. Modifies the ``cert`` param to be a ``(cert, key)`` pair if needed. certrrNz.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".) rrr6rrr bytesrrrir)rnrorprZis_adhocZ is_contextrrr _validate_keys0    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,||}tt|jfdd|DS)Ncsg|]}|qSrr)ritemrnroZ super_convertrrrsz-SeparatedPathType.convert..)Zsplit_envvar_valuerrr)rrprornitemsrrrrs  zSeparatedPathType.convert)rrrrrrrrrrrsrrunzRun a development server.)Z short_helpz--hostz-hz 127.0.0.1zThe interface to bind to.)defaultrsz--portz-pizThe port to bind to.z--certz(Specify a certificate file to use HTTPS.)typersz--keyrz2The key file to use when specifying a certificate.)rrurtrsz--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-loaderzaEnable 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-fileszRExtra files that trigger a reload on change. Multiple paths are separated by '{}'.)rrrsc Cstt} |dkr| }|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)rrrrrwrZwerkzeug.servingr) rhostportreloadZdebuggerrZ with_threadsrrrrrrrrr s(9 rshellzRun a shell in the app context.c Csddl}ddlm}|jj}dtjtj|j|j |j f}i}t j d}|rt j|rt|d}tt||d|W5QRX|||j||d dS) 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 it's configuration. This is useful for executing small snippets of management code without having to manually configure the application. rNr)_app_ctx_stackz)Python %s on %s App: %s [%s] Instance: %sZ PYTHONSTARTUPrexec)bannerlocal)codeglobalsrtoprr6versionrkrrZ instance_pathrNrrrOropenevalcompilereadrZmake_shell_contextZinteract)rrrrrnZstartuprrrrr`s"     rZrouteszShow the routes for the app.z--sortz-s)endpointmethodsrulerBrzgMethod to sort routes by. "match" is the order that Flask will match routes when dispatching a request.)rrrsz --all-methodszShow HEAD and OPTIONS methods.)rvrsc 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|jSrx)rr)rrrrz routes_command..cs g|]}dt|jqS)z, )rWrrrrZignored_methodsrrrsz"routes_command..)ZEndpointZMethodsZRulecss|]}t|jVqdSrx)r%rr rrr sz!routes_command..css|]}t|VqdSrx)r%)rrrrrrscss|]}t|jVqdSrx)r%rr rrrrscSsg|]\}}tt||qSr)maxr%)rhwrrrrsz"{{0:<{0}}} {{1:<{1}}} {{2:<{2}}}css|]}d|VqdS)-Nr)rwidthrrrrs)rr Zurl_mapZ iter_rulesrirjrrrrzipr&striprrrstrip) sortZ all_methodsrulesZ rule_methodsheadersZwidthsrowrrrr rrs*  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)rscCs$tjtjdd|rdndddS)Nrzpython -m flask)r1Z prog_name)rrr6argvZ as_modulerrrrsr__main__r )r)T)N)F)Kr __future__rrEr'rNrkrAr6r_ functoolsroperatorr threadingrrriZwerkzeug.utilsr_compatr r r r rr Zhelpersrrrrr^rZ UsageErrorrr0r)r+rJr\rdrrOptionrobjectrwrZmake_pass_decoratorZpass_script_inforrrrrrrZ ParamTyperrrrroptionr&rOpathseprrZChoicerr>rrrrrrrs                  3 ;  7B =.#  '  !  !