U
    Ha                     @   s  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
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 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!r$d dl"m#Z# ddl$m%Z% ddl&m'Z' e(dZ)e*dZ+e*dZ,dZ-G dd de.ej/e) Z0e1e2ddddZ3G dd dee Z4G dd  d ee Z5G d!d" d"Z6e6d#Z7e6d$Z8d%d&d'd(d)d*hZ9e2e2e2d+d,d-Z:e;e2d.d/d0Z<e2ej=e2ej>f e2d1d2d3Z?e2e2d4d5d6Z@ej>e2d7d8d9ZAe2e2d7d:d;ZBd\e2eCejDejEd=  d=d>d?d@ZFd]dBeCd=dCdDdEZGd^ejHejIe2ejJf dBejDe2 eKejDe2 eKejHeKe2f ejDejHeeCeLf  ejDejHeCejMejDe2 gejDeC f f  eKejDejEd=  ejDejHejIe2f  d=dHdIdJZNejHejIe2f ejHejIe2f dBej>d=dKdLdMZOd_e2eKej>dNdOdPZPd`e2eKeKejQe2 dQdRdSZRdadTdUZSdVdW ZTG dXdY dYeUZVG dZd[ d[eWZXdS )b    N)datetime)name2codepoint)time)adler32   )_DictAccessorProperty)_missing)_parse_signature)_TAccessorValue)Headers)NotFound)RequestedRangeNotSatisfiable)	safe_join)	url_quote)	wrap_file)WSGIEnvironment)RequestResponse_T	&([^;]+);z[^A-Za-z0-9_.-])CONAUXZCOM1ZCOM2ZCOM3ZCOM4ZLPT1ZLPT2ZLPT3PRNNULc                       s~   e Zd ZdZdejejgef eje	 eje	 dd fddZ
eeddddZdeeed	d
dZeddddZ  ZS )cached_propertya  A :func:`property` that is only evaluated once. Subsequent access
    returns the cached value. Setting the property sets the cached
    value. Deleting the property clears the cached value, accessing it
    again will evaluate it again.

    .. code-block:: python

        class Example:
            @cached_property
            def value(self):
                # calculate something important here
                return 42

        e = Example()
        e.value  # evaluates
        e.value  # uses cache
        e.value = 16  # sets cache
        del e.value  # clears cache

    The class must have a ``__dict__`` for this to work.

    .. versionchanged:: 2.0
        ``del obj.name`` clears the cached value.
    N)fgetnamedocreturnc                    s(   t  j||d |p|j| _|j| _d S )N)r   )super__init____name__
__module__)selfr   r   r   	__class__ 2/tmp/pip-unpacked-wheel-ub1y1qyw/werkzeug/utils.pyr!   M   s    zcached_property.__init__)objvaluer   c                 C   s   ||j | j< d S N__dict__r"   )r$   r)   r*   r'   r'   r(   __set__W   s    zcached_property.__set__)r)   typer   c                 C   s>   |d kr| S |j | jt}|tkr:| |}||j | j< |S r+   )r-   getr"   r   r   )r$   r)   r/   r*   r'   r'   r(   __get__Z   s    
zcached_property.__get__r)   r   c                 C   s   |j | j= d S r+   r,   r$   r)   r'   r'   r(   
__delete__f   s    zcached_property.__delete__)NN)N)r"   r#   __qualname____doc__tCallableAnyr   Optionalstrr!   objectr.   r/   r1   r4   __classcell__r'   r'   r%   r(   r   3   s     
r   )r)   r   r   c                 C   s   t jdtdd t| | dS )af  Invalidates the cache for a :class:`cached_property`:

    >>> class Test(object):
    ...     @cached_property
    ...     def magic_number(self):
    ...         print("recalculating...")
    ...         return 42
    ...
    >>> var = Test()
    >>> var.magic_number
    recalculating...
    42
    >>> var.magic_number
    42
    >>> invalidate_cached_property(var, "magic_number")
    >>> var.magic_number
    recalculating...
    42

    You must pass the name of the cached property as the second argument.

    .. deprecated:: 2.0
        Will be removed in Werkzeug 2.1. Use ``del obj.name`` instead.
    zk'invalidate_cached_property' is deprecated and will be removed in Werkzeug 2.1. Use 'del obj.name' instead.   
stacklevelN)warningswarnDeprecationWarningdelattr)r)   r   r'   r'   r(   invalidate_cached_propertyj   s    rE   c                   @   s$   e Zd ZdZdZdddddZdS )	environ_propertya  Maps request attributes to environment variables. This works not only
    for the Werkzeug request object, but also any other class with an
    environ attribute:

    >>> class Test(object):
    ...     environ = {'key': 'value'}
    ...     test = environ_property('key')
    >>> var = Test()
    >>> var.test
    'value'

    If you pass it a second value it's used as default if the key does not
    exist, the third one can be a converter that takes a value and converts
    it.  If it raises :exc:`ValueError` or :exc:`TypeError` the default value
    is used. If no default value is provided `None` is used.

    Per default the property is read only.  You have to explicitly enable it
    by passing ``read_only=False`` to the constructor.
    Tr   r   r2   c                 C   s   |j S r+   )environr3   r'   r'   r(   lookup   s    zenviron_property.lookupN)r"   r#   r5   r6   Z	read_onlyrH   r'   r'   r'   r(   rF      s   rF   c                   @   s&   e Zd ZdZejd edddZdS )header_propertyz(Like `environ_property` but for headers.)r   r   r2   c                 C   s   |j S r+   )headersr3   r'   r'   r(   rH      s    zheader_property.lookupN)r"   r#   r5   r6   r7   Unionr   rH   r'   r'   r'   r(   rI      s   rI   c                   @   s   e Zd ZdZedZe Z	de	d< ddddd	d
ddddddddddddhZ
dddddddddd d!d"hZd#hZd$d%hZd&d' Zd(d) Zd*d+ Zed,d-d.Zd/S )0HTMLBuildera2  Helper object for HTML generation.

    Per default there are two instances of that class.  The `html` one, and
    the `xhtml` one for those two dialects.  The class uses keyword parameters
    and positional parameters to generate small snippets of HTML.

    Keyword parameters are converted to XML/SGML attributes, positional
    arguments are used as children.  Because Python accepts positional
    arguments before keyword arguments it's a good idea to use a list with the
    star-syntax for some children:

    >>> html.p(class_='foo', *[html.a('foo', href='foo.html'), ' ',
    ...                        html.a('bar', href='bar.html')])
    '<p class="foo"><a href="foo.html">foo</a> <a href="bar.html">bar</a></p>'

    This class works around some browser limitations and can not be used for
    arbitrary SGML/XML generation.  For that purpose lxml and similar
    libraries exist.

    Calling the builder escapes the string passed:

    >>> html.p(html("<foo>"))
    '<p>&lt;foo&gt;</p>'

    .. deprecated:: 2.0
        Will be removed in Werkzeug 2.1.
    r   '   ZaposareabasebasefontbrcolcommandembedframehrimginputkeygenisindexlinkmetaparamsourcewbrselectedcheckedcompactZdeclaredeferdisabledismapmultipleZnohrefZnoresizenoshadeZnowraptextareascriptstylec                 C   s
   || _ d S r+   )_dialect)r$   dialectr'   r'   r(   r!      s    zHTMLBuilder.__init__c                 C   s"   dd l }tjdtdd ||S )Nr   F'utils.HTMLBuilder' is deprecated and will be removed in Werkzeug 2.1.r>   r?   )htmlrA   rB   rC   escape)r$   srn   r'   r'   r(   __call__   s    zHTMLBuilder.__call__c                    sD   dd l  tjdtdd d d dkr0t fdd}|S )Nr   rm   r>   r?   __c                     s2  d }|  D ]|\}}|d kr$q|d dkr<|d d }|jkrj|sLqjdkrdd| d}q|d}nd | d}|d| | 7 }q| sjkrjdkr|d	7 }n|d
7 }|S |d
7 }ddd | D }|rjkr |}n$jkrjdkrd| d}||d d
 7 }|S )N<_xhtmlz=""  z />>c                 S   s   g | ]}|d k	rt |qS r+   )r;   .0xr'   r'   r(   
<listcomp>$  s      z:HTMLBuilder.__getattr__.<locals>.proxy.<locals>.<listcomp>z/*<![CDATA[*/z/*]]>*/z</)items_boolean_attributesrk   ro   _empty_elementsjoin_plaintext_elements_c_like_cdata)children	argumentsbufferkeyr*   Zchildren_as_stringrn   r$   tagr'   r(   proxy  s8    





z&HTMLBuilder.__getattr__.<locals>.proxy)rn   rA   rB   rC   AttributeError)r$   r   r   r'   r   r(   __getattr__   s    #zHTMLBuilder.__getattr__r   c                 C   s   dt | j d| jdS )Nrs   z for rz   )r/   r"   rk   r$   r'   r'   r(   __repr__0  s    zHTMLBuilder.__repr__N)r"   r#   r5   r6   recompile
_entity_rer   copyZ	_entitiesr   r   r   r   r!   rq   r   r;   r   r'   r'   r'   r(   rL      sT   

0rL   rn   rv   zapplication/ecmascriptzapplication/javascriptzapplication/sqlzapplication/xmlzapplication/xml-dtdz&application/xml-external-parsed-entity)mimetypecharsetr   c                 C   s.   |  ds| tks| dr*| d| 7 } | S )aL  Returns the full content type string with charset for a mimetype.

    If the mimetype represents text, the charset parameter will be
    appended, otherwise the mimetype is returned unchanged.

    :param mimetype: The mimetype to be used as content type.
    :param charset: The charset to be appended for text mimetypes.
    :return: The content type.

    .. versionchanged:: 0.15
        Any type that ends with ``+xml`` gets a charset, not just those
        that start with ``application/``. Known text types such as
        ``application/javascript`` are also given charsets.
    ztext/z+xmlz
; charset=)
startswith_charset_mimetypesendswith)r   r   r'   r'   r(   get_content_typeD  s    r   )datar   c                 C   s   t jdtdd | dd }|dd tjkr2dS d|kr>d	S |tjtjfkrRd
S |dd tjtjfkrndS t	|dkr|dd dkrdS |ddd dkrdS |dd dkrdS |ddd dkrdS t	|dkr|
drdS dS d	S )a  Detect which UTF encoding was used to encode the given bytes.

    The latest JSON standard (:rfc:`8259`) suggests that only UTF-8 is
    accepted. Older documents allowed 8, 16, or 32. 16 and 32 can be big
    or little endian. Some editors or libraries may prepend a BOM.

    :internal:

    :param data: Bytes in unknown UTF encoding.
    :return: UTF encoding name

    .. deprecated:: 2.0
        Will be removed in Werkzeug 2.1. This is built in to
        :func:`json.loads`.

    .. versionadded:: 0.15
    zj'detect_utf_encoding' is deprecated and will be removed in Werkzeug 2.1. This is built in to 'json.loads'.r>   r?   N      z	utf-8-sig    utf-8zutf-32zutf-16s      z	utf-32-bes     z	utf-16-ber   z	utf-32-lez	utf-16-le)rA   rB   rC   codecsBOM_UTF8BOM_UTF32_BEBOM_UTF32_LEBOM_UTF16_BEBOM_UTF16_LElenr   )r   headr'   r'   r(   detect_utf_encoding]  s4    r   )stringcontextr   c                 C   s*   ddl m} tjdtdd || |S )ak  String-template format a string:

    >>> format_string('$foo and ${foo}s', dict(foo=42))
    '42 and 42s'

    This does not do any attribute lookup.

    :param string: the format string.
    :param context: a dict with the variables to insert.

    .. deprecated:: 2.0
        Will be removed in Werkzeug 2.1. Use :class:`string.Template`
        instead.
    r   )Templatezg'utils.format_string' is deprecated and will be removed in Werkzeug 2.1. Use 'string.Template' instead.r>   r?   )r   r   rA   rB   rC   
substitute)r   r   r   r'   r'   r(   format_string  s    r   )filenamer   c                 C   s   t d| } | ddd} tjjtjjfD ]}|r.| |d} q.t	t
dd|  d} tjdkr| r| d	d
  tkrd|  } | S )at  Pass it a filename and it will return a secure version of it.  This
    filename can then safely be stored on a regular file system and passed
    to :func:`os.path.join`.  The filename returned is an ASCII only string
    for maximum portability.

    On windows systems the function also makes sure that the file is not
    named after one of the special device files.

    >>> secure_filename("My cool movie.mov")
    'My_cool_movie.mov'
    >>> secure_filename("../../../etc/passwd")
    'etc_passwd'
    >>> secure_filename('i contain cool \xfcml\xe4uts.txt')
    'i_contain_cool_umlauts.txt'

    The function might return an empty filename.  It's your responsibility
    to ensure that the filename is unique and that you abort or
    generate a random filename if the function returned an empty one.

    .. versionadded:: 0.5

    :param filename: the filename to secure
    NFKDasciiignorery   rx   ru   z._nt.r   )unicodedata	normalizeencodedecodeospathsepaltsepreplacer;   _filename_ascii_strip_resubr   splitstripr   upper_windows_device_files)r   r   r'   r'   r(   secure_filename  s     
r   )rp   r   c                 C   sV   ddl }tjdtdd | dkr$dS t| dr6|  S t| tsHt| } |j| dd	S )
zReplace ``&``, ``<``, ``>``, ``"``, and ``'`` with HTML-safe
    sequences.

    ``None`` is escaped to an empty string.

    .. deprecated:: 2.0
        Will be removed in Werkzeug 2.1. Use MarkupSafe instead.
    r   NzY'utils.escape' is deprecated and will be removed in Werkzeug 2.1. Use MarkupSafe instead.r>   r?   rx   __html__T)quote)	rn   rA   rB   rC   hasattrr   
isinstancer;   ro   rp   rn   r'   r'   r(   ro     s    	

ro   c                 C   s"   ddl }tjdtdd || S )zThe reverse of :func:`escape`. This unescapes all the HTML
    entities, not only those inserted by ``escape``.

    .. deprecated:: 2.0
        Will be removed in Werkzeug 2.1. Use MarkupSafe instead.
    r   Nz['utils.unescape' is deprecated and will be removed in Werkzueg 2.1. Use MarkupSafe instead.r>   r?   )rn   rA   rB   rC   unescaper   r'   r'   r(   r     s    r   .  r   )locationcoder   r   c                 C   sx   ddl }|dkrddlm} || }t| trHddlm} || dd} |d||  d	| d
|dd}| |jd< |S )aa  Returns a response object (a WSGI application) that, if called,
    redirects the client to the target location. Supported codes are
    301, 302, 303, 305, 307, and 308. 300 is not supported because
    it's not a real redirect and 304 because it's the answer for a
    request with a request with defined If-Modified-Since headers.

    .. versionadded:: 0.6
       The location can now be a unicode string that is encoded using
       the :func:`iri_to_uri` function.

    .. versionadded:: 0.10
        The class used for the Response object can now be passed in.

    :param location: the location the response should redirect to.
    :param code: the redirect status code. defaults to 302.
    :param class Response: a Response class to use when instantiating a
        response. The default is :class:`werkzeug.wrappers.Response` if
        unspecified.
    r   Nr   r   )
iri_to_uriT)Zsafe_conversionz<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="z">z</a>. If not click the link.z	text/html)r   ZLocation)	rn   wrappersr   ro   r   r;   urlsr   rJ   )r   r   r   rn   Zdisplay_locationr   responser'   r'   r(   redirect  s    



r   -  r   )rG   r   r   c                 C   s8   | d  dd }| d}|r.|d| 7 }t||S )a-  Redirects to the same URL but with a slash appended.  The behavior
    of this function is undefined if the path ends with a slash already.

    :param environ: the WSGI environment for the request that triggers
                    the redirect.
    :param code: the status code for the redirect.
    Z	PATH_INFO/QUERY_STRING?)r   r0   r   )rG   r   new_pathZquery_stringr'   r'   r(   append_slash_redirect?  s
    
r   FT)path_or_filerG   r   as_attachmentdownload_nameconditionaletaglast_modifiedmax_ageuse_x_sendfileresponse_class
_root_pathr   c                 C   sd  |
dkrddl m} |}
d}d}d}d}t }t| tjtfsHt| drt	tj
tjtf | } |dk	rxtj|| }ntj| }t|}|j}|j}n| }|dkr|dk	rtj|}|dkr|dkrtdt|\}}|dkrd}|dk	r|d| |dk	rz|d W nP tk
rn   td	|}|dd
d}t|dd}|d| d}Y n
X d|i}|rdnd}|jd|f| n|rtd|	r|dk	r||d< d}nP|dkrt|d}n0t|tjr| j }nt|tj!r
t"dt#||}|
|||dd}|dk	r4||_$|dk	rF||_%n|dk	rV||_%d|j&_'t(|rp||}|dk	r|dkrd|j&_'d|j&_)||j&_*t+t, | |_-t|tr|.| n<|r |dk	r t/|dd@ }|.| d| d|  |r`z|j0|d|d}W n* t1k
rD   |dk	r>|2   Y nX |j3dkr`|j45dd |S ) ae  Send the contents of a file to the client.

    The first argument can be a file path or a file-like object. Paths
    are preferred in most cases because Werkzeug can manage the file and
    get extra information from the path. Passing a file-like object
    requires that the file is opened in binary mode, and is mostly
    useful when building a file in memory with :class:`io.BytesIO`.

    Never pass file paths provided by a user. The path is assumed to be
    trusted, so a user could craft a path to access a file you didn't
    intend.

    If the WSGI server sets a ``file_wrapper`` in ``environ``, it is
    used, otherwise Werkzeug's built-in wrapper is used. Alternatively,
    if the HTTP server supports ``X-Sendfile``, ``use_x_sendfile=True``
    will tell the server to send the given path, which is much more
    efficient than reading it in Python.

    :param path_or_file: The path to the file to send, relative to the
        current working directory if a relative path is given.
        Alternatively, a file-like object opened in binary mode. Make
        sure the file pointer is seeked to the start of the data.
    :param environ: The WSGI environ for the current request.
    :param mimetype: The MIME type to send for the file. If not
        provided, it will try to detect it from the file name.
    :param as_attachment: Indicate to a browser that it should offer to
        save the file instead of displaying it.
    :param download_name: The default name browsers will use when saving
        the file. Defaults to the passed file name.
    :param conditional: Enable conditional and range responses based on
        request headers. Requires passing a file path and ``environ``.
    :param etag: Calculate an ETag for the file, which requires passing
        a file path. Can also be a string to use instead.
    :param last_modified: The last modified time to send for the file,
        in seconds. If not provided, it will try to detect it from the
        file path.
    :param max_age: How long the client should cache the file, in
        seconds. If set, ``Cache-Control`` will be ``public``, otherwise
        it will be ``no-cache`` to prefer conditional caching.
    :param use_x_sendfile: Set the ``X-Sendfile`` header to let the
        server to efficiently send the file. Requires support from the
        HTTP server. Requires passing a file path.
    :param response_class: Build the response using this class. Defaults
        to :class:`~werkzeug.wrappers.Response`.
    :param _root_path: Do not use. For internal use only. Use
        :func:`send_from_directory` to safely send files under a path.

    .. versionadded:: 2.0
        Adapted from Flask's implementation.

    .. versionchanged:: 2.0
        ``download_name`` replaces Flask's ``attachment_filename``
         parameter. If ``as_attachment=False``, it is passed with
         ``Content-Disposition: inline`` instead.

    .. versionchanged:: 2.0
        ``max_age`` replaces Flask's ``cache_timeout`` parameter.
        ``conditional`` is enabled and ``max_age`` is not set by
        default.

    .. versionchanged:: 2.0
        ``etag`` replaces Flask's ``add_etags`` parameter. It can be a
        string to use instead of generating one.

    .. versionchanged:: 2.0
        If an encoding is returned when guessing ``mimetype`` from
        ``download_name``, set the ``Content-Encoding`` header.
    Nr   r   
__fspath__zUnable to detect the MIME type because a file name is not available. Either set 'download_name', pass a path instead of a file, or set 'mimetype'.zapplication/octet-streamzContent-Encodingr   r   r   rx   )safezUTF-8'')r   z	filename*r   
attachmentinlinezContent-Dispositionz]No name provided for attachment. Either set 'download_name' or pass a path instead of a file.z
X-Sendfilerbz3Files must be opened in binary mode or use BytesIO.T)r   rJ   Zdirect_passthroughr   r   l    -)Zaccept_rangesZcomplete_lengthi0  z
x-sendfile)6r   r   r   r   r   PathLiker;   r   r7   castrK   r   r   abspathstatst_sizest_mtimebasename	TypeError	mimetypes
guess_typesetr   UnicodeEncodeErrorr   r   r   r   openioBytesIO	getbuffernbytes
TextIOBase
ValueErrorr   content_lengthr   Zcache_controlno_cachecallablepublicr   intr   expiresZset_etagr   Zmake_conditionalr   closestatus_coderJ   pop)r   rG   r   r   r   r   r   r   r   r   r   r   r   r   filesizemtimerJ   r   encodingsimplequotednamesr*   r   rvcheckr'   r'   r(   	send_fileN  s    T 





   






r  )	directoryr   rG   kwargsr   c                 K   s~   t t| t|}|dkr$t d|kr>tj|d |}ztj|sRt W n tk
rn   t Y nX t||f|S )a  Send a file from within a directory using :func:`send_file`.

    This is a secure way to serve files from a folder, such as static
    files or uploads. Uses :func:`~werkzeug.security.safe_join` to
    ensure the path coming from the client is not maliciously crafted to
    point outside the specified directory.

    If the final path does not point to an existing regular file,
    returns a 404 :exc:`~werkzeug.exceptions.NotFound` error.

    :param directory: The directory that ``path`` must be located under.
    :param path: The path to the file to send, relative to
        ``directory``.
    :param environ: The WSGI environ for the current request.
    :param kwargs: Arguments to pass to :func:`send_file`.

    .. versionadded:: 2.0
        Adapted from Flask's implementation.
    Nr   )	r   r   fspathr   r   r   isfiler   r  )r  r   rG   r  r'   r'   r(   send_from_directory$  s    
r  )import_namesilentr   c              
   C   s   |  dd} zzt|  W n tk
r8   d| kr4 Y nX tj|  W S | dd\}}t|t t |g}zt||W W S  t	k
r } zt|W 5 d}~X Y nX W n> tk
r } z |st
| |t d W 5 d}~X Y nX dS )aC  Imports an object based on a string.  This is useful if you want to
    use import paths as endpoints or something similar.  An import path can
    be specified either in dotted notation (``xml.sax.saxutils.escape``)
    or with a colon as object delimiter (``xml.sax.saxutils:escape``).

    If `silent` is True the return value will be `None` if the import fails.

    :param import_name: the dotted name for the object to import.
    :param silent: if set to `True` import errors are ignored and
                   `None` is returned instead.
    :return: imported object
    :r   r   Nr>   )r   
__import__ImportErrorsysmodulesrsplitglobalslocalsgetattrr   ImportStringErrorwith_tracebackexc_info)r  r  module_nameZobj_namemoduleer'   r'   r(   import_stringQ  s$    *r$  )import_pathinclude_packages	recursiver   c           	      c   s   t | }t|dd}|dkr*t| d|j d}t|D ]>\}}}|| }|rx|r`|V  |r~t||dE dH  q@|V  q@dS )a  Finds all the modules below a package.  This can be useful to
    automatically import all views / controllers so that their metaclasses /
    function decorators have a chance to register themselves on the
    application.

    Packages are not returned unless `include_packages` is `True`.  This can
    also recursively list modules but in that case it will import all the
    packages to get the correct load path of that module.

    :param import_path: the dotted name for the package to find child modules.
    :param include_packages: set to `True` if packages should be returned, too.
    :param recursive: set to `True` if recursion should happen.
    :return: generator
    __path__Nz is not a packager   T)r$  r  r   r"   pkgutiliter_modulesfind_modules)	r%  r&  r'  r"  r   r   	_importermodnameispkgr'   r'   r(   r+  v  s    r+  c                 C   sj   t jdtdd t| }|||dd \}}}}}|rFtt|n|sN|r^|s^td||t||fS )a3  Checks if the function accepts the arguments and keyword arguments.
    Returns a new ``(args, kwargs)`` tuple that can safely be passed to
    the function without causing a `TypeError` because the function signature
    is incompatible.  If `drop_extra` is set to `True` (which is the default)
    any extra positional or keyword arguments are dropped automatically.

    The exception raised provides three attributes:

    `missing`
        A set of argument names that the function expected but where
        missing.

    `extra`
        A dict of keyword arguments that the function can not handle but
        where provided.

    `extra_positional`
        A list of values that where given by positional argument but the
        function cannot accept.

    This can be useful for decorators that forward user submitted data to
    a view function::

        from werkzeug.utils import ArgumentValidationError, validate_arguments

        def sanitize(f):
            def proxy(request):
                data = request.values.to_dict()
                try:
                    args, kwargs = validate_arguments(f, (request,), data)
                except ArgumentValidationError:
                    raise BadRequest('The browser failed to transmit all '
                                     'the data expected.')
                return f(*args, **kwargs)
            return proxy

    :param func: the function the validation is performed against.
    :param args: a tuple of positional arguments.
    :param kwargs: a dict of keyword arguments.
    :param drop_extra: set to `False` if you don't want extra arguments
                       to be silently dropped.
    :return: tuple in the form ``(args, kwargs)``.

    .. deprecated:: 2.0
        Will be removed in Werkzeug 2.1. Use :func:`inspect.signature`
        instead.
    zn'utils.validate_arguments' is deprecated and will be removed in Werkzeug 2.1. Use 'inspect.signature' instead.r>   r?   N   )rA   rB   rC   r	   ArgumentValidationErrortuple)funcargsr  Z
drop_extraparsermissingextraextra_positionalr'   r'   r(   validate_arguments  s    0r8  c                 C   s   t jdtdd t| ||\}}}}}}}}i }	t||D ]\\}
}}}||	|
< q<|dk	rjt||	|< n|rvtd|dk	rt|dd |D @ }|rtdtt	|||	|< n|rtd	tt	||	S )
a  Bind the arguments provided into a dict.  When passed a function,
    a tuple of arguments and a dict of keyword arguments `bind_arguments`
    returns a dict of names as the function would see it.  This can be useful
    to implement a cache decorator that uses the function arguments to build
    the cache key based on the values of the arguments.

    :param func: the function the arguments should be bound for.
    :param args: tuple of positional arguments.
    :param kwargs: a dict of keyword arguments.
    :return: a :class:`dict` of bound keyword arguments.

    .. deprecated:: 2.0
        Will be removed in Werkzeug 2.1. Use :meth:`Signature.bind`
        instead.
    zg'utils.bind_arguments' is deprecated and will be removed in Werkzeug 2.1. Use 'Signature.bind' instead.r>   r?   Nztoo many positional argumentsc                 S   s   h | ]}|d  qS )r   r'   r{   r'   r'   r(   	<setcomp>  s     z!bind_arguments.<locals>.<setcomp>z)got multiple values for keyword argument z got unexpected keyword argument )
rA   rB   rC   r	   zipr1  r   r   nextiter)r2  r3  r  r5  r6  r7  Zarg_specZ
vararg_varZ	kwarg_varvaluesr   Z_has_default_defaultr*   Zmultikwr'   r'   r(   bind_arguments  s@    

r?  c                       s"   e Zd ZdZd fdd	Z  ZS )r0  zRaised if :func:`validate_arguments` fails to validate

    .. deprecated:: 2.0
        Will be removed in Werkzeug 2.1 along with ``utils.bind`` and
        ``validate_arguments``.
    Nc                    sV   t |pd| _|pi | _|pg | _t dt| j dt| jt| j  d d S )Nr'   zfunction arguments invalid. (z
 missing, z additional))r   r5  r6  r7  r    r!   r   )r$   r5  r6  r7  r%   r'   r(   r!     s    

&z ArgumentValidationError.__init__)NNN)r"   r#   r5   r6   r!   r=   r'   r'   r%   r(   r0  	  s   r0  c                       sJ   e Zd ZU dZeed< eed< eedd fddZedd	d
Z  Z	S )r  zBProvides information about a failed :func:`import_string` attempt.r  	exceptionN)r  r@  r   c           
   	      s   || _ || _|}d}g }|dddD ]}|r@| d| n|}t|dd}|rl||t|dd f q*dd |D }|d	|d
 d|}	d|d|	 dt|j	 d| } qq*t
 | d S )Nrx   r  r   T)r  __file__c                 S   s"   g | ]\}}d |d|dqS )- z
 found in r   r'   )r|   nir'   r'   r(   r~   0  s     z.ImportStringError.__init__.<locals>.<listcomp>rB  z not found.
zimport_string() failed for z. Possible reasons are:

- missing __init__.py in a package;
- package or module path not included in sys.path;
- duplicated package or module name taking precedence in sys.path;
- missing module, class, function or variable;

Debugged import:

z

Original exception:

z: )r  r@  r   r   r$  appendr  r   r/   r"   r    r!   )
r$   r  r@  msgr   ZtrackedpartZimportedtrackZ	track_strr%   r'   r(   r!   $  s"    
 zImportStringError.__init__r   c                 C   s"   dt | j d| jd| jdS )Nrs   (z, z)>)r/   r"   r  r@  r   r'   r'   r(   r   B  s    zImportStringError.__repr__)
r"   r#   r5   r6   r;   __annotations__BaseExceptionr!   r   r=   r'   r'   r%   r(   r    s
   
r  )r   N)r   )
NFNTTNNFNN)F)FF)T)Yr   r   r   r   r)  r   r  typingr7   r   rA   r   html.entitiesr   r   zlibr   	_internalr   r   r	   r
   Zdatastructuresr   
exceptionsr   r   securityr   r   r   Zwsgir   TYPE_CHECKINGZ_typeshed.wsgir   Zwrappers.requestr   Zwrappers.responser   TypeVarr   r   r   r   r   propertyGenericr   r<   r;   rE   rF   rI   rL   rn   rv   r   r   bytesr   Mappingr9   r   r   ro   r   r   r:   Typer   r   rK   r   BinaryIOboolfloatr8   r  r  r$  Iteratorr+  r8  r?  r   r0  r  r  r'   r'   r'   r(   <module>   s   


7" 
9/     0          $ X-&     !
?3