o
    
i                     @   s   d Z ddlZddlZzddlZddlZddlZW n ey#   dZY nw ddl	Z
ddlZ
ddl
mZ eeZdZ	 dZ	 ddiZdd	 Zd
d Zdd ZdeddddfddZ					dddZ				dddZdS )zAImplements file-like objects for reading and writing to/from GCS.    NT)	constantsgsi   ignore_flushc                 C   s:   t j| }|jtksJ |j}|jd}tt||dS )N/)scheme	bucket_idblob_id)	
smart_openutilssafe_urlsplitr   SCHEMEnetlocpathlstripdict)uri_as_stringsrr   r    r   B/home/ubuntu/.local/lib/python3.10/site-packages/smart_open/gcs.py	parse_uri$   s
   r   c                 C   s2   t | }tjt|}t|d |d |fi |S )Nr   r   )r   r	   r
   check_kwargsopen)urimodetransport_params
parsed_urikwargsr   r   r   open_uri,   s   r   c                 C   s   d|  d}t |t d S )Nz
Parameter z7 is deprecated, this parameter no-longer has any effect)warningswarnUserWarning)parameter_namemessager   r   r   warn_deprecated2   s   r#   c	           
      C   sz   |du ri }|durt d |tjddfv r!t| ||||d}	|	S |tjddfv r5t| |||||d}	|	S td	| d
)a  Open an GCS blob for reading or writing.

    Parameters
    ----------
    bucket_id: str
        The name of the bucket this object resides in.
    blob_id: str
        The name of the blob within the bucket.
    mode: str
        The mode for opening the object. Must be either "rb" or "wb".
    buffer_size:
        deprecated
    min_part_size: int, optional
        The minimum part size for multipart uploads. For writing only.
    client: google.cloud.storage.Client, optional
        The GCS client to use when working with google-cloud-storage.
    get_blob_kwargs: dict, optional
        Additional keyword arguments to propagate to the bucket.get_blob
        method of the google-cloud-storage library. For reading only.
    blob_properties: dict, optional
        Set properties on blob before writing. For writing only.
    blob_open_kwargs: dict, optional
        Additional keyword arguments to propagate to the blob.open method
        of the google-cloud-storage library.

    Nbuffer_sizerrt)bucketkeyclientget_blob_kwargsblob_open_kwargswwt)r'   blobmin_part_sizer)   blob_propertiesr+   zGCS support for mode z not implemented)r#   r   READ_BINARYReaderWRITE_BINARYWriterNotImplementedError)
r   r   r   r$   r/   r)   r*   r0   r+   _blobr   r   r   r   7   s,   %
r   c           	      C   s   |d u ri }|d u ri }|d u rt jj }|d urtd |d ur&td || }|j|fi |}|d u rEt jjd| d|  |j	di |S )Nr$   line_terminatorzblob z not found in rb)r8   )
googlecloudstorageClientr#   r'   get_blob
exceptionsNotFoundr   )	r'   r(   r$   r7   r)   r*   r+   bktr.   r   r   r   r2   w   s   
r2   c           
      C   s   |d u ri }|d u ri }|d u rt jj }i t|}|| j||d}| D ]
\}}t||| q*|j	di |}	dd |	_
|	S )N)
chunk_sizewbc                   S   s   d S )Nr   r   r   r   r   <lambda>   s    zWriter.<locals>.<lambda>)rB   )r9   r:   r;   r<   _DEFAULT_WRITE_OPEN_KWARGSr'   r.   itemssetattrr   	terminate)
r'   r.   r/   r)   r0   r+   g_blobkvr6   r   r   r   r4      s    

r4   )NNNNN)NNNN)__doc__loggingr   google.cloud.exceptionsr9   google.cloud.storagegoogle.auth.transport.requestsImportErrorMISSING_DEPSsmart_open.bytebufferr	   smart_open.utilsr   	getLogger__name__loggerr   _DEFAULT_MIN_PART_SIZErD   r   r   r#   r   r2   r4   r   r   r   r   <module>   sP   
	
B
