
    Ng{                        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         L/var/www/html/ai-engine/env/lib/python3.11/site-packages/iopath/common/s3.pys3_close_and_uploadr-      s    IIaLLL DJ $$$ ;z$--//0099::W"	 	 	
 	
 	
 	
 	
 * W W WNNtAww7GNN1NNOOUV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6s;;xxqrr
##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,,tX&& $	#-T\BBB%nnT22&9   N  
 n  , /F /Aww'/ /+,/ /  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     !OOD11	w||$.))4+A9
 
 	
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' ( 8I!{88((44    jll  !9,Q0G0G0GGG=DDT:VV    *+1	 1	 1	 1	 1	 1	 1	 1	. KK(//55666v%C w~~c"" 	#"ood33OFG%%f--F!//GS1E 0   C,,,IcNNNN    DIcNNNN    D KK-44T: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0FLLELLXVVWWW5//(33!!&))	z674CWXXX4". 	 	 	&x00FLL4;;CFFCCDDD55555	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77+3 3/03 3   A 'vvwPP ++6w+GGXDK H$"' "&% #(	 	 	 	 D[[d{{ ..1E   M 94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0FLLELLXVVWWW5"&//(";";
K"&//(";";
KZ''')U'''!!*--	KK(&  +     4". 	 	 	&x00FLL299#a&&AABBB55555	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EHO". 	 	 	z'"9->>UUUd1gg>NUURSUU  44444	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*Fv*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!!Bldl4&B&B6&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       #R8P8P 14E
   r:   c                 P    g | ]#}|                     d g           D ]
}|d         $S )CommonPrefixesr   r   r   s      r,   r   z%S3PathHandler._ls.<locals>.<listcomp>>  sR       88$4b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
 ,,". 	 	 	HDHHa1AHHQ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LT!WW5E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 <<<<<". 	 	 	HDHHa1AHHQ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 eCHo    "(# ( ( ( (V

 
 
 
&IC I3 I3 I I I I\ AF# ##),#9=#QT#	# # # #L 4bgr%y() 4 	 4
  4  4  4  4  4  4J  #' $!%)-e; e;e; e; 	e; 3-e; e; #e; "#e; e; 
r#w5	!	"e; e; e; e;P ?D& &&'*&7;&OR&	& & & &T $    
3C 
33 
34 
3 
3 
3 
3GC G3 G4 G G G GC3 C# C$ C C C C! !s !tCy ! ! ! !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     292Ew,,...4$$Q{{jll''v3'??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;;;; DKKq[[DK'1,,,,KK6!KKKq[[+.DK{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    yy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!88;,D4t{233kk;$... K$*>*DDM4;((**MD$8#d>R:S:S T TT C
 s88tKK3s88#KK:: #c((?T_,,KK3s88#KK''dk3t{T'9CHH'Dq'H$+#V#VWW F KK3v;;&KK< 	""4;S#9::: 	t{$$&&q4#c((?':;;3xx4s3xxSzz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<#--dl;;;kk#//4?/KK 	 	E5LCC
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    
 #lT_<dk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 8Xc] 8c 8 8 8 88uUI-. 88C= 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	 LLL OOOO   EHHH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