§
    2?ÄjFn  ã            
       ó  — d Z ddlZddlZ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
mZmZ ddlmZ ddlmZ ddlmZ d	ZdZd
ZdZdZdZ G d„ deej        ¦  «        Z G d„ deej        ¦  «        Zej         G d„ deej        ¦  «        ¦   «         ZdZdZ i dd“dd“dd“dd“dd“d d!“d"d#“d$d%“d&d'“d(d)“d*d+“d,d-“d.d/“d0d1“d2d3“d4d5“d6d7“d8d9d:d;d<d=d>d?d@œ¥Z! G dA„ dBe"¦  «        Z#dC„ Z$ G dD„ dE¦  «        Z% G dF„ dGe&¦  «        Z'dS )Hzx
Definition of the Request object, which acts as a kind of bridge between
what the user wants and what the plugins can.
é    N)ÚBytesIOé   )ÚurlopenÚget_remote_file)ÚPath)Úurlparse)ÚOptionalé   é   é   é   é   c                   ó   — e Zd ZdZdZdZdS )ÚIOModeak  Available Image modes

    This is a helper enum for ``Request.Mode`` which is a composite of a
    ``Request.ImageMode`` and ``Request.IOMode``. The IOMode that tells the
    plugin if the resource should be read from or written to. Available values are

    - read ("r"): Read from the specified resource
    - write ("w"): Write to the specified resource

    ÚrÚwN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚreadÚwrite© ó    úEC:\Projects\Historical\venv\Lib\site-packages\imageio/core/request.pyr   r   !   s$   € € € € € ð	ð 	ð €DØ€E€E€Er   r   c                   ó&   — e Zd ZdZdZdZdZdZdZdS )Ú	ImageModea2  Available Image modes

    This is a helper enum for ``Request.Mode`` which is a composite of a
    ``Request.ImageMode`` and ``Request.IOMode``. The image mode that tells the
    plugin the desired (and expected) image shape. Available values are

    - single_image ("i"): Return a single image extending in two spatial
      dimensions
    - multi_image ("I"): Return a list of images extending in two spatial
      dimensions
    - single_volume ("v"): Return an image extending into multiple dimensions.
      E.g. three spatial dimensions for image stacks, or two spatial and one
      time dimension for videos
    - multi_volume ("V"): Return a list of images extending into multiple
      dimensions.
    - any_mode ("?"): Return an image in any format (the plugin decides the
      appropriate action).

    ÚiÚIÚvÚVú?N)	r   r   r   r   Úsingle_imageÚmulti_imageÚsingle_volumeÚmulti_volumeÚany_moder   r   r   r   r   1   s3   € € € € € ðð ð( €LØ€KØ€MØ€LØ€H€H€Hr   r   c                   óŽ   — e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZed„ ¦   «         Zedefd„¦   «         Zedefd„¦   «         Zd„ ZdS )ÚModea  The mode to use when interacting with the resource

    ``Request.Mode`` is a composite of ``Request.ImageMode`` and
    ``Request.IOMode``. The image mode that tells the plugin the desired (and
    expected) image shape and the ``Request.IOMode`` tells the plugin the way
    the resource should be interacted with. For a detailed description of the
    available modes, see the documentation for ``Request.ImageMode`` and
    ``Request.IOMode`` respectively.

    Available modes are all combinations of ``Request.IOMode`` and ``Request.ImageMode``:

    - read_single_image ("ri")
    - read_multi_image ("rI")
    - read_single_volume ("rv")
    - read_multi_volume ("rV")
    - read_any ("r?")
    - write_single_image ("wi")
    - write_multi_image ("wI")
    - write_single_volume ("wv")
    - write_multi_volume ("wV")
    - write_any ("w?")

    Examples
    --------
    >>> Request.Mode("rI")  # a list of simple images should be read from the resource
    >>> Request.Mode("wv")  # a single volume should be written to the resource

    ÚriÚrIÚrvÚrVúr?ÚwiÚwIÚwvÚwVúw?c                 ój   — |dk    r | d¦  «        S |dk    r | d¦  «        S t          |› d�¦  «        ‚)a¸  Enable Mode("r") and Mode("w")

        The sunder method ``_missing_`` is called whenever the constructor fails
        to directly look up the corresponding enum value from the given input.
        In our case, we use it to convert the modes "r" and "w" (from the v3
        API) into their legacy versions "r?" and "w?".

        More info on _missing_:
        https://docs.python.org/3/library/enum.html#supported-sunder-names
        r   r.   r   r3   z is no valid Mode.)Ú
ValueError)ÚclsÚvalues     r   Ú	_missing_zMode._missing_w   sI   € ð �CŠ<ˆ<Ø�3�t‘9”9ÐØ�cŠ\ˆ\Ø�3�t‘9”9Ðå Ð9Ð9Ð9Ñ:Ô:Ð:r   Úreturnc                 ó6   — t          | j        d         ¦  «        S )Nr   )r   r7   ©Úselfs    r   Úio_modezMode.io_mode‹   s   € å�d”j ”mÑ$Ô$Ð$r   c                 ó6   — t          | j        d         ¦  «        S )Nr
   )r   r7   r;   s    r   Ú
image_modezMode.image_mode�   s   € å˜œ AœÑ'Ô'Ð'r   c                 óZ   — |dk    r| j         S |dk    r| j        S t          d|› �¦  «        ‚)z7For backwards compatibility with the old non-enum modesr   r
   zMode has no item )r=   r?   Ú
IndexError)r<   Úkeys     r   Ú__getitem__zMode.__getitem__“   s;   € à�!Š8ˆ8Ø”<ÐØ�AŠXˆXØ”?Ð"åÐ6°Ð6Ð6Ñ7Ô7Ð7r   N)r   r   r   r   Úread_single_imageÚread_multi_imageÚread_single_volumeÚread_multi_volumeÚread_anyÚwrite_single_imageÚwrite_multi_imageÚwrite_single_volumeÚwrite_multi_volumeÚ	write_anyÚclassmethodr8   Úpropertyr   r=   r   r?   rC   r   r   r   r)   r)   M   sÐ   € € € € € ðð ð: ÐØÐØÐØÐØ€HØÐØÐØÐØÐØ€Iàð;ð ;ñ „[ð;ð& ð%˜ð %ð %ð %ñ „Xð%ð ð(˜Ið (ð (ð (ñ „Xð(ð8ð 8ð 8ð 8ð 8r   r)   )z<videoz<screen>z<clipboard>ú<bytes>zastronaut.pngz%Image of the astronaut Eileen Collinsz
camera.pngz#A grayscale image of a photographerzcheckerboard.pngz'Black and white image of a checkerboardzwood.jpgz'A (repeatable) texture of wooden planksz
bricks.jpgz&A (repeatable) texture of stone bricksz	clock.pngz7Photo of a clock with motion blur (Stefan van der Walt)z
coffee.pngz*Image of a cup of coffee (Rachel Michetti)zchelsea.pngzImage of Stefan's catz
wikkie.pngzImage of Almar's catz	coins.pngz&Image showing greek coins from Pompeiiz	horse.pngz8Image showing the silhouette of a horse (Andreas Preuss)zhubble_deep_field.pngz+Photograph taken by Hubble telescope (NASA)zimmunohistochemistry.pngz"Immunohistochemical (IHC) stainingzmoon.pngz2Image showing a portion of the surface of the moonzpage.pngzA scanned page of textztext.pngzA photograph of handdrawn textzbacterial_colony.tifz+Multi-page TIFF image of a bacterial colonyzNeuronal calcium imaging videoz*The chelsea.png in a zipfile (for testing)z+The chelsea.png in a BSDF file(for testing)z!Animated GIF of a newton's cradlezVideo file of a cockatooz1Video file of a cockatoo with yuv420 pixel formatz2Volumetric image showing a stented abdominal aortaz5A cubemap image of a meadow, e.g. to render a skybox.)zcalcium_imaging.tifzchelsea.zipzchelsea.bsdfznewtonscradle.gifzcockatoo.mp4zcockatoo_yuv420.mp4z	stent.npzzmeadow_cube.jpgc                   ó  — e Zd ZdZdddœdefd„Zd„ Zed„ ¦   «         Zedefd	„¦   «         Z	ede
e         fd
„¦   «         Zej        deddfd„¦   «         Zed„ ¦   «         Zed„ ¦   «         Zd„ Zd„ Zdd„Zd„ Zed„ ¦   «         Zdd„ZdS )ÚRequestaU  ImageResource handling utility.

    Represents a request for reading or saving an image resource. This
    object wraps information to that request and acts as an interface
    for the plugins to several resources; it allows the user to read
    from filenames, files, http, zipfiles, raw bytes, etc., but offer
    a simple interface to the plugins via ``get_file()`` and
    ``get_local_filename()``.

    For each read/write operation a single Request instance is used and passed
    to the can_read/can_write method of a format, and subsequently to
    the Reader/Writer class. This allows rudimentary passing of
    information between different formats and between a format and
    associated reader/writer.

    Parameters
    ----------
    uri : {str, bytes, file}
        The resource to load the image from.
    mode : str
        The first character is "r" or "w", indicating a read or write
        request. The second character is used to indicate the kind of data:
        "i" for an image, "I" for multiple images, "v" for a volume,
        "V" for multiple volumes, "?" for don't care.

    N)Ú	extensionÚformat_hintrT   c                ó  — || _         d | _        d | _        d | _        d | _        || _        d | _        d | _        d | _        d | _	        d | _
        d| _        d | _        d | _        	 t          |¦  «        | _        n # t           $ r t!          d|› �¦  «        ‚w xY w|                      |¦  «         |�'|d         dk    rt!          d|› d�¦  «        ‚|| _        nr| j        �k| j        t$          t&          fv r| j        }nt)          | j        ¦  «        j        }t-          |¦  «        j                             ¦   «         }|dk    r|nd | _        |�t3          j        dt6          ¦  «         |�|d         dk    rt!          d	|› d�¦  «        ‚|| _        d S )
NFzInvalid Request.Mode: r   ú.zD`extension` should be a file extension starting with a `.`, but is `z`.Ú zdThe usage of `format_hint` is deprecated and will be removed in ImageIO v3. Use `extension` instead.zF`format_hint` should be a file extension starting with a `.`, but is `)Úraw_uriÚ	_uri_typeÚ	_filenameÚ
_extensionÚ_format_hintÚ_kwargsÚ_resultÚ_filename_zipÚ_bytesÚ_zipfileÚ_fileÚ_file_is_localÚ_filename_localÚ_firstbytesr)   Ú_moder5   Ú
_parse_uriÚURI_FILENAMEÚ
URI_ZIPPEDr   Úpathr   ÚsuffixÚlowerÚwarningsÚwarnÚDeprecationWarningrT   )r<   ÚuriÚmoderS   rT   Úkwargsrj   Úexts           r   Ú__init__zRequest.__init__Ü   så  € àˆŒØˆŒØˆŒØˆŒØ ˆÔØˆŒØˆŒð "ˆÔØˆŒØˆŒð ˆŒ
Ø#ˆÔØ#ˆÔØˆÔð	>Ý˜d™œˆDŒJˆJøÝð 	>ð 	>ð 	>ÝÐ<°dÐ<Ð<Ñ=Ô=Ð=ð	>øøøð 	�Š˜ÑÔÐð Ð Ø˜Œ|˜sÒ"Ð"Ý ð.Ø )ð.ð .ð .ñô ð ð (ˆDŒOˆOØŒ^Ð'ØŒ~¥,µ
Ð!;Ð;Ð;Ø”~��å ¤Ñ/Ô/Ô4�Ý�t‘*”*Ô#×)Ò)Ñ+Ô+ˆCØ%(¨B¢Y Y˜c˜c°DˆDŒOàÐ"ÝŒMð:å"ñô ð ð Ð" {°1¤~¸Ò'<Ð'<Ýð,Ø'ð,ð ,ð ,ñô ð ð
 'ˆÔÐÐs   Á$A9 Á9Bc                 ób  — | j         j        t          j        u }| j         j        t          j        u }t          |t          ¦  «        �rò|                     d¦  «        r¶|rt          d¦  «        ‚| 	                    dd¦  «        d          
                    ¦   «         }|                     d¦  «        \  }}}|r|dz  }|t          vrt          d|z  ¦  «        ‚t          | _        t!          d	|z   d
¬¦  «        | _        |r| xj        d|z   z  c_        �nL|                     d¦  «        s|                     d¦  «        rt$          | _        || _        �n|                     d¦  «        s|                     d¦  «        rt&          | _        || _        �nÎ|                     d¦  «        rt          | _        |dd…         | _        �nœ|                     t(          ¦  «        r|rt*          | _        || _        �nk|                     t,          ¦  «        r|rt*          | _        || _        �n:t          | _        || _        �n%t          |t.          ¦  «        r/|r-t*          | _        d| _        |                     ¦   «         | _        nát          |t4          ¦  «        r|rt*          | _        d| _        || _        n¯t          |t6          ¦  «        r!t          | _        t          |¦  «        | _        ny|r;t9          |d¦  «        r*t9          |d¦  «        rt:          | _        d| _        || _        n<|r:t9          |d¦  «        r*t9          |d¦  «        rt:          | _        d| _        || _        | j        t          k    rC| j                             d¦  «        r)t>          j          !                    | j        ¦  «        | _        | j        t          k    rÃdD ]À}| j         
                    ¦   «          "                    |¦  «        }|dk    rŒ|dz  }| j        d|…         }	t>          j          #                    |	¦  «        rŒh|st>          j          $                    |	¦  «        r7tJ          | _        |	| j        |d…          &                    d¦  «        f| _'         nŒÁ| j        €AtQ          |¦  «        }
tS          |
¦  «        dk    r|
dd…         d z   }
tU          d!|
z  ¦  «        ‚t$          t&          g}|r| j        |v rtU          d"¦  «        ‚|rn| j        t          tJ          fv rY| j        }| j'        r| j'        d         }t>          j          +                    |¦  «        s|t          v rtU          d#|›d$|›d%�¦  «        ‚| j        t          tJ          fv rm| j'        r=t>          j          ,                    | j'        d         ¦  «        | j'        d         f| _'        n)t>          j          ,                    | j        ¦  «        | _        | j        t          tJ          fv r²| j        }| j'        r| j'        d         }|r<t>          j          +                    |¦  «        st[          t\          j/        d&|¦  «        ‚dS t>          j          0                    |¦  «        }t>          j          +                    |¦  «        st[          t\          j/        d'|¦  «        ‚dS dS )(z$Try to figure our what we were givenzimageio:z$Cannot write to the standard images.ú:r
   éÿÿÿÿú.zip/z.zipzUnknown standard image %r.zimages/T)Úautoú/zhttp://zhttps://zftp://zftps://zfile://é   NrP   r   Úclosez<file>r   ú~)rx   z.zip\r   r   z/\é<   é9   z...z Cannot understand given URI: %s.z-imageio does not support writing to http/ftp.zNo such file: z}. This file looks like one of the standard images, but from imageio 2.1, standard images have to be specified using "imageio:z".zNo such file or directoryzThe directory does not exist)1rq   r=   r   r   r   Ú
isinstanceÚstrÚ
startswithÚRuntimeErrorÚsplitrl   Ú	partitionÚEXAMPLE_IMAGESr5   rh   rY   r   rZ   ÚURI_HTTPÚURI_FTPÚSPECIAL_READ_URISÚ	URI_BYTESÚRETURN_BYTESÚ
memoryviewÚtobytesr`   Úbytesr   ÚhasattrÚURI_FILErb   Úosrj   Ú
expanduserÚfindÚisdirÚisfileri   Úlstripr_   ÚreprÚlenÚIOErrorÚexistsÚabspathÚFileNotFoundErrorÚerrnoÚENOENTÚdirname)r<   rp   Úis_read_requestÚis_write_requestÚfnÚ_Úzip_partÚneedleÚzip_iÚzip_pathÚuri_rÚ	noWritingÚdns                r   rg   zRequest._parse_uri  s_  € àœ)Ô+­v¬{Ð:ˆØœ9Ô,µ´Ð<Ðå�c�3ÑÔñ 7	!à�~Š~˜jÑ)Ô)ð %Ø#ð OÝ&Ð'MÑNÔNÐNØ—Y’Y˜s AÑ&Ô& rÔ*×0Ò0Ñ2Ô2�Ø"$§,¢,¨wÑ"7Ô"7‘��A�xØð !Ø˜&‘L�BØ�^Ð+Ð+Ý$Ð%AÀBÑ%FÑGÔGÐGÝ!-�”Ý!0°¸R±ÀdÐ!KÑ!KÔ!K�”Øð 5Ø�N”N c¨H¡nÑ4�N”NùØ—’ 	Ñ*Ô*ð %¨c¯nªn¸ZÑ.HÔ.Hð %Ý!)�”Ø!$�”‘Ø—’ Ñ)Ô)ð %¨S¯^ª^¸IÑ-FÔ-Fð %Ý!(�”Ø!$�”‘Ø—’ 	Ñ*Ô*ð %Ý!-�”Ø!$ Q R R¤�”‘Ø—’Õ 1Ñ2Ô2ð %°ð %Ý!*�”Ø!$�”‘Ø—’¥Ñ-Ô-ð %Ð2Bð %Ý!*�”Ø!$�”‘å!-�”Ø!$�”‘å˜�ZÑ(Ô(ð 	!¨_ð 	!Ý&ˆDŒNØ&ˆDŒNØŸ+š+™-œ-ˆDŒKˆKÝ˜�UÑ#Ô#ð 	!¨ð 	!Ý&ˆDŒNØ&ˆDŒNØˆDŒKˆKÝ˜�TÑ"Ô"ð 	!Ý)ˆDŒNÝ  ™XœXˆDŒNˆNàð 		!Ý�s˜FÑ#Ô#ð !­°°WÑ(=Ô(=ð !Ý!)�”Ø!)�”Ø �”
øØð 	!Ý�s˜GÑ$Ô$ð !­°°gÑ)>Ô)>ð !Ý!)�”Ø!)�”Ø �”
ð Œ>�\Ò)Ð)¨d¬n×.GÒ.GÈÑ.LÔ.LÐ)ÝœW×/Ò/°´Ñ?Ô?ˆDŒNð Œ>�\Ò)Ð)à-ð ð �Øœ×,Ò,Ñ.Ô.×3Ò3°FÑ;Ô;�Ø˜1’9�9Ø˜Q‘J�EØ#œ~¨f¨u¨fÔ5�HÝ”w—}’} XÑ.Ô.ð ØØ)ð ­R¬W¯^ª^¸HÑ-EÔ-Eð Ý)3˜œà$Ø œN¨5¨6¨6Ô2×9Ò9¸%Ñ@Ô@ð.˜Ô*ð ˜øð Œ>Ð!Ý˜‘I”IˆEÝ�5‰zŒz˜BŠˆØ˜c˜r˜cœ
 UÑ*�ÝÐ<¸uÑDÑEÔEÐEõ �wÐ'ˆ	Øð 	K ¤°)Ð ;Ð ;ÝÐIÑJÔJÐJð ð 
	˜tœ~µ,Å
Ð1KÐKÐKØ”ˆBØÔ!ð +ØÔ'¨Ô*�Ý”G—N’N 2Ñ&Ô&ð ¨Rµ>Ð-AÐ-AÝ�gð (* r r¨2¨2¨2ð/ñô ð ð Œ>�l­JÐ7Ð7Ð7ØÔ!ð Aå”G—O’O DÔ$6°qÔ$9Ñ:Ô:ØÔ& qÔ)ð&�Ô"Ð"õ
 "$¤§¢°´Ñ!@Ô!@�”ð Œ>�l­JÐ7Ð7Ð7Ø”ˆBØÔ!ð +ØÔ'¨Ô*�Øð å”w—~’~ bÑ)Ô)ð Ý+ÝœÐ&AÀ2ñô ð ðð õ ”W—_’_ RÑ(Ô(�Ý”w—~’~ bÑ)Ô)ð Ý+ÝœÐ&DÀbñô ð ð 8Ð7ðð r   c                 ó   — | j         S )a(  Name of the ImageResource.


        The uri for which reading/saving was requested. This
        can be a filename, an http address, or other resource
        identifier. Do not rely on the filename to obtain the data,
        but use ``get_file()`` or ``get_local_filename()`` instead.
        )rZ   r;   s    r   ÚfilenamezRequest.filename¦  s   € ð Œ~Ðr   r9   c                 ó   — | j         S )z¤The (lowercase) extension of the requested filename.
        Suffixes in url's are stripped. Can be None if the request is
        not based on a filename.
        )r[   r;   s    r   rS   zRequest.extension²  s   € ð ŒÐr   c                 ó   — | j         S ©N)r\   r;   s    r   rT   zRequest.format_hintº  s   € àÔ Ð r   Úformatc                 ó4   — || _         | j        €	|| _        d S d S r¯   )r\   r[   )r<   r°   s     r   rT   zRequest.format_hint¾  s%   € à"ˆÔØŒ?Ð"Ø$ˆDŒOˆOˆOð #Ð"r   c                 ó   — | j         S )a.  The mode of the request. The first character is "r" or "w",
        indicating a read or write request. The second character is
        used to indicate the kind of data:
        "i" for an image, "I" for multiple images, "v" for a volume,
        "V" for multiple volumes, "?" for don't care.
        )rf   r;   s    r   rq   zRequest.modeÄ  s   € ð ŒzÐr   c                 ó   — | j         S )z3The dict of keyword arguments supplied by the user.)r]   r;   s    r   rr   zRequest.kwargsÎ  s   € ð Œ|Ðr   c                 ó¦  — | j         j        t          j        u }| j        �| j        S | j        t          k    r9|rt          ¦   «         | _        d| _        �nwt          | j	        ¦  «        | _        �n\| j        t          k    r:|rt          | j        d¦  «        | _        �n.t          | j        d¦  «        | _        �n| j        t          k    r{| j        \  }}|rt          ¦   «         | _        d| _        nÛt          j        |d¦  «        | _        | j                             |d¦  «        | _        t%          | j        ¦  «        | _        n‡| j        t&          pt(          fv rq|rJ ‚t+          j        d¦  «        }|�|                     ¦   «         sd}t1          | j        t3          |¦  «        ¬¦  «        | _        t%          | j        ¦  «        | _        | j        S )	a¸  get_file()
        Get a file object for the resource associated with this request.
        If this is a reading request, the file is in read mode,
        otherwise in write mode. This method is not thread safe. Plugins
        should not close the file when done.

        This is the preferred way to read/write the data. But if a
        format cannot handle file-like objects, they should use
        ``get_local_filename()``.
        NTÚwbÚrbr   ÚIMAGEIO_REQUEST_TIMEOUTr   )Útimeout)rq   r=   r   r   rb   rY   rŠ   r   rc   r`   rh   Úopenr¬   ri   r_   ÚzipfileÚZipFilera   ÚSeekableFileObjectr‡   rˆ   r‘   ÚgetenvÚisdigitr   Úfloat)r<   Úwant_to_writer¬   Únamer¸   s        r   Úget_filezRequest.get_fileÕ  sš  € ð œ	Ô)­V¬\Ð9ˆð
 Œ:Ð!Ø”:ÐàŒ>�YÒ&Ð&Øð 2å$™YœY�”
Ø&*�Ô#Ñ#å$ T¤[Ñ1Ô1�”
‘
àŒ^�|Ò+Ð+Øð 7Ý! $¤-°Ñ6Ô6�”
‘
å! $¤-°Ñ6Ô6�”
‘
àŒ^�zÒ)Ð)à!Ô/‰NˆH�dØð <å$™YœY�”
Ø&*�Ô#Ð#õ !(¤°¸#Ñ >Ô >�”Ø!œ]×/Ò/°°cÑ:Ô:�”
Ý/°´
Ñ;Ô;�”
�
àŒ^¥Ð 3­GÐ4Ð4Ð4Ø$Ð$Ð$Ð$Ý”iÐ 9Ñ:Ô:ˆGØˆ g§o¢oÑ&7Ô&7ˆØ�Ý  ¤½¸g¹¼ÐGÑGÔGˆDŒJÝ+¨D¬JÑ7Ô7ˆDŒJàŒzÐr   c                 óî  — | j         t          k    r| j        S | j        �| j        }n*t          j                             | j        ¦  «        d         }t          j        |d¦  «        \  }| _	        t	          j
        |¦  «         | j        j        t          j        k    rTt          | j	        d¦  «        5 }t!          j        |                      ¦   «         |¦  «         ddd¦  «         n# 1 swxY w Y   | j	        S )zóget_local_filename()
        If the filename is an existing file on this filesystem, return
        that. Otherwise a temporary file is created on the local file
        system which can be used by the format to read from or write to.
        Nr
   Úimageio_rµ   )rY   rh   rZ   rS   r‘   rj   ÚsplitextÚtempfileÚmkstemprd   r|   rq   r=   r   r   r¹   ÚshutilÚcopyfileobjrÂ   )r<   rs   ÚfdÚfiles       r   Úget_local_filenamezRequest.get_local_filename  s
  € ð Œ>�\Ò)Ð)Ø”>Ð!ð Œ~Ð)Ø”n��å”g×&Ò& t¤~Ñ6Ô6°qÔ9�Ý'/Ô'7¸¸ZÑ'HÔ'HÑ$ˆB�Ô$ÝŒH�R‰LŒLˆLàŒyÔ ¥F¤KÒ/Ð/Ý˜$Ô.°Ñ5Ô5ð >¸ÝÔ& t§}¢}¡¤¸Ñ=Ô=Ð=ð>ð >ð >ñ >ô >ð >ð >ð >ð >ð >ð >øøøð >ð >ð >ð >àÔ'Ð's   Â1(C%Ã%C)Ã,C)c                 ó´  — | j         j        t          j        k    �rd}| j        r't          | j        ¦  «                             ¦   «         }n'| j        r d| _        | j         	                    ¦   «         }|�¨| j
        t          k    r|| _        n�| j
        t          k    r| j                             |¦  «         ne| j
        t          k    rUt          j        | j        d         d¦  «        }|                     | j        d         |¦  «         |                     ¦   «          | j        r0| j
        t          k    r | j                             ¦   «          d| _        | j        r | j                             ¦   «          d| _        | j        rO	 t+          j        | j        ¦  «         n-# t.          $ r  t1          j        d| j        › d�¦  «         Y nw xY wd| _        d| _        dS )zžWrap up this request.

        Finishes any pending reads or writes, closes any open files and frees
        any resources allocated by this request.
        NFr   Úar
   z(Failed to delete the temporary file at `z`. Please report this issue.)rq   r=   r   r   rd   r   Ú
read_bytesrc   rb   ÚgetvaluerY   rŠ   r^   r�   ri   rº   r»   r_   Úwritestrr|   ra   r‘   ÚremoveÚ	Exceptionrm   rn   r`   )r<   rŽ   Úzfs      r   ÚfinishzRequest.finish$  së  € ð Œ9Ô¥¤Ò,Ñ,àˆEØÔ#ð .Ý˜TÔ1Ñ2Ô2×=Ò=Ñ?Ô?��ØÔ$ð .Ø&+�Ô#Øœ
×+Ò+Ñ-Ô-�ð Ð Ø”>¥YÒ.Ð.Ø#(�D”L�LØ”^¥xÒ/Ð/Ø”J×$Ò$ UÑ+Ô+Ð+Ð+Ø”^¥zÒ1Ð1Ý œ¨Ô);¸AÔ)>ÀÑDÔD�BØ—K’K Ô 2°1Ô 5°uÑ=Ô=Ð=Ø—H’H‘J”J�Jð
 Œ:ð 	˜$œ.­HÒ4Ð4ØŒJ×ÒÑÔÐØˆDŒJØŒ=ð 	!ØŒM×ÒÑ!Ô!Ð!Ø ˆDŒMð Ôð 	(ðÝ”	˜$Ô.Ñ/Ô/Ð/Ð/øÝð ð ð Ý”ðKØÔ,ðKð Kð Kñô ð ð ð ðøøøð
 $(ˆDÔ ð ˆŒˆˆs   ÆF Æ'GÇGc                 ó$   — d| j         c| _         }|S )z‰For internal use. In some situations a write action can have
        a result (bytes data). That is obtained with this function.
        N)r^   )r<   Úress     r   Ú
get_resultzRequest.get_resultW  s   € ð
 ! $¤,ÐˆŒ�cØˆ
r   c                 óF   — | j         €|                      ¦   «          | j         S )zuThe first 256 bytes of the file. These can be used to
        parse the header to determine the file-format.
        )re   Ú_read_first_bytesr;   s    r   Ú
firstbyteszRequest.firstbytes_  s(   € ð
 ÔÐ#Ø×"Ò"Ñ$Ô$Ð$ØÔÐr   é   c                 ó4  — | j         �| j         d |…         | _        d S 	 |                      ¦   «         }nI# t          $ r< t          j                             | j        ¦  «        rt          ¦   «         | _        Y d S ‚ w xY w	 | 	                    ¦   «         }n# t          $ r d }Y nw xY wt          ||¦  «        | _        	 |€t          d¦  «        ‚|                     |¦  «         d S # t          $ r* d | _        | j        t          k    rt          d¦  «        ‚Y d S w xY w)Nzcannot seek with Nonez*Cannot seek back after getting firstbytes!)r`   re   rÂ   r™   r‘   rj   r”   r¬   rŽ   ÚtellrÓ   Úread_n_bytesÚseekrb   rY   r�   )r<   ÚNÚfr   s       r   rÚ   zRequest._read_first_bytesh  sE  € ØŒ;Ð"Ø#œ{¨2¨A¨2œˆDÔÐÐðØ—M’M‘O”O��øÝð ð ð Ý”7—=’= ¤Ñ/Ô/ð Ý',¡w¤w�DÔ$Ø�F�FØð	øøøð
Ø—F’F‘H”H��øÝð ð ð Ø���ðøøøõ  ,¨A¨qÑ1Ô1ˆDÔð	PØ�9Ý#Ð$;Ñ<Ô<Ð<Ø—’�q‘	”	�	�	�	øÝð Pð Pð Pà!�”
à”>¥XÒ-Ð-Ý!Ð"NÑOÔOÐOð .Ð-Ð-ð	Pøøøs4   Ÿ4 ´AA:Á8A:Á>B ÂB"Â!B"Â;&C# Ã#0DÄD)r9   N)rÜ   )r   r   r   r   r�   rt   rg   rO   r¬   rS   r	   rT   Úsetterrq   rr   rÂ   rÌ   rÕ   rØ   rÛ   rÚ   r   r   r   rR   rR   À   s«  € € € € € ðð ð6 04Èð >'ð >'ð >'À#ð >'ð >'ð >'ð >'ð@Hð Hð HðT ð	ð 	ñ „Xð	ð ð˜3ð ð ð ñ „Xðð ð!˜X cœ]ð !ð !ð !ñ „Xð!ð Ôð% #ð %¨$ð %ð %ð %ñ Ôð%ð
 ðð ñ „Xðð ðð ñ „Xðð6ð 6ð 6ðp(ð (ð (ð.1ð 1ð 1ð 1ðfð ð ð ð ð  ñ „Xð ðPð Pð Pð Pð Pð Pr   rR   c                 óÈ   — t          ¦   «         }t          |¦  «        |k     r@|                      |t          |¦  «        z
  ¦  «        }|sn||z  }t          |¦  «        |k     °@|S )z“read_n_bytes(file, n)

    Read n bytes from the given file, or less if the file has less
    bytes. Returns zero bytes if the file is closed.
    )rŽ   r˜   r   )râ   rá   ÚbbÚextra_bytess       r   rß   rß   ‡  sd   € õ 
‰Œ€BÝ
ˆb‰'Œ'�AŠ+ˆ+Ø—f’f˜Q¥ R¡¤™[Ñ)Ô)ˆØð 	ØØ
ˆkÑˆõ	 ˆb‰'Œ'�AŠ+ˆ+ð
 €Ir   c                   óH   — e Zd ZdZd„ Zdd„Zdd„Zd„ Zdd	„Zd
„ Z	d„ Z
d„ ZdS )r¼   a)  A readonly wrapper file object that add support for seeking, even if
    the wrapped file object does not. The allows us to stream from http and
    still use Pillow.

    readline matches BytesIO: it returns bytes up to the next newline, EOF, or
    size, using the same buffer as read/seek.
    c                 óL   — || _         d| _        d| _        d| _        d| _        d S )Nr   r   F)râ   Ú_iÚ_bufferÚ	_have_allÚclosed)r<   râ   s     r   rt   zSeekableFileObject.__init__Ÿ  s)   € ØˆŒØˆŒØˆŒØˆŒØˆŒˆˆr   Nc                 ó  — |€nt          |¦  «        }|dk     rd }| j        s�d}|€!| j                             ¦   «         }d| _        n[| j        |z   }|t          | j        ¦  «        z
  }|dk    r4| j                             |¦  «        }t          |¦  «        |k     rd| _        | xj        |z  c_        |€| j        | j        d …         }n| j        | j        | j        |z   …         }| xj        t          |¦  «        z  c_        |S )Nr   r   T)Úintrë   râ   r   ré   r˜   rê   )r<   ÚnÚmoreÚwant_iÚ	want_morer×   s         r   r   zSeekableFileObject.read¦  s  € àˆ9Øå�A‘”ˆAØ�1ŠuˆuØ�ð Œ~ð 	!ØˆDØˆyØ”v—{’{‘}”}�Ø!%�”�àœ 1™�Ø"¥S¨¬Ñ%6Ô%6Ñ6�	Ø˜q’=�=Øœ6Ÿ;š; yÑ1Ô1�DÝ˜4‘y”y 9Ò,Ð,Ø)-˜œØˆLŒL˜DÑ ˆLŒLð ˆ9Ø”,˜tœw˜y˜yÔ)ˆCˆCà”,˜tœw¨¬°1©Ð4Ô5ˆCØˆŒ•3�s‘8”8ÑˆŒàˆ
r   rw   c                 ó¼  — |€d}nt          |¦  «        }|dk    rdS | j        s¿| j                             d| j        ¦  «        }t          | j        ¦  «        | j        z
  }|dk    r}|dk     s||k     rq|dk     r!| j                             ¦   «         }d| _        n:| j                             ||z
  ¦  «        }t          |¦  «        ||z
  k     rd| _        | xj        |z  c_        | j                             d| j        ¦  «        }|dk    rt          | j        ¦  «        | j        z
  }n|dz   | j        z
  }|dk    rt          ||¦  «        }|                      |¦  «        S )Nrw   r   r   ó   
Tr
   )	rî   rë   rê   r“   ré   r˜   râ   r   Úmin)r<   ÚsizeÚnlÚunreadrð   rï   s         r   ÚreadlinezSeekableFileObject.readlineÇ  sM  € Øˆ<ØˆDˆDå�t‘9”9ˆDØ�qŠyˆyØ�sàŒ~ð 	%Ø”×"Ò" 5¨$¬'Ñ2Ô2ˆBÝ˜œÑ&Ô&¨¬Ñ0ˆFØ�RŠxˆx˜T AšX˜X¨°$ª¨Ø˜!’8�8Øœ6Ÿ;š;™=œ=�DØ%)�D”N�Nàœ6Ÿ;š; t¨f¡}Ñ5Ô5�DÝ˜4‘y”y 4¨&¡=Ò0Ð0Ø)-˜œØ�” Ñ$�”àŒ\×Ò˜u d¤gÑ.Ô.ˆØ�Š8ˆ8Ý�D”LÑ!Ô! D¤GÑ+ˆAˆAà�Q‘˜œÑ ˆAØ�1Š9ˆ9Ý�A�t‘”ˆAØ�yŠy˜‰|Œ|Ðr   c                 ó   — | j         S r¯   )ré   r;   s    r   rÞ   zSeekableFileObject.tellå  s	   € ØŒwˆr   r   c                 ó  — t          |¦  «        }|dk    r(|dk     rt          dt          |¦  «        z   ¦  «        ‚|}nx|dk    rt          d| j        |z   ¦  «        }nY|dk    rA| j        s|                      ¦   «          t          dt          | j        ¦  «        |z   ¦  «        }nt          d|z  ¦  «        ‚|t          | j        ¦  «        k    rn1| j        s*|| j        k    sJ ‚|                      || j        z
  ¦  «         || _        | j        S )Nr   znegative seek value r
   r   z(invalid whence (%s, should be 0, 1 or 2))	rî   r5   r�   Úmaxré   rë   r   r˜   rê   )r<   r   rq   Úreal_is       r   rà   zSeekableFileObject.seekè  s  € õ �‰FŒFˆØ�1Š9ˆ9Ø�1ŠuˆuÝ Ð!7½#¸a¹&¼&Ñ!@ÑAÔAÐAØˆFˆFØ�QŠYˆYÝ˜˜DœG a™KÑ(Ô(ˆFˆFØ�QŠYˆYØ”>ð Ø—	’	‘”�Ý˜�C ¤Ñ-Ô-°Ñ1Ñ2Ô2ˆFˆFåÐGÈ!ÑKÑLÔLÐLð •S˜œÑ&Ô&Ò&Ð&ØØ”ð 	(Ø˜DœGÒ#Ð#Ð#Ð#Ø�IŠI�f˜tœwÑ&Ñ'Ô'Ð'àˆŒØŒwˆr   c                 óF   — d| _         | j                             ¦   «          d S ©NT)rì   râ   r|   r;   s    r   r|   zSeekableFileObject.close  s   € ØˆŒØŒ�Š‰Œˆˆˆr   c                 ó   — dS )NFr   r;   s    r   ÚisattyzSeekableFileObject.isatty  s   € Øˆur   c                 ó   — dS rÿ   r   r;   s    r   ÚseekablezSeekableFileObject.seekable  s   € Øˆtr   r¯   )rw   )r   )r   r   r   r   rt   r   rù   rÞ   rà   r|   r  r  r   r   r   r¼   r¼   –  s¦   € € € € € ðð ðð ð ðð ð ð ðBð ð ð ð<ð ð ðð ð ð ð8ð ð ðð ð ðð ð ð ð r   r¼   c                   ó   — e Zd ZdZdS )ÚInitializationErrora  The plugin could not initialize from the given request.

    This is a _internal_ error that is raised by plugins that fail to handle
    a given request. We use this to differentiate incompatibility between
    a plugin and a request from an actual error/bug inside a plugin.

    N)r   r   r   r   r   r   r   r  r    s   € € € € € ðð ð 	€Dr   r  )(r   r�   r‘   Úior   rº   rÆ   rÈ   Úenumrm   Úcorer   r   Úpathlibr   Úurllib.parser   Útypingr	   rŠ   r�   rh   ri   r‡   rˆ   r�   ÚEnumr   r   Úuniquer)   r‰   r‹   r†   ÚobjectrR   rß   r¼   rÓ   r  r   r   r   ú<module>r     s8  ððð ð
 €€€Ø 	€	€	€	Ø Ð Ð Ð Ð Ð Ø €€€Ø €€€Ø €€€Ø €€€Ø €€€à +Ð +Ð +Ð +Ð +Ð +Ð +Ð +à Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð ð €	Ø€Ø€Ø€
Ø€Ø
€ðð ð ð ð ˆS�$”)ñ ô ð ð ð ð ð ð ��T”Yñ ô ð ð8 „ðL8ð L8ð L8ð L8ð L8ˆ3�”	ñ L8ô L8ñ „ðL8ð^ 8Ð ð €ðØÐ<ðàÐ7ðð ÐAðð Ð9ð	ð
 Ð:ðð ÐJðð Ð>ðð Ð*ðð Ð(ðð Ð9ðð ÐKðð ÐJðð Ð Dðð ÐDðð Ð(ðð  Ð0ð!ð" ÐIð#ð$ <Ø?ØAØ<Ø.ØNØEØNð3ð ð €ð:DPð DPð DPð DPð DPˆfñ DPô DPð DPðNð ð ðvð vð vð vð vñ vô vð vðr		ð 		ð 		ð 		ð 		˜)ñ 		ô 		ð 		ð 		ð 		r   