
    #HJj                    ~   d Z ddlmZ ddlZddlmZmZ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 er
ddlZddlmZ  ej*                  e      ZdZ	 d	Z	 d
diZ G d de      ZddZddZeddddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ y# e$ r dZY w xY w)zAImplements file-like objects for reading and writing to/from GCS.    )annotationsN)TYPE_CHECKINGAny	TypedDictT)	constants)TransportParams)gcsgsi   ignore_flushc                  ,    e Zd ZU ded<   ded<   ded<   y)_GCSUristrscheme	bucket_idblob_idN)__name__
__module____qualname____annotations__     X/Users/ahmed/devFolder/claude-voice/.venv/lib/python3.12/site-packages/smart_open/gcs.pyr   r   )   s    KNLr   r   c                    t         j                  j                  |       }|j                  t        v sJ |j
                  }|j                  j                  d      }|j                  ||dS )zHParse a ``gcs://`` or ``gs://`` URI into its bucket and blob components./)r   r   r   )
smart_openutilssafe_urlsplitr   SCHEMESnetlocpathlstrip)uri_as_stringsrr   r   s       r   	parse_urir$   /   sV    				'	'	6B99		IggnnS!GiiiGLLr   c                    t        |       }t        j                  j                  t        |      }t	        |d   |d   |fi |S )z9Open a GCS URI using the given mode and transport params.r   r   )r$   r   r   check_kwargsopen)urimodetransport_params
parsed_urikwargss        r   open_urir-   8   sB    3J**41ABF
;'I)>OOOr   c                    |i }|t         j                  ddfv rt        | ||||      }|S |t         j                  ddfv rt	        | |||||      }|S d| d}	t        |	      )	a  Open an GCS blob for reading or writing.

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

    Returns:
        A file-like object for the GCS blob.

    Raises:
        NotImplementedError: If `mode` is not one of the supported modes.
    rrt)bucketkeyclientget_blob_kwargsblob_open_kwargswwt)r1   blobmin_part_sizer3   blob_propertiesr5   zGCS support for mode z not implemented)r   READ_BINARYReaderWRITE_BINARYWriterNotImplementedError)
r   r   r)   r9   r3   r4   r:   r5   _blobmsgs
             r   r'   r'   ?   s    < 	%%sD11+-
, L 
)((#t4	4'+-
 L &dV+;<!#&&r   c                8   |i }|i }|(t         j                  j                  j                         }|j	                  |       } |j
                  |fi |}|1d| d|  }t         j                  j                  j                  |       |j                  di |S )zGReturn a file-like object for reading the GCS blob `key` from `bucket`.zblob z not found in )rb)	googlecloudstorageClientr1   get_blob
exceptionsNotFoundr'   )r1   r2   r3   r4   r5   bktr8   rA   s           r   r<   r<   z   s     ~%%,,.
--
C3<<//D|cU.1ll%%..s33499.-..r   c                ,   |i }|i }|(t         j                  j                  j                         }i t        |}|j                  |       j                  ||      }|j                         D ]  \  }}t        |||         |j                  di |S )zEReturn a file-like object for writing to GCS blob `blob` in `bucket`.)
chunk_size)wb)
rD   rE   rF   rG   _DEFAULT_WRITE_OPEN_KWARGSr1   r8   itemssetattrr'   )	r1   r8   r9   r3   r:   r5   g_blobkvs	            r   r>   r>      s     ~%%,,.I4I8HI]]6"''  ( F
  %%'11 ( 6;;0/00r   )r"   r   returnr   )r(   r   r)   r   r*   r   rU   	io.IOBase)r   r   r   r   r)   r   r9   intr3   "google.cloud.storage.Client | Noner4   dict[str, Any] | Noner:   rY   r5   rY   rU   rV   )NNN)r1   r   r2   r   r3   rX   r4   rY   r5   rY   rU   rV   )NNNN)r1   r   r8   r   r9   z
int | Noner3   rX   r:   rY   r5   rY   rU   rV   )!__doc__
__future__r   loggingtypingr   r   r   google.auth.transport.requestsrD   google.cloud.exceptionsgoogle.cloud.storageImportErrorMISSING_DEPSsmart_open.bytebufferr   smart_open.utilsr   iosmart_open._typingr   	getLoggerr   loggerr   _DEFAULT_MIN_PART_SIZErO   r   r$   r-   r'   r<   r>   r   r   r   <module>rj      s   H "  0 0)"    2			8	$
 g%  9,d3 i MP 015-1-1.2888 8 	8
 /8 +8 +8 ,8 8| 26-1.2//	/ // +	/
 ,/ /8 !%15-1.211
1 1 /	1
 +1 ,1 1C  Ls   B2 2B<;B<