§
    ¶¯¸j¥{  ã                   ó  — 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 mZ d dlm	Z	 d dl
mZmZmZmZmZmZmZ d dlmZmZmZ 	 d dlZd dlZn# e$ r dZdZY nw xY wdd„Z G d„ d	e¦  «        Z G d
„ dej        ¦  «        ZdS )é    N)ÚdatetimeÚ	timedelta)Úpartial)ÚAnyÚDictÚIOÚListÚOptionalÚTupleÚUnion)Ú	file_lockÚget_cache_dirÚPathHandlerÚreturnc                 ó®  — |                       d¦  «         | j        | _        t          | t          j        ¦  «        r9t	          j        |                      ¦   «                              d¦  «        ¦  «        } 	 | 	                    | |||¬¦  «         d S # t          j        j        $ r/}t          d|› t          |¦  «        j        › d|› �¦  «        |‚d }~ww xY w)Nr   úutf-8©ÚConfigzError in file upload - ú: )ÚseekÚ_closeÚcloseÚ
isinstanceÚioÚStringIOÚBytesIOÚgetvalueÚencodeÚupload_fileobjÚbotocoreÚ
exceptionsÚClientErrorÚOSErrorÚtypeÚ__name__)ÚselfÚclientÚbucketÚs3_pathÚtransfer_configÚes         ú`/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/iopath/common/s3.pyÚs3_close_and_uploadr-      së   € à‡I‚Iˆa�L„L€Lð ”€D„Jõ �$�œÑ$Ô$ð ;ÝŒz˜$Ÿ-š-™/œ/×0Ò0°Ñ9Ô9Ñ:Ô:ˆðWØ×ÒØØØØ"ð	 	ñ 	
ô 	
ð 	
ð 	
ð 	
øõ ÔÔ*ð Wð Wð WÝÐN°ÐNµt¸A±w´wÔ7GÐNÐNÈ1ÐNÐNÑOÔOÐUVÐVøøøøðWøøøs   Á6B ÂCÂ%*CÃCc                   óx  — e Zd ZdZdZdZdZ	 	 	 d0dee         dee         d	ee	         fd
„Z
dee         fd„Zdedeeef         fd„Zdefd„Zdefd„Zdededefd„Z	 d1dededededef
d„Zdeee         ee         f         dedededef
d„Z	 	 	 	 	 	 d2ded ed!ed"ee         d#ee         d$ee         d%ee         dedeee         ee         f         fd&„Z	 d1d'ededededef
d(„Zdedee	         fd)„Zdededefd*„Zdededefd+„Zdededefd,„Zdededee         fd-„Z dededdfd.„Z!dededdfd/„Z"dS )3ÚS3PathHandleru€  
    Support for Amazon Simple Storage Service (S3)

    PathHanlder methods, at a glance:

     File     --torch.load->     In     --open(..., 'w')->   Amazon    <- _exists,_isfile,_isdir,_ls,_rm ...
    System   <-torch.save--     Mem.   <-open(..., 'r')--      S3
            <----------------_copy_from_local-----------------
            ----------------_get_local_path ----------------->

    Mem usage, for processing N bytes:
        open(..., mode)
            mode=='w':    2N,  due to fully buffering user input,
                                *and doing naive conversion from StringIO -> BytesIO*,
                                before writing to S3
                                ^ Potential for optimization.
            mode=='wb':    N,  due to fully buffering user input, before writing to S3.
            mode=='r':     N,  due to fully buffering file in memory
            mode=='rb':    N,  due to fully buffering file in memory
        _copy_from_local: â‰ˆ0.  boto3 streams from file system directly to s3
        _get_local_path:  â‰ˆ0.  boto3 streams from s3 directly from s3 to file system

    NOTE:
        S3 doesn't have a notion of directories.  This pathhandler simulates
        directories via uploading objects with a name ending in a slash, on calls to mkdir().
        ls() calls return objects as if they were in a directory structure, via
        boto3's options.
    Fzs3://Ús3_cacheNÚsamlÚ	cache_dirÚprofileÚtransfer_config_kwargsc                 óP   — || _         || _        ddlm}  |di |r|ni ¤Ž| _        dS )a¬  
        Args:
            cache_dir (str): Local filesystem directory to use for caching. If None,
                uses default from `file_io.get_cache_dir()`.
            transfer_config_kwargs (dict): Settings for boto3.s3.transfer.TransferConfig.
                Used to specify settings for multipart transfers.
                See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3.html for details.
        r   )ÚTransferConfigN© )r2   r3   Úboto3.s3.transferr6   r*   )r&   r2   r3   r4   r6   s        r,   Ú__init__zS3PathHandler.__init__[   sX   € ð  #ˆŒØˆŒà4Ð4Ð4Ð4Ð4Ð4ð  .˜~ð  
ð  
Ø)?ÐGÐ%Ð%ÀRð 
ð  
ˆÔÐÐó    r   c                 ó   — | j         gS )zg
        Returns:
            List[str]: the list of URI prefixes this PathHandler can support
        )Ú	S3_PREFIX©r&   s    r,   Ú_get_supported_prefixesz%S3PathHandler._get_supported_prefixesu   s   € ð
 ”ÐÐr:   Úuric                 ó°   — |                      | j        d¦  «                             d¦  «        }|d         }d                     |dd…         ¦  «        }||fS )zô
        Parses a "s3://bucket/path" URI into `bucket` and `path` strings.

        Args:
            uri (str): A s3:// URI.

        Returns:
            bucket (str): the s3 bucket.
            path (str): the path on the s3 system.
        Ú ú/r   é   N)Úreplacer<   ÚsplitÚjoin)r&   r?   Úsplitsr(   Úpaths        r,   Ú
_parse_urizS3PathHandler._parse_uri|   sS   € ð —’˜Tœ^¨RÑ0Ô0×6Ò6°sÑ;Ô;ˆØ˜”ˆØ�xŠx˜˜q˜r˜rœ
Ñ#Ô#ˆØ�tˆ|Ðr:   r(   c                 ó®  — t          j        t          ¦  «        }t          | d¦  «        s¦	 t	          j        | j        ¬¦  «        }|                     d¦  «        | _        np# t          j	        j
        $ rY}|                     d¦  «         |                     d¦  «         t          d|› t          |¦  «        j        › d|› �¦  «        |‚d }~ww xY w| j        S )Nr'   )Úprofile_nameÚs3zÚ See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html  for method of using environment variable to point to aws credentials, and the  order in which boto will search for said credentials. a&  Boto3 searches via the order below.  If on FAIR Cluster, method 4 may be most convenient.The order in which Boto3 searches for credentials is:1) [UNUSED] Passing credentials as parameters in the boto.client() method2) [UNUSED] Passing credentials as parameters when creating a Session object3) Environment variables       AWS_ACCESS_KEY_ID - The access key for your AWS account.       AWS_SECRET_ACCESS_KEY - The secret key for your AWS account.       AWS_SESSION_TOKEN - The session key for your AWS account.           This is only needed when you are using temporary credentials. 4) Shared credential file (~/.aws/credentials)       default: ~/.aws/credentials       changed via: AWS_SHARED_CREDENTIALS_FILE       *for FAIR cluster usage: `export AWS_SHARED_CREDENTIALS_FILE=~/.fairusers_aws/credentials`5) AWS config file (~/.aws/config)       default: ~/.aws/config       changed via: AWS_CONFIG_FILE6) Assume Role provider7) Boto2 config file (/etc/boto.cfg and ~/.boto)8) Instance metadata service on an Amazon EC2 instance that has an IAM role configured.z%Error in making s3 client for bucket r   )ÚloggingÚ	getLoggerr%   ÚhasattrÚboto3ÚSessionr3   r'   r    r!   ÚNoCredentialsErrorÚerrorr#   r$   )r&   r(   ÚloggerÚsessionr+   s        r,   Ú_get_clientzS3PathHandler._get_client�   s  € ÝÔ"¥8Ñ,Ô,ˆÝ�t˜XÑ&Ô&ð $	ð#Ýœ-°T´\ÐBÑBÔB�à%Ÿnšn¨TÑ2Ô2�”�øÝÔ&Ô9ð ð ð Ø—’ðNñô ð ð
 —’ðnñô ð õ, ð/¸Fð /Ý˜A‘w”wÔ'ð/ð /Ø+,ð/ð /ñô ð ðøøøøð9øøøðB Œ{Ðs   «4A  Á CÁ4ACÃCrH   c                 ó¢   — |                       |¦  «        \  }}t          j                             t	          | j        ¦  «        | j        |¦  «        S )a  
        Helper that returns a local cache path for a given uri.
        Args:
            path (str): A URI supported by this PathHandler.
        Returns:
            local_cache_path (str): a file path which exists on the local file system,
            in a cache directory.
        )rI   ÚosrH   rF   r   r2   ÚCACHE_SUBDIR_NAME)r&   rH   r(   Ú	file_paths       r,   Ú_local_cache_pathzS3PathHandler._local_cache_path¸   sF   € ð !ŸOšO¨DÑ1Ô1Ñˆ�	ÝŒw�|Š|Ý˜$œ.Ñ)Ô)¨4Ô+AÀ9ñ
ô 
ð 	
r:   Úkwargsc                 ó†  — t          j        t          ¦  «        }|                      |¦  «         |                     d¦  «        rt          d¦  «        ‚|                      |¦  «        sJ ‚|                      |¦  «        }t          |¦  «        5  t          j
                             |¦  «        rÀ|                      |¦  «        }|�©|d         }t          j                             t          j
                             |¦  «        ¦  «                             ¦   «         }||z
  t          j        d¬¦  «        k    r7|                     d                     ||¦  «        ¦  «         |cddd¦  «         S |                     d                     |¦  «        ¦  «         |d	z   }t          j
                             |¦  «        rt          j        |¦  «         |                      |¦  «        \  }	}
|                      |	¦  «        }	 |                     |	|
|| j        ¬
¦  «        }t7          j        ||¦  «         	 t          j        |¦  «         n:# t:          $ r Y n.w xY w# 	 t          j        |¦  «         w # t:          $ r Y w w xY wxY w|                     d                     ||¦  «        ¦  «         |cddd¦  «         S # 1 swxY w Y   dS )aZ  
        Get a filepath which is compatible with native Python I/O such as `open`
        and `os.path`.
        If URI points to a remote resource, this function may download and cache
        the resource to local disk. In this case, the cache stays on filesystem
        (under `file_io.get_cache_dir()`) and will be used by a different run.
        Therefore this function is meant to be used with read-only resources.
        Args:
            path (str): A URI supported by this PathHandler
        Returns:
            local_path (str): a file path which exists on the local file system
        rB   z@S3PathHandler does not currently support downloading directoriesNÚLastModifiedr   )ÚminuteszURL {} was already cached in {}zCaching {} ...z.tmpr   zURL {} cached in {})rM   rN   r%   Ú_check_kwargsÚendswithÚNotImplementedErrorÚ_isfiler[   r   rX   rH   ÚexistsÚ_head_objectÚdtr   ÚfromtimestampÚgetmtimeÚ
astimezoner   ÚinfoÚformatÚisfileÚunlinkrI   rV   Údownload_filer*   ÚshutilÚmoveÚ	Exception)r&   rH   r\   rT   Ú
local_pathÚresponseÚ	remote_dtÚlocal_dtÚtmpr(   r)   r'   s               r,   Ú_get_local_pathzS3PathHandler._get_local_pathË   s&  € õ Ô"¥8Ñ,Ô,ˆØ×Ò˜6Ñ"Ô"Ð"ð �=Š=˜ÑÔð 	Ý%ØRñô ð ð �|Š|˜DÑ!Ô!Ð!Ð!Ð!à×+Ò+¨DÑ1Ô1ˆ
Ý�zÑ"Ô"ð 1	ð 1	ÝŒw�~Š~˜jÑ)Ô)ð *ð  ×,Ò,¨TÑ2Ô2�ØÐ'Ø (¨Ô 8�IÝ!œ{×8Ò8Ýœ×(Ò(¨Ñ4Ô4ñ ô  ç ’j‘l”lð ð ! 9Ñ,µ´ÀQÐ0GÑ0GÔ0GÒGÐGØŸšØ=×DÒDÀTÈ:ÑVÔVñô ð ð  *ð+1	ð 1	ð 1	ð 1	ñ 1	ô 1	ð 1	ð 1	ð. �KŠKÐ(×/Ò/°Ñ5Ô5Ñ6Ô6Ð6Ø˜vÑ%ˆCõ Œw�~Š~˜cÑ"Ô"ð Ý”	˜#‘”�à"Ÿošo¨dÑ3Ô3‰OˆF�GØ×%Ò% fÑ-Ô-ˆFðØ!×/Ò/Ø˜G S°Ô1Eð 0ñ ô �õ ”˜C Ñ,Ô,Ð,ðÝ”I˜c‘N”N�N�NøÝ ð ð ð Ø�DðøøøøðÝ”I˜c‘N”N�N�NøÝ ð ð ð Ø�Dðøøøøøøð �KŠKÐ-×4Ò4°T¸:ÑFÔFÑGÔGÐGØðc1	ð 1	ð 1	ð 1	ñ 1	ô 1	ð 1	ð 1	ð 1	ð 1	ð 1	ð 1	øøøð 1	ð 1	ð 1	ð 1	ð 1	ð 1	st   ÂCJ6Å.BJ6Ç<3IÈ0IÉJ6É
IÉJ6ÉIÉJ6ÉI<ÉI,É+I<É,
I9	É6I<É8I9	É9I<É<-J6Ê6J:Ê=J:rr   Údst_pathÚ	overwritec                 óÎ  — |                       |¦  «         |                     d¦  «        s|                     d¦  «        rt          d¦  «        ‚|sX|                      |¦  «        rCt	          j        t          ¦  «        }|                     d                     |¦  «        ¦  «         dS |  	                    |¦  «        \  }}|  
                    |¦  «        }	 |                     |||| j        ¬¦  «         dS # t          j        j        $ rY}	t	          j        t          ¦  «        }|                     d                     t!          |	¦  «        ¦  «        ¦  «         Y d}	~	dS d}	~	ww xY w)	aÄ  
        Copies a local file to the specified URI.
        If the URI is another local path, this should be functionally identical
        to copy.
        Args:
            local_path (str): a file path which exists on the local file system
            dst_path (str): A URI supported by this PathHandler
            overwrite (bool): Bool flag for forcing overwrite of existing URI
        Returns:
            status (bool): True on success
        rB   z>S3PathHandler does not currently support uploading directoriesú*Error: Destination path {} already exists.Fr   TzError in file upload - {}N)r`   ra   rb   Ú_existsrM   rN   r%   rS   rk   rI   rV   Úupload_filer*   r    r!   r"   Ústr)
r&   rr   rx   ry   r\   rT   r(   r)   r'   r+   s
             r,   Ú_copy_from_localzS3PathHandler._copy_from_local  sh  € ð 	×Ò˜6Ñ"Ô"Ð"ð ×Ò˜sÑ#Ô#ð 	 x×'8Ò'8¸Ñ'=Ô'=ð 	Ý%ØPñô ð ð ð 	˜TŸ\š\¨(Ñ3Ô3ð 	ÝÔ&¥xÑ0Ô0ˆFØ�LŠLÐE×LÒLÈXÑVÔVÑWÔWÐWØ�5àŸ/š/¨(Ñ3Ô3‰ˆ�Ø×!Ò! &Ñ)Ô)ˆð	Ø×Ò˜z¨6°7À4ÔCWÐÑXÔXÐXØ�4øÝÔ"Ô.ð 	ð 	ð 	ÝÔ&¥xÑ0Ô0ˆFØ�LŠLÐ4×;Ò;½CÀ¹F¼FÑCÔCÑDÔDÐDØ�5�5�5�5�5øøøøð	øøøs   ÃC7 Ã7E$ÄAEÅE$Úbufferr'   r)   r*   c                 ó„   — |j         |_        t          t          ||||¬¦  «        }t	          j        ||¦  «        |_         d S )N)r'   r(   r)   r*   )r   r   r   r-   ÚtypesÚ
MethodType)r&   r€   r'   r(   r)   r*   Úfns          r,   Ú_decorate_buf_with_s3_methodsz+S3PathHandler._decorate_buf_with_s3_methods>  sL   € ð œˆŒõ ÝØØØØ+ð
ñ 
ô 
ˆõ" Ô'¨¨FÑ3Ô3ˆŒˆˆr:   ÚréÿÿÿÿÚmodeÚ	bufferingÚencodingÚerrorsÚnewlineÚread_chunk_sizec                 ó"  — |                       |¦  «         |                      |¦  «        \  }	}
|                      |	¦  «        }d|v ré|€�t          j        ¦   «         }	 |                     |	|
|| j        ¬¦  «         nF# t          j        j	        $ r/}t          d|	› t          |¦  «        j        › d|› �¦  «        |‚d}~ww xY w|                     d¦  «         nt          ||	|
|¦  «        }|                     |	|
¬¦  «        d         | _        d}d	|vrd
}t          j        |d|ddd¬¦  «        S |S d|v rKd	|v rt          j        ¦   «         }nt          j        ¦   «         }|                      |||	|
| j        ¦  «         |S t          d|› �¦  «        ‚)a¨  
        Open a stream to a URI, similar to the built-in `open`.
        Args:
            path (str): A URI supported by this PathHandler
            mode (str): Specifies the mode in which the file is opened. It defaults
                to 'r'.
            buffering (int): An optional integer used to set the buffering policy.
                Pass 0 to switch buffering off and an integer >= 1 to indicate the
                size in bytes of a fixed-size chunk buffer. When no buffering
                argument is given, the default buffering policy depends on the
                underlying I/O implementation.
        Returns:
            file: a file-like object.
        r†   Nr   z%Error in making s3 client for bucekt r   r   ©ÚBucketÚKeyÚContentLengthÚbr   TF)Úwrite_throughrŠ   r‹   rŒ   Úline_bufferingÚwzUnsupported open mode )r`   rI   rV   r   r   Údownload_fileobjr*   r    r!   r"   r#   r$   r%   r   ÚS3ChunkReadIOÚ
get_objectÚlengthÚTextIOWrapperr   r…   )r&   rH   rˆ   r‰   rŠ   r‹   rŒ   r�   r\   r(   r)   r'   r€   r+   s                 r,   Ú_openzS3PathHandler._open`  s  € ð8 	×Ò˜6Ñ"Ô"Ð"àŸ/š/¨$Ñ/Ô/‰ˆ�Ø×!Ò! &Ñ)Ô)ˆð �$ˆ;ˆ;ØÐ&õ œ™œ�ðð
 ×+Ò+Ø ¨¸Ô8Lð ,ñ ô ð ð øõ  Ô*Ô6ð ð ð Ý!ð3Àð 3Ý ™7œ7Ô+ð3ð 3Ø/0ð3ð 3ñô ð ðøøøøðøøøð —’˜A‘”��õ ' v¨v°wÀÑPÔP�à ×+Ò+°6¸wÐ+ÑGÔGÈÔXˆDŒKð ˆHà˜$ˆˆØ"�ÝÔ'ð Ø"&Ø%ØØ Ø#(ð	ñ 	ô 	ð 	ð �à�Dˆ[ˆ[à�dˆ{ˆ{Ýœ™œ��åœ™œ�ð ×.Ò.Ø˜ ¨°Ô1Eñô ð ð ˆMõ Ð9°4Ð9Ð9Ñ:Ô:Ð:s   ÁA< Á<B?Â*B:Â:B?Úsrc_pathc                 ó²  — |                       |¦  «         |sX|                      |¦  «        rCt          j        t          ¦  «        }|                     d                     |¦  «        ¦  «         dS |                      |¦  «        \  }}|                      |¦  «        \  }}	||k    s
J d¦   «         ‚|                      |¦  «        }
	 |
 	                    ||dœ||	| j
        ¬¦  «         dS # t          j        j        $ rY}t          j        t          ¦  «        }|                     d                     t          |¦  «        ¦  «        ¦  «         Y d}~dS d}~ww xY w)	aV  
        Copies a source path to a destination path.
        Args:
            src_path (str): A URI supported by this PathHandler
            dst_path (str): A URI supported by this PathHandler
            overwrite (bool): Bool flag for forcing overwrite of existing file
        Returns:
            status (bool): True on success
        r{   Fz*For now, can only _copy() within a bucket.r�   r   TzError in file copy - {}N)r`   r|   rM   rN   r%   rS   rk   rI   rV   Úcopyr*   r    r!   r"   r~   )r&   r�   rx   ry   r\   rT   Ú
src_bucketÚsrc_s3_pathÚ
dst_bucketÚdst_s3_pathr'   r+   s               r,   Ú_copyzS3PathHandler._copyÇ  sp  € ð 	×Ò˜6Ñ"Ô"Ð"àð 	˜TŸ\š\¨(Ñ3Ô3ð 	ÝÔ&¥xÑ0Ô0ˆFØ�LŠLÐE×LÒLÈXÑVÔVÑWÔWÐWØ�5à"&§/¢/°(Ñ";Ô";Ñˆ
�KØ"&§/¢/°(Ñ";Ô";Ñˆ
�KØ˜ZÒ'Ð'Ð'Ð)UÑ'Ô'Ð'Ø×!Ò! *Ñ-Ô-ˆð	Ø�KŠKà(Ø&ðð ð ØØÔ+ð ñ ô ð ð �4øÝÔ"Ô.ð 	ð 	ð 	ÝÔ&¥xÑ0Ô0ˆFØ�LŠLÐ2×9Ò9½#¸a¹&¼&ÑAÔAÑBÔBÐBØ�5�5�5�5�5øøøøð	øøøs   Ã!C) Ã)EÃ=AEÅEc           	      óX  — |                       |¦  «        \  }}|                      |¦  «        }	 |                     ||¬¦  «        }|S # t          j        j        $ rM}|j        d         d         dk    r+t          d|› dt          |¦  «        j	        › d|› �¦  «        |‚Y d }~d S d }~ww xY w)Nr�   ÚErrorÚMessagezBad RequestzError in checking s3 path ú - r   )
rI   rV   Úhead_objectr    r!   r"   rs   r#   r$   r%   )r&   rH   r(   r)   r'   rs   r+   s          r,   re   zS3PathHandler._head_objectñ  sÑ   € ØŸ/š/¨$Ñ/Ô/‰ˆ�Ø×!Ò! &Ñ)Ô)ˆð		à×)Ò)°¸WÐ)ÑEÔEˆHØˆOøÝÔ"Ô.ð 	ð 	ð 	ØŒz˜'Ô" 9Ô-°Ò>Ð>ÝØU°ÐUÐU½dÀ1¹g¼gÔ>NÐUÐUÐRSÐUÐUñô àðð �4�4�4�4�4øøøøð	øøøs   ¯A ÁB)ÁAB$Â$B)c                 óZ   — |                       |¦  «         |                      |¦  «        duS )zÆ
        Checks if there is a resource at the given URI.
        Args:
            path (str): A URI supported by this PathHandler
        Returns:
            bool: true if the path exists
        N)r`   re   ©r&   rH   r\   s      r,   r|   zS3PathHandler._exists   s1   € ð 	×Ò˜6Ñ"Ô"Ð"à× Ò  Ñ&Ô&¨dÐ2Ð2r:   c                 ót   — |                       |¦  «         |                     d¦  «         o | j        |fi |¤ŽS )zÌ
        Checks if the resource at the given URI is a file.
        Args:
            path (str): A URI supported by this PathHandler
        Returns:
            bool: true if the path is a file
        rB   ©r`   ra   r|   r«   s      r,   rc   zS3PathHandler._isfile  sH   € ð 	×Ò˜6Ñ"Ô"Ð"ð —=’= Ñ%Ô%Ð%ÐF¨,¨$¬,°tÐ*FÐ*F¸vÐ*FÐ*FÐFr:   c                 ór   — |                       |¦  «         |                     d¦  «        o | j        |fi |¤ŽS )zÖ
        Checks if the resource at the given URI is a directory.
        Args:
            path (str): A URI supported by this PathHandler
        Returns:
            bool: true if the path is a directory
        rB   r­   r«   s      r,   Ú_isdirzS3PathHandler._isdir  sE   € ð 	×Ò˜6Ñ"Ô"Ð"ð �}Š}˜SÑ!Ô!ÐB l d¤l°4Ð&BÐ&B¸6Ð&BÐ&BÐBr:   c           	      óª  — |                       |¦  «         |                      |¦  «        \  }}|                      |¦  «        }	 |                     d¦  «        }|                     ||d¬¦  «        }d„ |D ¦   «         }d„ |D ¦   «         }	||	z   S # t
          j        j        $ r0}
t          d|› dt          |
¦  «        j
        › d|
› �¦  «        |
‚d	}
~
ww xY w)
zÚ
        List the contents of the directory at the provided URI.
        Args:
            path (str): A URI supported by this PathHandler
        Returns:
            List[str]: list of contents in given path
        Úlist_objects_v2rB   )r�   ÚPrefixÚ	Delimiterc                 óP   — g | ]#}|                      d g ¦  «        D ]
}|d         ‘ŒŒ$S )ÚContentsr‘   ©Úget©Ú.0ÚpageÚobjs      r,   ú
<listcomp>z%S3PathHandler._ls.<locals>.<listcomp>;  sK   € ð ð ð Ø#¸¿ºÀÈRÑ8PÔ8Pðð Ø14��E”
ðð ð ð r:   c                 óP   — g | ]#}|                      d g ¦  «        D ]
}|d         ‘ŒŒ$S )ÚCommonPrefixesr²   r¶   r¸   s      r,   r¼   z%S3PathHandler._ls.<locals>.<listcomp>>  sR   € ð ð ð àØŸ8š8Ð$4°bÑ9Ô9ðð ð ð �H”ðð ð ð r:   zError in ls path r¨   r   N)r`   rI   rV   Úget_paginatorÚpaginater    r!   r"   r#   r$   r%   )r&   rH   r\   r(   r)   r'   Ú	paginatorÚpagesÚobj_resultsÚdir_resultsr+   s              r,   Ú_lszS3PathHandler._ls&  s#  € ð 	×Ò˜6Ñ"Ô"Ð"àŸ/š/¨$Ñ/Ô/‰ˆ�Ø×!Ò! &Ñ)Ô)ˆð	à×,Ò,Ð->Ñ?Ô?ˆIØ×&Ò&ØØØð 'ñ ô ˆEð
ð Ø',ðñ ô ˆKðð à!ðñ ô ˆKð
  Ñ,Ð,øÝÔ"Ô.ð 	ð 	ð 	ÝØH DÐHÐHµ°a±´Ô1AÐHÐHÀQÐHÐHñô àðøøøøð	øøøs   ÁA	B ÂCÂ"+CÃCc           	      ó†  — |                       |¦  «         |                     d¦  «        s
J |¦   «         ‚|                      |¦  «        \  }}|                      |¦  «        }	 |                     ||¬¦  «         dS # t
          j        j        $ r0}t          d|› dt          |¦  «        j
        › d|› �¦  «        |‚d}~ww xY w)a  
        Recursive directory creation function. Like mkdir(), but makes all
        intermediate-level directories needed to contain the leaf directory.
        Similar to the native `os.makedirs`.
        Args:
            path (str): A URI supported by this PathHandler
        rB   r�   zError in mkdirs path r¨   r   N)r`   ra   rI   rV   Ú
put_objectr    r!   r"   r#   r$   r%   ©r&   rH   r\   r(   r)   r'   r+   s          r,   Ú_mkdirszS3PathHandler._mkdirsI  sâ   € ð 	×Ò˜6Ñ"Ô"Ð"à�}Š}˜SÑ!Ô!Ð'Ð' 4Ñ'Ô'Ð!àŸ/š/¨$Ñ/Ô/‰ˆ�Ø×!Ò! &Ñ)Ô)ˆð	Ø×Ò V°ÐÑ9Ô9Ð9Ð9Ð9øÝÔ"Ô.ð 	ð 	ð 	ÝØL¨ÐLÐLµT¸!±W´WÔ5EÐLÐLÈÐLÐLñô àðøøøøð	øøøs   Á#A< Á<C Â+B;Â;C c           	      óH  — |                       |¦  «         |                      |¦  «        \  }}|                      |¦  «        }	 |                     ||¬¦  «         dS # t          j        j        $ r0}t          d|› dt          |¦  «        j	        › d|› �¦  «        |‚d}~ww xY w)z�
        Remove the file (not directory) at the provided URI.
        Args:
            path (str): A URI supported by this PathHandler
        r�   zError in rm path r¨   r   N)
r`   rI   rV   Údelete_objectr    r!   r"   r#   r$   r%   rÈ   s          r,   Ú_rmzS3PathHandler._rm_  sÂ   € ð 	×Ò˜6Ñ"Ô"Ð"àŸ/š/¨$Ñ/Ô/‰ˆ�Ø×!Ò! &Ñ)Ô)ˆð	Ø× Ò ¨°GÐ Ñ<Ô<Ð<Ð<Ð<øÝÔ"Ô.ð 	ð 	ð 	ÝØH DÐHÐHµ°a±´Ô1AÐHÐHÀQÐHÐHñô àðøøøøð	øøøs   ÁA ÁB!Á1+BÂB!)Nr1   N)F)r†   r‡   NNNN)#r%   Ú
__module__Ú__qualname__Ú__doc__Ú_strict_kwargs_checkr<   rY   r
   r~   r   r9   r	   r>   r   rI   rV   r[   r   rw   Úboolr   r   r   Úbytesr…   Úintrœ   r¤   re   r|   rc   r¯   rÅ   rÉ   rÌ   r7   r:   r,   r/   r/   6   s   € € € € € ðð ð< !Ðà€IØ"Ðð
 $(Ø!'ð 26ð
ð 
à˜C”=ð
ð ˜#”ð
ð !)¨¤ð
ð 
ð 
ð 
ð4 ¨¨c¬ð  ð  ð  ð  ð˜cð  e¨C°¨H¤oð ð ð ð ð"( #ð (ð (ð (ð (ðV
àð
ð 
ð 
ð 
ð&I Cð I°3ð I¸3ð Ið Ið Ið Ið\ AFð#ð #Øð#Ø),ð#Ø9=ð#ØQTð#à	ð#ð #ð #ð #ðL 4à�b˜”g˜r %œyÐ(Ô)ð 4ð ð	 4ð
 ð 4ð ð 4ð ð 4ð  4ð  4ð  4ðJ Øð #'Ø $Ø!%Ø)-ðe;ð e;àðe;ð ðe;ð ð	e;ð ˜3”-ðe;ð ˜”ðe;ð ˜#”ðe;ð " #œðe;ð ðe;ð 
ˆr�#Œw˜˜5œ	Ð!Ô	"ðe;ð e;ð e;ð e;ðP ?Dð&ð &Øð&Ø'*ð&Ø7;ð&ØORð&à	ð&ð &ð &ð &ðT ð ¨°$¬ð ð ð ð ð
3˜Cð 
3¨3ð 
3°4ð 
3ð 
3ð 
3ð 
3ðG˜Cð G¨3ð G°4ð Gð Gð Gð GðC˜3ð C¨#ð C°$ð Cð Cð Cð Cð!˜ð ! sð !¨t°C¬yð !ð !ð !ð !ðF˜Cð ¨3ð °4ð ð ð ð ð,˜ð  sð ¨tð ð ð ð ð ð r:   r/   c            
       ó@  — e Zd ZdZedfdedededee         fd„Ze	defd	„¦   «         Z
defd
„Zdefd„Zdefd„Zdefd„Zddededefd„Zdefd„Zd dee         defd„Zdeeef         dee         fd„Zd!d„Zd"dedefd„Zd"dedefd„Zdedefd„Zdeddfd„ZdS )#r˜   i   Nr(   ÚkeyÚ
chunk_sizeÚtimeoutc                 ó$  — || _         || _        || _        |�|                     ¦   «         nd | _        || _        d| _        t          dd¦  «        | _        t          j
        ¦   «         | _        |                     ||¬¦  «        d         | _        d S )Nr   r�   r’   )r'   r(   rÕ   Útotal_secondsr×   rÖ   ÚoffsetÚrangeÚbuffered_windowr   r   r€   r™   rš   )r&   r'   r(   rÕ   rÖ   r×   s         r,   r9   zS3ChunkReadIO.__init__w  s„   € ð ˆŒØˆŒØˆŒà29Ð2E�w×,Ò,Ñ.Ô.Ð.È4ˆŒØ$ˆŒØˆŒÝ$ Q¨™{œ{ˆÔÝ”j‘l”lˆŒà×'Ò'¨v¸3Ð'Ñ?Ô?ÀÔPˆŒˆˆr:   r   c                 ó   — | j         S ©N)rH   r=   s    r,   ÚnamezS3ChunkReadIO.name�  s   € ð ŒyÐr:   c                 ó   — dS )zÈ
        Return a bool indicating whether object supports random access.

        If False, seek(), tell() and truncate() will raise OSError.
        This method may need to do a test seek().
        Tr7   r=   s    r,   ÚseekablezS3ChunkReadIO.seekable’  s	   € ð ˆtr:   c                 ó   — dS )z
        Return a bool indicating whether object was opened for reading.

        If False, read() will raise OSError.
        Tr7   r=   s    r,   ÚreadablezS3ChunkReadIO.readable›  s	   € ð ˆtr:   c                 ó   — dS )z�
        Return a bool indicating whether object was opened for writing.

        If False, write() and truncate() will raise OSError.
        Fr7   r=   s    r,   ÚwritablezS3ChunkReadIO.writable£  s	   € ð ˆur:   c                 ó   — t          ¦   «         ‚rÞ   )ÚAttributeErrorr=   s    r,   ÚfilenozS3ChunkReadIO.fileno«  s   € ÝÑÔÐr:   r   rÚ   Úwhencec                 ó´   — |dk    r|dk    sJ ‚|| _         n<|dk    r!|| j         z   dk    sJ ‚| xj         |z  c_         n|dk    r| j        |z   | _         | j         S )a3  
        Change stream position.

        Change the stream position to byte offset offset. Argument offset is
        interpreted relative to the position indicated by whence.  Values
        for whence are ints:

        * 0 -- start of stream (the default); offset should be zero or positive
        * 1 -- current stream position; offset may be negative
        * 2 -- end of stream; offset is usually negative
        Some operating systems / file systems could provide additional values.

        Return an int indicating the new absolute position.
        r   rC   é   )rÚ   rš   )r&   rÚ   ré   s      r,   r   zS3ChunkReadIO.seek®  su   € ð �QŠ;ˆ;Ø˜Q’;�;�;�;Ø ˆDŒKˆKØ�qŠ[ˆ[Ø˜DœKÑ'¨1Ò,Ð,Ð,Ð,ØˆKŒK˜6Ñ!ˆKŒKˆKØ�qŠ[ˆ[Øœ+¨Ñ.ˆDŒKØŒ{Ðr:   c                 ó   — | j         S )z5Return an int indicating the current stream position.)rÚ   r=   s    r,   ÚtellzS3ChunkReadIO.tellÇ  s
   € àŒ{Ðr:   Úsizec                 ó    — t          d¦  «        ‚)z–
        Truncate file to size bytes.

        Size defaults to the current IO position as reported by tell().  Return

        the new size.
        zcan't truncate readonly stream©r#   ©r&   rî   s     r,   ÚtruncatezS3ChunkReadIO.truncateË  s   € õ Ð6Ñ7Ô7Ð7r:   r“   c                 ó    — t          d¦  «        ‚)zK
        Write bytes b to in-memory buffer, return number written.
        zcan't write to readonly streamrð   )r&   r“   s     r,   ÚwritezS3ChunkReadIO.writeÙ  s   € õ Ð6Ñ7Ô7Ð7r:   c                 ó   — dS )z
        noop
        Nr7   r=   s    r,   r   zS3ChunkReadIO.closeß  s	   € ð 	ˆr:   r‡   c                 ó,   — |                       |¦  «        S rÞ   )Úreadrñ   s     r,   Úread1zS3ChunkReadIO.read1å  s   € Ø�yŠy˜‰ŒÐr:   c                 ót  — |�|dk     r| j         | j        z
  }t          || j         | j        z
  ¦  «        }t          ¦   «         }| j        | j        v r[| j        | j        j        z
  }|| j                             ¦   «         |t          ||z   t          | j        ¦  «        ¦  «        …         z  }t          |¦  «        |k    r,| xj        t          |¦  «        z  c_        t          |¦  «        S |t          |¦  «        z
  | j
        k    r•| xj        t          |¦  «        z  c_        |                      t          | j        t          | j        |z   t          |¦  «        z
  dz
  | j         ¦  «        ¦  «        ¦  «        }| xj        t          |¦  «        z  c_        ||z   S |                      | j        t          |¦  «        z   ¦  «         || j                             ¦   «         d|t          |¦  «        z
  …         z  }t          |¦  «        |k    sJ ‚| xj        t          |¦  «        z  c_        t          |¦  «        S )zå
        Read and return up to size bytes. If the argument is omitted, None, or negative,
        data is read and returned until EOF is reached. An empty bytes object is
        returned if the stream is already at EOF.
        Nr   rC   )rš   rÚ   ÚminÚ	bytearrayrÜ   Ústartr€   Ú	getbufferÚlenrÒ   rÖ   Ú_read_from_s3rÛ   Ú_read_chunk_to_buffer)r&   rî   ÚretÚbuffer_offsetÚoutputs        r,   r÷   zS3ChunkReadIO.readê  sú  € ð ˆ<˜4 !š8˜8Ø”; ¤Ñ,ˆDå�4˜œ t¤{Ñ2Ñ3Ô3ˆå‰kŒkˆàŒ;˜$Ô.Ð.Ð.Ø œK¨$Ô*>Ô*DÑDˆMØ�4”;×(Ò(Ñ*Ô*Ø¥ M°DÑ$8½#¸dÔ>RÑ:SÔ:SÑ TÔ TÐTôñ ˆCõ
 ˆs‰8Œ8�tÒÐØˆKŒK�3˜s™8œ8Ñ#ˆKŒKÝ˜‘:”:Ðð •#�c‘(”(‰?˜Tœ_Ò,Ð,ØˆKŒK�3˜s™8œ8Ñ#ˆKŒKà×'Ò'Ý�d”k¥3 t¤{°TÑ'9½CÀ¹H¼HÑ'DÀqÑ'HÈ$Ì+Ñ#VÔ#VÑWÔWñô ˆFð ˆKŒK�3˜v™;œ;Ñ&ˆKŒKà˜‘<Ðð 	×"Ò" 4¤;µ°S±´Ñ#9Ñ:Ô:Ð:ð 	ˆtŒ{×$Ò$Ñ&Ô& q¨4µ#°c±(´(©?Ð':Ô;Ñ;ˆå�3‰xŒx˜4ÒÐÐÐØˆŒ•s˜3‘x”xÑˆŒÝ�S‰zŒzÐr:   Údownload_rangec                 óP  — | j                              | j        | j        d|j        › d|j        › �¬¦  «        }|d         }| j        �|                     | j        ¦  «         t          ¦   «         }| 	                    | j
        ¬¦  «        D ]}||z  }Œ|                     ¦   «          |S )Nzbytes=ú-)r�   r‘   ÚRangeÚBody)rÖ   )r'   r™   r(   rÕ   rü   Ústopr×   Úset_socket_timeoutrû   Úiter_chunksrÖ   r   )r&   r  r»   Ústreaming_bodyr  Úchunks         r,   rÿ   zS3ChunkReadIO._read_from_s3  s·   € ØŒk×$Ò$Ø”;Ø”ØG˜>Ô/ÐGÐG°.Ô2EÐGÐGð %ñ 
ô 
ˆð
 ˜VœˆàŒ<Ð#Ø×-Ò-¨d¬lÑ;Ô;Ð;å‰kŒkˆØ#×/Ò/¸4¼?Ð/ÑKÔKð 	ð 	ˆEØ�5‰LˆCˆCØ×ÒÑÔÐàˆ
r:   Ústart_offsetc                 óü   — t          |t          || j        z   | j        ¦  «        ¦  «        }|                      |¦  «        }| j                             d¦  «         | j                             |¦  «         || _        dS )zº
        download a chuck size of data start from start_offset into current buffer, then update
        self.buffered_window for booking which part of data is currently buffered
        r   N)	rÛ   rú   rÖ   rš   rÿ   r€   r   rô   rÜ   )r&   r  r  r  s       r,   r   z#S3ChunkReadIO._read_chunk_to_buffer*  sz   € õ
 Ø�#˜l¨T¬_Ñ<¸d¼kÑJÔJñ
ô 
ˆð × Ò  Ñ0Ô0ˆàŒ×Ò˜ÑÔÐØŒ×Ò˜#ÑÔÐØ-ˆÔÐÐr:   )r   rÞ   ©r   N)r‡   )r%   rÍ   rÎ   ÚDEFAULT_CHUNK_SIZEr~   rÓ   r
   r   r9   Úpropertyrß   rÑ   rá   rã   rå   rè   r   rí   rò   r   rÒ   rû   rô   r   rø   r÷   rÛ   rÿ   r   r7   r:   r,   r˜   r˜   r  sO  € € € € € à)Ðð -Ø'+ðQð Qð ð	Qð
 ðQð ðQð ˜)Ô$ðQð Qð Qð Qð, ð�cð ð ð ñ „Xðð˜$ð ð ð ð ð˜$ð ð ð ð ð˜$ð ð ð ð ð˜ð ð ð ð ðð ˜3ð ¨ð °Cð ð ð ð ð2�cð ð ð ð ð8ð 8˜X cœ]ð 8°cð 8ð 8ð 8ð 8ð8�u˜U IÐ-Ô.ð 8°8¸C´=ð 8ð 8ð 8ð 8ðð ð ð ðð ˜#ð  uð ð ð ð ð
,ð ,˜ð , eð ,ð ,ð ,ð ,ð\¨Eð °eð ð ð ð ð$.°#ð .¸$ð .ð .ð .ð .ð .ð .r:   r˜   r  )r   rf   r   rM   rX   ro   r‚   r   Ú	functoolsr   Útypingr   r   r   r	   r
   r   r   Úiopath.common.file_ior   r   r   rP   r    ÚImportErrorr-   r/   ÚBufferedIOBaser˜   r7   r:   r,   ú<module>r     s�  ðð Ð Ð Ð Ø 	€	€	€	Ø €€€Ø 	€	€	€	Ø €€€Ø €€€Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø Ð Ð Ð Ð Ð Ø >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >à GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ Gð	ð €L€L€Lð €O€O€O€OøØð ð ð Ø€EØ€H€H€HðøøøðWð Wð Wð Wð0yð yð yð yð y�Kñ yô yð yðxE.ð E.ð E.ð E.ð E.�BÔ%ñ E.ô E.ð E.ð E.ð E.s   ÁA Á	AÁA