
    (phkZ                        S r SSKrSSKrSSKJr  SSKrSSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  Sr Sr Sr SrSr\R/                  \S9rSr\R4                  " \S5      r SrSr\R                  R<                  r\R@                  RB                  r"S r#S r$S r%S'S jr&S r'S r(S r) " S S\*5      r+S r,S(S jr-S  r.S! r/S" r0S# r1S)S$ jr2S% r3   S*S& jr4g)+zVHelper functions for Cloud Storage utility classes.

These are *not* part of the API.
    N)md5)urlsplit)
urlunsplit)uuid4)environment_vars)_DEFAULT_TIMEOUT)DEFAULT_RETRY))DEFAULT_RETRY_IF_METAGENERATION_SPECIFIEDSTORAGE_EMULATOR_HOSTAPI_ENDPOINT_OVERRIDEAPI_VERSION_OVERRIDEzgoogleapis.comzstorage.{universe_domain})universe_domainzhttps://v1))if_etag_matchzIf-Match)if_etag_not_matchzIf-None-Match))if_generation_matchifGenerationMatch)if_generation_not_matchifGenerationNotMatch)if_metageneration_matchifMetagenerationMatch)if_metageneration_not_matchifMetagenerationNotMatch)if_source_generation_matchifSourceGenerationMatch)if_source_generation_not_matchifSourceGenerationNotMatch)if_source_metageneration_matchifSourceMetagenerationMatch)"if_source_metageneration_not_matchifSourceMetagenerationNotMatchc                  J    [         R                  R                  [        S 5      $ N)osenvirongetSTORAGE_EMULATOR_ENV_VAR     P/var/www/html/venv/lib/python3.13/site-packages/google/cloud/storage/_helpers.py_get_storage_emulator_overrider+   Q   s    ::>>2D99r)   c                  N    [         R                  " [        [        [        -   5      $ r#   )r$   getenv_API_ENDPOINT_OVERRIDE_ENV_VAR_DEFAULT_SCHEME_TRUE_DEFAULT_STORAGE_HOSTr(   r)   r*   _get_default_storage_base_urlr1   U   s    99&:T(T r)   c                  J    [        5       [        [        -   :w  a
  [        5       $ g)zIThis is an experimental configuration variable. Use api_endpoint instead.N)r1   r/   r0   r(   r)   r*   _get_api_endpoint_overrider3   [   s    $&/<V*VV,..r)   c                     [        U 5      nU SUR                   3n[        UR                  XB(       a  SOSSS45      nU$ )zReturns the scheme and netloc sections of the url, with the bucket
prepended to the netloc.

Not intended for use with netlocs which include a username and password.
./ )r   netlocr   scheme)urlbuckettrailing_slash
parsed_url
new_netlocbase_urls         r*   _virtual_hosted_style_base_urlr@   b   sM     #J81Z../0J			J~2r2NH Or)   c                  4    [         R                  " S5      S:H  $ )N!GOOGLE_API_USE_CLIENT_CERTIFICATEtrue)r$   r-   r(   r)   r*   _use_client_certrD   p   s    9989VCCr)   c                      [         R                  " [        R                  [         R                  " [        R                  5      5      $ r#   )r$   r-   r   PROJECTLEGACY_PROJECTr(   r)   r*   _get_environ_projectrH   t   s/    99  
		"112 r)   c                     U c  g[        U S   R                  5       U S   R                  5       /5      (       d  [        S5      eU $ )zPre-flight ``Bucket`` name validation.

:type name: str or :data:`NoneType`
:param name: Proposed bucket name.

:rtype: str or :data:`NoneType`
:returns: ``name`` if valid.
Nr   z8Bucket names must start and end with a number or letter.)allisalnum
ValueError)names    r*   _validate_namerO   {   sG     | Q!48#3#3#5677STTKr)   c                       \ rS rSrSrSS jr\S 5       r\S 5       r\S 5       r	S r
S	 r\S
 5       rSSSSSSSS\\S4S jrS rS rSSSSS\\S4S jrSSSSS\\S4S jrSrg)_PropertyMixin   a  Abstract mixin for cloud storage classes with associated properties.

Non-abstract subclasses should implement:
  - path
  - client
  - user_project

:type name: str
:param name: The name of the object. Bucket names must start and end with a
             number or letter.
Nc                 <    Xl         0 U l        [        5       U l        g r#   )rN   _propertiesset_changes)selfrN   s     r*   __init___PropertyMixin.__init__   s    	r)   c                     [         e)z$Abstract getter for the object path.NotImplementedErrorrW   s    r*   path_PropertyMixin.path   
     "!r)   c                     [         e)z&Abstract getter for the object client.r[   r]   s    r*   client_PropertyMixin.client   r`   r)   c                     [         e)z,Abstract getter for the object user_project.r[   r]   s    r*   user_project_PropertyMixin.user_project   r`   r)   c                 $    Uc  U R                   nU$ )ak  Check client or verify over-ride.

:type client: :class:`~google.cloud.storage.client.Client` or
              ``NoneType``
:param client: the client to use.  If not passed, falls back to the
               ``client`` stored on the current object.

:rtype: :class:`google.cloud.storage.client.Client`
:returns: The client passed in or the currently bound client.
)rb   )rW   rb   s     r*   _require_client_PropertyMixin._require_client   s     >[[Fr)   c                     0 $ )a  Return any encryption headers needed to fetch the object.

.. note::
   Defined here because :meth:`reload` calls it, but this method is
   really only relevant for :class:`~google.cloud.storage.blob.Blob`.

:rtype: dict
:returns: a mapping of encryption-related headers.
r(   r]   s    r*   _encryption_headers"_PropertyMixin._encryption_headers   s	     	r)   c                 B    0 nU R                   b  U R                   US'   U$ )zDefault query parameters.userProject)re   )rW   paramss     r*   _query_params_PropertyMixin._query_params   s*     ($($5$5F=!r)   noAclc           	         U R                  U5      nU R                  nX,S'   [        UUUUUS9  Ub  XS'   U R                  US'   U R	                  5       n[        XUS9  UR                  U R                  UUU	U
U S9nU R                  U5        g)a  Reload properties from Cloud Storage.

If :attr:`user_project` is set, bills the API request to that project.

:type client: :class:`~google.cloud.storage.client.Client` or
              ``NoneType``
:param client: the client to use. If not passed, falls back to the
               ``client`` stored on the current object.

:type projection: str
:param projection: (Optional) If used, must be 'full' or 'noAcl'.
                   Defaults to ``'noAcl'``. Specifies the set of
                   properties to return.

:type if_etag_match: Union[str, Set[str]]
:param if_etag_match: (Optional) See :ref:`using-if-etag-match`

:type if_etag_not_match: Union[str, Set[str]])
:param if_etag_not_match: (Optional) See :ref:`using-if-etag-not-match`

:type if_generation_match: long
:param if_generation_match:
    (Optional) See :ref:`using-if-generation-match`

:type if_generation_not_match: long
:param if_generation_not_match:
    (Optional) See :ref:`using-if-generation-not-match`

:type if_metageneration_match: long
:param if_metageneration_match:
    (Optional) See :ref:`using-if-metageneration-match`

:type if_metageneration_not_match: long
:param if_metageneration_not_match:
    (Optional) See :ref:`using-if-metageneration-not-match`

:type timeout: float or tuple
:param timeout:
    (Optional) The amount of time, in seconds, to wait
    for the server response.  See: :ref:`configuring_timeouts`

:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
:param retry:
    (Optional) How to retry the RPC. See: :ref:`configuring_retries`

:type soft_deleted: bool
:param soft_deleted:
    (Optional) If True, looks for a soft-deleted object. Will only return
    the object metadata if the object exists and is in a soft-deleted state.
    :attr:`generation` is required to be set on the blob if ``soft_deleted`` is set to True.
    See: https://cloud.google.com/storage/docs/soft-delete

projectionr   r   r   r   NsoftDeleted
generation)r   r   )query_paramsheaderstimeoutretry_target_object)	rh   rp    _add_generation_match_parametersrw   rk   _add_etag_match_headers_get_resourcer^   _set_properties)rW   rb   rt   r   r   r   r   r   r   rz   r{   soft_deletedrx   ry   api_responses                  r*   reload_PropertyMixin.reload   s    D %%f-)) &0\"( 3$;$;(C	
 #*6' *.L&**,DU	
 ++II% , 
 	\*r)   c                 V    U R                   R                  U5        X R                  U'   g)am  Update field of this object's properties.

This method will only update the field provided and will not
touch the other fields.

It **will not** reload the properties from the server. The behavior is
local only and syncing occurs via :meth:`patch`.

:type name: str
:param name: The field name to update.

:type value: object
:param value: The value being updated.
N)rV   addrT   )rW   rN   values      r*   _patch_property_PropertyMixin._patch_property2  s$     	$!&r)   c                 .    Xl         [        5       U l        g)zSet the properties for the current object.

:type value: dict or :class:`google.cloud.storage.batch._FutureDict`
:param value: The properties to be set.
N)rT   rU   rV   )rW   r   s     r*   r   _PropertyMixin._set_propertiesD  s     !r)   Fc	           	      2   U R                  U5      nU R                  n	SU	S'   U(       a  XS'   [        U	UUUUS9  U R                   V
s0 s H  oU R                  U
   _M     nn
UR                  U R                  UU	U UUS9nU R                  U5        gs  sn
f )aj  Sends all changed properties in a PATCH request.

Updates the ``_properties`` with the response from the backend.

If :attr:`user_project` is set, bills the API request to that project.

:type client: :class:`~google.cloud.storage.client.Client` or
              ``NoneType``
:param client: the client to use. If not passed, falls back to the
               ``client`` stored on the current object.

:type if_generation_match: long
:param if_generation_match:
    (Optional) See :ref:`using-if-generation-match`

:type if_generation_not_match: long
:param if_generation_not_match:
    (Optional) See :ref:`using-if-generation-not-match`

:type if_metageneration_match: long
:param if_metageneration_match:
    (Optional) See :ref:`using-if-metageneration-match`

:type if_metageneration_not_match: long
:param if_metageneration_not_match:
    (Optional) See :ref:`using-if-metageneration-not-match`

:type timeout: float or tuple
:param timeout:
    (Optional) The amount of time, in seconds, to wait
    for the server response.  See: :ref:`configuring_timeouts`

:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
:param retry:
    (Optional) How to retry the RPC. See: :ref:`configuring_retries`

:type override_unlocked_retention: bool
:param override_unlocked_retention:
    (Optional) override_unlocked_retention must be set to True if the operation includes
    a retention property that changes the mode from Unlocked to Locked, reduces the
    retainUntilTime, or removes the retention configuration from the object. See:
    https://cloud.google.com/storage/docs/json_api/v1/objects/patch
fullrt   overrideUnlockedRetentionru   )rx   r|   rz   r{   N)rh   rp   r}   rV   rT   _patch_resourcer^   r   )rW   rb   r   r   r   r   rz   r{   override_unlocked_retentionrx   keyupdate_propertiesr   s                r*   patch_PropertyMixin.patchN  s    l %%f-)) &,\"&8S45( 3$;$;(C	
 DH==Q=C$"2"23"77=Q --II% . 
 	\* Rs   	Bc	           	          U R                  U5      nU R                  n	SU	S'   U(       a  XS'   [        U	UUUUS9  UR                  U R                  U R
                  U	UUU S9n
U R                  U
5        g)a`  Sends all properties in a PUT request.

Updates the ``_properties`` with the response from the backend.

If :attr:`user_project` is set, bills the API request to that project.

:type client: :class:`~google.cloud.storage.client.Client` or
              ``NoneType``
:param client: the client to use. If not passed, falls back to the
               ``client`` stored on the current object.

:type if_generation_match: long
:param if_generation_match:
    (Optional) See :ref:`using-if-generation-match`

:type if_generation_not_match: long
:param if_generation_not_match:
    (Optional) See :ref:`using-if-generation-not-match`

:type if_metageneration_match: long
:param if_metageneration_match:
    (Optional) See :ref:`using-if-metageneration-match`

:type if_metageneration_not_match: long
:param if_metageneration_not_match:
    (Optional) See :ref:`using-if-metageneration-not-match`

:type timeout: float or tuple
:param timeout:
    (Optional) The amount of time, in seconds, to wait
    for the server response.  See: :ref:`configuring_timeouts`

:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
:param retry:
    (Optional) How to retry the RPC. See: :ref:`configuring_retries`

:type override_unlocked_retention: bool
:param override_unlocked_retention:
    (Optional) override_unlocked_retention must be set to True if the operation includes
    a retention property that changes the mode from Unlocked to Locked, reduces the
    retainUntilTime, or removes the retention configuration from the object. See:
    https://cloud.google.com/storage/docs/json_api/v1/objects/patch
r   rt   r   ru   )rx   rz   r{   r|   N)rh   rp   r}   _put_resourcer^   rT   r   )rW   rb   r   r   r   r   rz   r{   r   rx   r   s              r*   update_PropertyMixin.update  s    l %%f-))%+\"&8S45( 3$;$;(C	
 ++II% , 
 	\*r)   )rV   rT   rN   r#   )__name__
__module____qualname____firstlineno____doc__rX   propertyr^   rb   re   rh   rk   rp   r   r	   r   r   r   r   r
   r   __static_attributes__r(   r)   r*   rQ   rQ      s    

 " " " " " "
     $ $$( _+B'$   $ $$( $)O+f   $ $$( 7$)L+r)   rQ   c                 2   ^  U 4S jnU 4S jn[        X5      $ )zHCreate a property descriptor around the :class:`_PropertyMixin` helpers.c                 :   > U R                   R                  T5      $ )zScalar property getter.)rT   r&   )rW   	fieldnames    r*   _getter!_scalar_property.<locals>._getter  s    ##I..r)   c                 *   > U R                  TU5        g)zScalar property setter.N)r   )rW   r   r   s     r*   _setter!_scalar_property.<locals>._setter  s    Y.r)   )r   )r   r   r   s   `  r*   _scalar_propertyr     s    // G%%r)   c                     U R                  U5      n[        U5      S:  a4  UR                  U5        U R                  U5      n[        U5      S:  a  M3  gg)a  Read blocks from a buffer and update a hash with them.

:type buffer_object: bytes buffer
:param buffer_object: Buffer containing bytes used to update a hash object.

:type hash_obj: object that implements update
:param hash_obj: A hash object (MD5 or CRC32-C).

:type digest_block_size: int
:param digest_block_size: The block size to write to the hash.
                          Defaults to 8192.
r   N)readlenr   )buffer_objecthash_objdigest_block_sizeblocks       r*   _write_buffer_to_hashr     sJ     01E
e*q.""#45 e*q.r)   c                 x    [        5       n[        X5        UR                  5       n[        R                  " U5      $ )zGet MD5 hash of bytes (as base64).

:type buffer_object: bytes buffer
:param buffer_object: Buffer containing bytes used to compute an MD5
                      hash (as base64).

:rtype: str
:returns: A base64 encoded digest of the MD5 hash.
)r   r   digestbase64	b64encode)r   r   digest_bytess      r*   _base64_md5hashr     s0     uH-2??$LL))r)   c                     [          HF  u  p#UR                  U5      nUc  M  [        U[        5      (       a  U/nSR	                  U5      X'   MH     g)zAdd generation match parameters into the given parameters list.

:type headers: dict
:param headers: Headers dict.

:type match_parameters: dict
:param match_parameters: if*etag*match parameters to add.
N, )_ETAG_MATCH_PARAMETERSr&   
isinstancestrjoin)ry   match_parameterssnakecase_nameheader_namer   s        r*   r~   r~   !  sL     (># $$^4%%%#'99U#3G  (>r)   c                     [          Hh  u  p#UR                  U5      nUc  M  [        U [        5      (       a  U R	                  X445        MD  [        U [
        5      (       a  X@U'   M_  [        S5      e   g)aF  Add generation match parameters into the given parameters list.

:type parameters: list or dict
:param parameters: Parameters list or dict.

:type match_parameters: dict
:param match_parameters: if*generation*match parameters to add.

:raises: :exc:`ValueError` if ``parameters`` is not a ``list()``
         or a ``dict()``.
Nz5`parameters` argument should be a dict() or a list().)_GENERATION_MATCH_PARAMETERSr&   r   listappenddictrM   )
parametersr   r   camelcase_namer   s        r*   r}   r}   3  sn     +G& $$^4*d++!!>"9:J---2>* !K  +Gr)   c                      [        S U R                  5        5       5      S:  aP  U R                  5        Vs/ s H	  nSU S3PM     nnSR                  USS 5      nUS   nSU SU 3n[	        U5      egs  snf )	zRaise ``ValueError`` exception if more than one parameter was set.

:type error: :exc:`ValueError`
:param error: Description of which fields were set

:raises: :class:`~ValueError` containing the fields that were set
c              3   (   #    U  H  oS Lv   M
     g 7fr#   r(   ).0args     r*   	<genexpr>._raise_if_more_than_one_set.<locals>.<genexpr>W  s     
6osd?os      'r   NrJ   zPass at most one of z and )sumvalueskeysr   rM   )kwargsrN   escaped_keyskeys_but_lastlast_keymsgs         r*   _raise_if_more_than_one_setr   O  s     
6fmmo
66:06>!D6>		,s"34#$]O5
Co ;>s   A6c                 n    [        U 5      nUR                  (       a  UR                  (       a  U $ U SU  3$ )a  Helper to build bucket bound hostname URL.

:type host: str
:param host: Host name.

:type scheme: str
:param scheme: (Optional) Web scheme. If passed, use it
               as a scheme in the result URL.

:rtype: str
:returns: A bucket bound hostname URL.
z://)r   r9   r8   )hostr9   	url_partss      r*   _bucket_bound_hostname_urlr   b  s4     II,,XSr)   c                  .    S[        [        5       5      -   $ )Nzgccl-invocation-id/)r   r   r(   r)   r*   _get_invocation_idr   v  s     3uw<//r)   c                 b    U  S[        5        3nU(       a  USU 3-  nSSU UUU=(       d    US.$ )a  Get the headers for a request.

:type user_agent: str
:param user_agent: The user-agent for requests.

:type command: str
:param command:
    (Optional) Information about which interface for the operation was
    used, to be included in the X-Goog-API-Client header. Please leave
    as None unless otherwise directed.

:rtype: dict
:returns: The headers to be used for the request.
 z gccl-gcs-cmd/zapplication/jsonzgzip, deflate)AcceptzAccept-Encodingz
User-AgentzX-Goog-API-Clientzcontent-typezx-upload-content-type)r   )
user_agentcontent_typex_upload_content_typecommandx_goog_api_clients        r*   _get_default_headersr   z  sR    ( &,a(:(<'=>~gY77 %* .$!6!F, r)   )F)i    r#   )zapplication/json; charset=UTF-8NN)5r   r   datetimehashlibr   r$   urllib.parser   r   uuidr   google.authr   google.cloud.storage.constantsr   google.cloud.storage.retryr	   r
   r'   r.   _API_VERSION_OVERRIDE_ENV_VAR_DEFAULT_UNIVERSE_DOMAIN_STORAGE_HOST_TEMPLATEformatr0   r/   r-   _API_VERSIONr   r   now_NOWtimezoneutc_UTCr+   r1   r3   r@   rD   rH   rO   objectrQ   r   r   r   r~   r}   r   r   r   r   r(   r)   r*   <module>r      s)  
    	 ! #  ( ; 4 P 3  >!8  O 6  O+ 4 3::, ;   yy6= - 	   :D$^+V ^+B&6** 4$8& (0 3	 r)   