o
    q>e                     @  s  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlmZ d dlmZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ d	d
lmZ d	dlmZ d	dlmZ ejrmd	dl m!Z! G dd dej"Z#dd Z$dd Z%dd Z&dd Z'dddZ(dd Z)ej*dgdde)ddd Z+G d!d" d"Z,ej-e,dd#Z.d$d% Z/G d&d' d'ej0Z1dd/d0Z2ej*d1d2gd3d4dde2d5Z3dd8d9Z4ej*d:gd;de4d<Z5dd=d>Z6ej*d?d@gej7dddAdBdde6dCZ8G dDdE dEe1Z9dFdG Z:dddJdKZ;dLdM Z<G dNdO dOej=Z>dPdQ Z?G dRdS dSej7Z@ejAdTdUdVejBdWdXdYdZd[ejBd\d]d^d_d[ejBd`e> daddbejBdcej7ddddde?ddedfejBdgddhd[ejBdiddjd[ejBdkddld[ejBdmde@ dnejCjDdodpejBdqde@ drejCjDdodpe.dsdt ZEeEjFGd e5 ejAdudvdVe/ddxdyZHejAdzd{dVejBd|d}eId~dddejBdddde/dddZJe9dddZKdddZLeMdkreL  dS dS )    )annotationsN)update_wrapper)
itemgetter)ParameterSource)
run_simple)is_running_from_reloader)import_string   )current_app)get_debug_flag)get_load_dotenvFlaskc                   @  s   e Zd ZdZdS )NoAppExceptionz3Raised if an application cannot be found or loaded.N)__name__
__module____qualname____doc__ r   r   J/var/www/bmteknikk.ddns.net/venv/lib/python3.10/site-packages/flask/cli.pyr      s    r   c                   s*  ddl m  dD ]}t| |d}t| r|  S q fdd| j D }t|dkr0|d S t|dkrCtd| j d	| j d
dD ]B}t| |d}t	
|rz| }t| r`|W   S W qE ty } zt|sn td| d| j d| j d| d	|d}~ww qEtd| 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|qS r   )
isinstance).0vr   r   r   
<listcomp>/   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_appzDetected 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)module	attr_namer   matchesapp_factoryer   r   r   find_best_app!   s^   



r-   c                 C  sF   t  d }z|dur|jj| ju rW ~dS |j}|dusW ~dS ~w )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)sysexc_infotb_framef_code__code__tb_next)ftbr   r   r   r'   V   s   	
r'   c           
   
   C  s  ddl m} ztj| ddj}W n ty"   td|ddw t|tj	r1|j
}g }i }nDt|tjrmt|jtj	sFtd|d	|jj
}zd
d |jD }dd |jD }W n tyl   td|d	dw td|dzt| |}W n ty } ztd|d| jd	|d}~ww t|rz	||i |}	W n  ty } zt|s td|d| jd|d}~ww |}	t|	|r|	S td| j d| d)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.
    r	   r   eval)modezFailed to parse z' as an attribute name or function call.Nz*Function reference must be a simple name: .c                 S  s   g | ]}t |qS r   )astliteral_eval)r   argr   r   r   r      s    z&find_app_by_string.<locals>.<listcomp>c                 S  s   i | ]
}|j t|jqS r   )r<   r:   r;   value)r   kwr   r   r   
<dictcomp>   s    z&find_app_by_string.<locals>.<dictcomp>z-Failed to parse arguments as literal values: zFailed to find attribute z in zThe factory z in module z2 could not be called with the specified arguments.z1A valid Flask application was not obtained from 'r   z'.)r   r   r:   parsestripbodySyntaxErrorr   r   NameidCallfuncargskeywords
ValueErrorr    AttributeErrorr   r$   r%   r&   r'   )
r(   app_namer   exprnamerH   kwargsattrr,   r   r   r   r   find_app_by_stringp   s   






rQ   c                 C  s   t j| } t j| \}}|dkr|} t j| dkr"t j| } g }	 t j| \} }|| t jt j	| ds>nq%t
jd | krMt
jd|  d	|ddd S )	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__Tz__init__.pyr   r9   N)ospathrealpathsplitextbasenamedirnamesplitappendexistsjoinr/   insert)rU   fnameextmodule_namerN   r   r   r   prepare_import   s    
rb   Tc              	   C  s   zt |  W n) ty/   t d jr!td| dt  d |r,td| dd Y d S w tj|  }|d u r=t	|S t
||S )Nr.   zWhile importing z, an ImportError was raised:

zCould not import r9   )
__import__ImportErrorr/   r0   r4   r   	traceback
format_excmodulesr-   rQ   )ra   rL   raise_if_not_foundr(   r   r   r   
locate_app   s&   

ri   c                 C  sX   |r| j rd S tjd}tjd}tjdt  d| d| | jd | 	  d S )NflaskwerkzeugPython z
Flask z

Werkzeug )color)
resilient_parsing	importlibmetadataversionclickechoplatformpython_versionrm   exit)ctxparamr=   flask_versionwerkzeug_versionr   r   r   get_version   s   
r{   z	--versionzShow the Flask version.F)helpexpose_valuecallbackis_flagis_eagerc                   @  s,   e Zd ZdZ			ddddZdddZdS )
ScriptInfoa  Helper 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.
    NTapp_import_path
str | Noner   t.Callable[..., Flask] | Noneset_debug_flagboolreturnNonec                 C  s"   || _ || _i | _|| _d | _d S N)r   r   datar   _loaded_app)selfr   r   r   r   r   r   rR     s
   
zScriptInfo.__init__r   c                 C  s   | j dur| j S | jdur|  }n3| jr1tjd| jdddg dd \}}t|}t||}ndD ]}t|}t|ddd}|rD nq3|sKtd	| jrRt	 |_
|| _ |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.
        Nz
:(?![\\/])r	   )maxsplitr.   )zwsgi.pyzapp.pyF)rh   zCould not locate a Flask application. Use the 'flask --app' option, 'FLASK_APP' environment variable, or a 'wsgi.py' or 'app.py' file in the current directory.)r   r   r   rerZ   rb   ri   r   r   r   debug)r   r   rU   rN   import_namer   r   r   load_app%  s0   


zScriptInfo.load_app)NNT)r   r   r   r   r   r   r   r   )r   r   )r   r   r   r   rR   r   r   r   r   r   r     s    
r   )ensurec                   s   t j fdd}t| S )a  Wraps a callback so that it's guaranteed to be executed with the
    script's application context.

    Custom commands (and their options) registered under ``app.cli`` or
    ``blueprint.cli`` will always have an app context available, this
    decorator is not required in that case.

    .. versionchanged:: 2.2
        The app context is active for subcommands as well as the
        decorated callback. The app context is always available to
        ``app.cli`` command and parameter callbacks.
    c                   s8   t s| t }| |  | j g|R i |S r   )r
   ensure_objectr   r   with_resourceapp_contextinvoke)__ctxrH   rO   r   r5   r   r   	decorator`  s   z"with_appcontext.<locals>.decorator)rr   pass_contextr   )r5   r   r   r   r   with_appcontextR  s   
r   c                   @  s    e Zd ZdZdd Zdd ZdS )AppGroupa   This 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`.
    c                   s"    dd fdd}|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``.
        r   Tc                   s*   rt | } tjjg R i | S r   )r   rr   Groupcommandr   rH   rO   r   wrap_for_ctxr   r   r   z  s   z#AppGroup.command.<locals>.decorator)pop)r   rH   rO   r   r   r   r   r   s  s   zAppGroup.commandc                 O  s&   | dt tjj| g|R i |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)
setdefaultr   rr   r   group)r   rH   rO   r   r   r   r     s   zAppGroup.groupN)r   r   r   r   r   r   r   r   r   r   r   k  s    r   rw   click.Contextrx   click.Optionr=   r   r   c                 C  s    |d u rd S |  t}||_|S r   )r   r   r   )rw   rx   r=   infor   r   r   _set_app  s
   
r   z-Az--appIMPORTzThe Flask application or factory function to load, in the form 'module:name'. Module can be a dotted import or file path. Name is not required if it is 'app', 'application', 'create_app', or 'make_app', and can be 'name(args)' to pass arguments.)metavarr|   r   r}   r~   r   bool | Nonec                 C  s>   |  |j}|d ur|tjtjfv rd S |rdndtjd< |S )N10FLASK_DEBUG)get_parameter_sourcerN   r   DEFAULTDEFAULT_MAPrT   environ)rw   rx   r=   sourcer   r   r   
_set_debug  s   
r   z--debug/--no-debugzSet debug mode.)r|   r}   r~   c                 C  sP   |d u rd S dd l }z|d W n ty!   tjd| |dd w t| |S )Nr   dotenvz4python-dotenv must be installed to load an env file.)rw   rx   )ro   import_modulerd   rr   BadParameterload_dotenv)rw   rx   r=   ro   r   r   r   _env_file_callback  s    	r   z-ez
--env-file)r\   dir_okayzKLoad environment variables from this file. python-dotenv must be installed.)typer|   r   r}   r~   c                      sn   e Zd ZdZ					d#d$ fddZdd Z fddZ fddZ	d%d& fddZd' fd!d"Z	  Z
S )(
FlaskGroupa0  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.

    .. versionchanged:: 2.2
        Added the ``-A/--app``, ``--debug/--no-debug``, ``-e/--env-file`` options.

    .. versionchanged:: 2.2
        An app context is pushed when running ``app.cli`` commands, so
        ``@with_appcontext`` is no longer required for those commands.

    .. versionchanged:: 1.0
        If installed, python-dotenv will be used to load environment variables
        from :file:`.env` and :file:`.flaskenv` files.
    TNadd_default_commandsr   r   r   add_version_optionr   r   extrat.Anyr   r   c                   s   t |dd pd}|tttf |r|t d|vr!i |d< |d dd t	 j
dd|i| || _|| _|| _|rN| t | t | t d| _d S )Nparamsr   context_settingsauto_envvar_prefixFLASKF)listr   extend_env_file_option_app_option_debug_optionr[   version_optionr   superrR   r   r   r   add_commandrun_commandshell_commandroutes_command_loaded_plugin_commands)r   r   r   r   r   r   r   r   	__class__r   r   rR     s    	




zFlaskGroup.__init__c                 C  sX   | j rd S tjdkrddlm} ndd l}|jddD ]}| | |j	 qd| _ d S )N)   
   r   )rp   zflask.commands)r   T)
r   r/   version_inforo   rp   importlib_metadataentry_pointsr   loadrN   )r   rp   epr   r   r   _load_plugin_commands$  s   

z FlaskGroup._load_plugin_commandsc              
     s   |    t ||}|d ur|S |t}z| }W n! ty= } ztjd|	  dddd W Y d }~d S d }~ww t
rFt
 |urM||  |j||S NzError: 
Tred)errfg)r   r   get_commandr   r   r   r   rr   sechoformat_messager
   _get_current_objectr   r   cli)r   rw   rN   rvr   r   r,   r   r   r   r   5  s   
zFlaskGroup.get_commandc              
     s   |    tt |}|t}z|| j| W t|S  t	yD } zt
jd|  dddd W Y d }~t|S d }~w ty\   t
jt  dddd Y t|S w r   )r   setr   list_commandsr   r   updater   r   r   rr   r   r   	Exceptionre   rf   sorted)r   rw   r   r   r,   r   r   r   r   P  s   

&zFlaskGroup.list_commands	info_namer   rH   	list[str]parentclick.Context | Noner   c                   sZ   dt jd< t| jrt  d|vr d| jvr t| j| jd|d< t j	||fd|i|S )NtrueFLASK_RUN_FROM_CLIobj)r   r   r   )
rT   r   r   r   r   r   r   r   r   make_context)r   r   rH   r   r   r   r   r   r   e  s   



zFlaskGroup.make_contextrw   c                   s4   |s| j rt|i g  t|i g  t ||S r   )no_args_is_helpr   handle_parse_resultr   r   
parse_args)r   rw   rH   r   r   r   r   }  s   
zFlaskGroup.parse_args)TNTTT)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )
r   r   rH   r   r   r   r   r   r   r   )rw   r   rH   r   r   r   )r   r   r   r   rR   r   r   r   r   r   __classcell__r   r   r   r   r     s    %r   c                 C  s&   t j| |t| d t j|kS )zTake ``other`` and remove the length of ``path`` from it. Then join it
    to ``path``. If it is the original value, ``path`` is an ancestor of
    ``other``.N)rT   rU   r]   r#   lstripsep)rU   otherr   r   r   _path_is_ancestor  s   &r   rU   str | os.PathLike | Nonec                 C  s   zddl }W n  ty&   | stjdstjdr#tjdddd Y d	S w | dur:tj| r8|j| d
dS d	S d	}dD ]}|j|dd} | sJq>|j| d
d d}q>|S )a?  Load "dotenv" files in order of precedence to set environment variables.

    If an env var is already set it is not overwritten, so earlier files in the
    list are preferred over later files.

    This is a no-op if `python-dotenv`_ is not installed.

    .. _python-dotenv: https://github.com/theskumar/python-dotenv#readme

    :param path: Load the file at this location instead of searching.
    :return: ``True`` if a file was loaded.

    .. versionchanged:: 2.0
        The current directory is not changed to the location of the
        loaded file.

    .. versionchanged:: 2.0
        When loading the env files, set the default encoding to UTF-8.

    .. versionchanged:: 1.1.0
        Returns ``False`` when python-dotenv is not installed, or when
        the given path isn't a file.

    .. versionadded:: 1.0
    r   N.env	.flaskenvz^ * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.yellowT)r   r   Fzutf-8)encoding)r   r   )usecwd)	r   rd   rT   rU   isfilerr   r   r   find_dotenv)rU   r   loadedrN   r   r   r   r     s.   r   c                 C  sL   t  rdS |durtd| d | dur$td| rdnd  dS dS )z]Show extra startup messages the first time the server is run,
    ignoring the reloader.
    Nz * Serving Flask app ''z * Debug mode: onoff)r   rr   rs   )r   r   r   r   r   show_server_banner  s   r  c                   @  s$   e Zd ZdZdZdd Zdd ZdS )CertParamTypezClick option type for the ``--cert`` option. Allows either an
    existing file, the string ``'adhoc'``, or an import for a
    :class:`~ssl.SSLContext` object.
    rU   c                 C  s   t jdddd| _d S )NTFr\   r   resolve_path)rr   Path	path_type)r   r   r   r   rR     s   zCertParamType.__init__c                 C  s   zdd l }W n ty   td||d w z| |||W S  tjy]   t||| }|dkrLz	dd l}W | Y S  tyK   td||d w t|dd}t	||j
r\| Y S  w )Nr   z?Using "--cert" requires Python to be compiled with SSL support.adhocz<Using ad-hoc certificates requires the cryptography library.T)silent)sslrd   rr   r   r  STRINGlowercryptographyr   r   
SSLContext)r   r=   rx   rw   r  r  r   r   r   r   convert  sB   
	zCertParamType.convertN)r   r   r   r   rN   rR   r  r   r   r   r   r    s
    r  c                 C  s   | j d}|dk}zddl}W n ty   d}Y nw t||j}|durJ|r/td| ||r8td| ||sAtd| |||f| j d< |S |rW|sW|sWt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.
    certr  r   NFz.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.zRequired when using "--cert".)r   getr  rd   r   r  rr   r   )rw   rx   r=   r  is_adhocr  
is_contextr   r   r   _validate_key  s0   r  c                      s    e Zd ZdZ fddZ  ZS )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.
    c                   s(   |  |}t j fdd|D S )Nc                   s   g | ]}| qS r   r   )r   itemrw   rx   super_convertr   r   r   6  s    z-SeparatedPathType.convert.<locals>.<listcomp>)split_envvar_valuer   r  )r   r=   rx   rw   itemsr   r  r   r  3  s   
zSeparatedPathType.convert)r   r   r   r   r  r   r   r   r   r   r  -  s    r  runzRun a development server.)
short_helpz--hostz-hz	127.0.0.1zThe interface to bind to.)defaultr|   z--portz-pi  zThe port to bind to.z--certz(Specify a certificate file to use HTTPS.)r   r|   r   z--keyr	  z2The key file to use when specifying a certificate.)r   r~   r}   r|   z--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 --with-threads/--without-threadsz!Enable or disable multithreading.z--extra-fileszMExtra files that trigger a reload on change. Multiple paths are separated by r9   )r"  r   r|   z--exclude-patternsznFiles matching these fnmatch patterns will not trigger a reload on change. Multiple patterns are separated by c	                   s   z|   }	W n% ty+ }
 zt rt  |
  fdd}	n|
dW Y d}
~
nd}
~
ww t }|du r5|}|du r;|}t|| j t|||	||||||d	 dS )a  Run 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 with the '--debug'
    option.
    c                   s    d r   r   )r   start_responser   r   r   r     s   zrun_command.<locals>.appN)use_reloaderuse_debuggerthreadedssl_contextextra_filesexclude_patterns)	r   r   r   re   	print_excr   r  r   r   )r   hostportreloaddebuggerwith_threadsr  r)  r*  r   r,   r   r   r$  r   r   9  s8   H
r   shellzRun a shell in the app context.r   c                  C  s   ddl } dtj dtj dtj dtj }i }tj	d}|rEtj
|rEt|}tt| |d| W d   n1 s@w   Y  |t  ttd	d}|durwzddl}dd
lm} W n	 tyk   Y n	w |||j |  | j||d dS )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.
    r   Nrl   z on z
App: z
Instance: PYTHONSTARTUPexec__interactivehook__)	Completer)bannerlocal)coder/   rq   rt   r
   r   instance_pathrT   r   r  rU   r  openr7   compilereadr   make_shell_contextr    readlinerlcompleterr5  rd   set_completercompleteinteract)r8  r6  rw   startupr5   interactive_hookr>  r5  r   r   r   r     s2   

r   routeszShow the routes for the app.z--sortz-s)endpointmethodsdomainrulematchrF  zgMethod to sort routes by. 'match' is the order that Flask will match routes when dispatching a request.)r   r"  r|   z--all-methodszShow HEAD and OPTIONS methods.)r   r|   sortstrall_methodsc                   s  t tj }|std dS |rt nddh}tjj t fdd|D }g |D ],}|j	d
t|jp8t | g}|rM| rG|jn|jpKd ||j | q,d	d
g}ddg}|rq| ridnd |d |d |d zjt|| d W n	 ty   Y nw d| fddtt|D }	ddd |	D  d
dd t|	D }
D ]
}t|
j|  qdS )z6Show all registered routes with endpoints and methods.zNo routes were registered.NHEADOPTIONSc                 3  s     | ]} r	|j n|jV  qd S r   )r,  	subdomain)r   rI  )host_matchingr   r   	<genexpr>  s    z!routes_command.<locals>.<genexpr>z, r   EndpointMethodsrF  rG  Host	SubdomainrH  RulerI  )keyr   c                   s"   g | ] t  fd dD qS )c                 3  s    | ]	}t |  V  qd S r   )r#   )r   rowir   r   rR    s    z,routes_command.<locals>.<listcomp>.<genexpr>)max)r   )rowsrZ  r   r     s   " z"routes_command.<locals>.<listcomp>r	   c                 S  s   g | ]}d | qS )-r   )r   wr   r   r   r     s    z  c                 s  s&    | ]\}}d | d| dV  qdS ){z:<}Nr   )r   r[  r_  r   r   r   rR    s   $ )r   r
   url_map
iter_rulesrr   rs   r   rQ  anyrF  r]   r   rG  r[   r,  rP  rI  rK  r   indexrJ   r^   ranger#   	enumerateformat)rK  rM  rulesignored_methods
has_domainrI  rY  headerssortswidthstemplater   )rQ  r]  r   r     sF   



r   rj   zA general utility script for Flask applications.

An application to load must be given with the '--app' option,
'FLASK_APP' environment variable, or with a 'wsgi.py' or 'app.py' file
in the current directory.
)rN   r|   c                   C  s   t   d S r   )r   mainr   r   r   r   rp  '  s   rp  __main__)T)rw   r   rx   r   r=   r   r   r   )rw   r   rx   r   r=   r   r   r   r   )rU   r   r   r   )r   r   )rK  rL  rM  r   r   r   )N
__future__r   r:   importlib.metadataro   r$   rT   rt   r   r/   re   typingt	functoolsr   operatorr   rr   
click.corer   rk   r   werkzeug.servingr   werkzeug.utilsr   globalsr
   helpersr   r   TYPE_CHECKINGr   r   
UsageErrorr   r-   r'   rQ   rb   ri   r{   Optionr   r   make_pass_decoratorpass_script_infor   r   r   r   r   r   r   r   r  r   r   r   r   r  	ParamTyper  r  r  r   optionrU   pathsepr   r   r^   r   Choicer   r   rp  r   r   r   r   r   <module>   s$   5L

D



 '=.%	
;/
1


