
    'g-                        d dl mZ d dlm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  G d d      Z G d deeef         ZddlmZ y)    )annotationsN)BytesIO)fsdecode)fspath   )
_plain_int   )Headers)	MultiDictc                      e Zd ZdZ	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZddZedd       Zedd       Zedd       Z	edd       Z
	 d	 	 	 	 	 dd	Zdd
ZddZddZddZddZy)FileStoragea@  The :class:`FileStorage` class is a thin wrapper over incoming files.
    It is used by the request object to represent uploaded files.  All the
    attributes of the wrapper stream are proxied by the file storage so
    it's possible to do ``storage.read()`` instead of the long form
    ``storage.stream.read()``.
    Nc                   || _         |xs
 t               | _        |/t        |dd       }|t	        |      }|r|d   dk(  r|d   dk(  rd }nt	        |      }|| _        |
t               }|| _        |||d<   |t        |      |d<   y y )Nnamer   <>zContent-TypezContent-Length)	r   r   streamgetattrr   filenamer
   headersstr)selfr   r   r   content_typecontent_lengthr   s          \/var/www/html/knws/venv/lib/python3.12/site-packages/werkzeug/datastructures/file_storage.py__init__zFileStorage.__init__   s     	)	
 vvt4H##H-HQK3.8B<33F)H ?iG#&2GN#%(+N(;G$% &    c                f    t        | d      s%t        j                  | j                        | _        y y )N_parsed_content_type)hasattrhttpparse_options_headerr   r   r   s    r   _parse_content_typezFileStorage._parse_content_type<   s+    t34(,(A(A$BSBS(TD% 5r   c                8    | j                   j                  d      S )z;The content-type sent in the header.  Usually not availablezcontent-type)r   getr#   s    r   r   zFileStorage.content_type@   s     ||//r   c                p    d| j                   v r	 t        | j                   d         S y# t        $ r Y yw xY w)z=The content-length sent in the header.  Usually not availablezcontent-lengthr   )r   r   
ValueErrorr#   s    r   r   zFileStorage.content_lengthE   sF     t||+!$,,/?"@AA   s   ) 	55c                \    | j                          | j                  d   j                         S )a  Like :attr:`content_type`, but without parameters (eg, without
        charset, type etc.) and always lowercase.  For example if the content
        type is ``text/HTML; charset=utf-8`` the mimetype would be
        ``'text/html'``.

        .. versionadded:: 0.7
        r   )r$   r   lowerr#   s    r   mimetypezFileStorage.mimetypeP   s*     	  "((+1133r   c                @    | j                          | j                  d   S )zThe mimetype parameters as dict.  For example if the content
        type is ``text/html; charset=utf-8`` the params would be
        ``{'charset': 'utf-8'}``.

        .. versionadded:: 0.7
        r	   )r$   r   r#   s    r   mimetype_paramszFileStorage.mimetype_params\   s!     	  "((++r   c                    ddl m} d}t        |d      rt        |      }t	        |t
              rt        |d      }d}	  || j                  ||       |r|j                          yy# |r|j                          w w xY w)an  Save the file to a destination path or file object.  If the
        destination is a file object you have to close it yourself after the
        call.  The buffer size is the number of bytes held in memory during
        the copy process.  It defaults to 16KB.

        For secure file saving also have a look at :func:`secure_filename`.

        :param dst: a filename, :class:`os.PathLike`, or open file
            object to write to.
        :param buffer_size: Passed as the ``length`` parameter of
            :func:`shutil.copyfileobj`.

        .. versionchanged:: 1.0
            Supports :mod:`pathlib`.
        r   )copyfileobjF
__fspath__wbTN)	shutilr/   r    r   
isinstancer   openr   close)r   dstbuffer_sizer/   	close_dsts        r   savezFileStorage.saveg   sq    $ 	'	3%+Cc3sD/CI	S+6		 y		 s   A' 'A<c                X    	 | j                   j                          y# t        $ r Y yw xY w)z&Close the underlying file if possible.N)r   r5   	Exceptionr#   s    r   r5   zFileStorage.close   s)    	KK 		s    	))c                ,    t        | j                        S N)boolr   r#   s    r   __bool__zFileStorage.__bool__   s    DMM""r   c                    	 t        | j                  |      S # t        $ r: t        | j                  d      r"t        | j                  j                  |      cY S  w xY w)N_file)r   r   AttributeErrorr    rA   )r   r   s     r   __getattr__zFileStorage.__getattr__   sQ    	4;;-- 	 t{{G,t{{00$77	s    ?AAc                ,    t        | j                        S r=   )iterr   r#   s    r   __iter__zFileStorage.__iter__   s    DKK  r   c                h    dt        |       j                   d| j                  d| j                  dS )Nr   z: z (z)>)type__name__r   r   r#   s    r   __repr__zFileStorage.__repr__   s5    4:&&'r$--):"T=N=N<QQSTTr   )NNNNNN)r   zt.IO[bytes] | Noner   
str | Noner   rK   r   rK   r   z
int | Noner   zHeaders | None)returnNone)rL   rK   )rL   int)rL   r   )rL   zdict[str, str])i @  )r6   z$str | os.PathLike[str] | t.IO[bytes]r7   rN   rL   rM   )rL   r>   )r   r   rL   zt.Any)rL   zcabc.Iterator[bytes])rI   
__module____qualname____doc__r   r$   propertyr   r   r+   r-   r9   r5   r?   rC   rF   rJ    r   r   r   r      s     &*##'%)"&"<""< "< 	"<
 !"< #"<  "<HU 0 0   	4 	4 , , MR!7!FI!	!F#!Ur   r   c                  0    e Zd ZdZ	 	 d	 	 	 	 	 	 	 	 	 ddZy)FileMultiDictzA special :class:`MultiDict` that has convenience methods to add
    files to it.  This is used for :class:`EnvironBuilder` and generally
    useful for unittesting.

    .. versionadded:: 0.5
    Nc           	     R   t        |t              r| j                  ||       yt        |t        t        j
                  f      r$|t	        j                  |      }t        |d      }n|}|r|t        j                  |      d   xs d}| j                  |t        ||||             y)aP  Adds a new file to the dict.  `file` can be a file name or
        a :class:`file`-like or a :class:`FileStorage` object.

        :param name: the name of the field.
        :param file: a filename or :class:`file`-like object
        :param filename: an optional filename
        :param content_type: an optional content type
        Nrbr   zapplication/octet-stream)
r3   r   addr   osPathLiker   r4   	mimetypes
guess_type)r   r   filer   r   file_objs         r   add_filezFileMultiDict.add_file   s     dK(HHT4 dS"++./99T?$(t$4HH,$$X.q1O5O  	{8Xt\JKr   )NN)
r   r   r]   z2str | os.PathLike[str] | t.IO[bytes] | FileStorager   rK   r   rK   rL   rM   )rI   rO   rP   rQ   r_   rS   r   r   rU   rU      sK      $#' L L A L 	 L
 ! L 
 Lr   rU   )r!   )
__future__r   collections.abcabccabcr[   rY   typingtior   r   r   	_internalr   r   r
   
structuresr   r   r   rU    r!   rS   r   r   <module>rj      sS    "   	     "  !RU RUj(LIc;./ (LX r   