
    Bf_                        d Z ddlZddlZddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ dZ	 dZ	 dZ	 dZdZe                    e          ZdZ ej        ed          Z	 dZdZdZ ej        j!        Z"ej#        j$        Z%d Z&d Z'd Z(d-dZ)d Z*d Z+d Z, G d d e-          Z.d! Z/d.d#Z0d$ Z1d% Z2d& Z3d' Z4d/d(Z5d/d)Z6d* Z7	 	 	 d0d,Z8dS )1zVHelper functions for Cloud Storage utility classes.

These are *not* part of the API.
    N)md5)urlsplit)
urlunsplit)uuid4)resumable_media)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ifSourceMetagenerationNotMatchz`num_retries` has been deprecated and will be removed in a future release. Use the `retry` argument with a Retry or ConditionalRetryPolicy object, or None, instead.c                  L    t           j                            t          d           S N)osenvirongetSTORAGE_EMULATOR_ENV_VAR     l/home/panchajanya/Development/work/volatility3/lib/python3.11/site-packages/google/cloud/storage/_helpers.py_get_storage_emulator_overrider,   X   s    :>>2D999r*   c                  P    t          j        t          t          t          z             S r$   )r%   getenv_API_ENDPOINT_OVERRIDE_ENV_VAR_DEFAULT_SCHEME_TRUE_DEFAULT_STORAGE_HOSTr)   r*   r+   _get_default_storage_base_urlr2   \   s!    9&:T(T  r*   c                  `    t                      t          t          z   k    rt                      S dS )zIThis is an experimental configuration variable. Use api_endpoint instead.N)r2   r0   r1   r)   r*   r+   _get_api_endpoint_overrider4   b   s*    $&&/<V*VVV,...4r*   Fc                 v    t          |           }| d|j         }t          |j        ||rdndddf          }|S )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_urlrA   i   sU     #J00Z.00J		J~(E2r2N H Or*   c                  2    t          j        d          dk    S )N!GOOGLE_API_USE_CLIENT_CERTIFICATEtrue)r%   r.   r)   r*   r+   _use_client_certrE   w   s    9899VCCr*   c                  x    t          j        t          j        t          j        t          j                            S r$   )r%   r.   r   PROJECTLEGACY_PROJECTr)   r*   r+   _get_environ_projectrI   {   s-    9 
	"122  r*   c                     | dS t          | d                                         | d                                         g          st          d          | S )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_namerP      sX     | Q!!48#3#3#5#5677 USTTTKr*   c                       e Zd ZdZddZed             Zed             Zed             Zd Z	d Z
ed	             Zdd
ddddddeedfdZd Zd ZdddddeedfdZdddddeedfdZdS )_PropertyMixina1  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                 H    || _         i | _        t                      | _        d S r$   )rO   _propertiesset_changes)selfrO   s     r+   __init__z_PropertyMixin.__init__   s     	r*   c                     t           )z$Abstract getter for the object path.NotImplementedErrorrW   s    r+   pathz_PropertyMixin.path   
     "!r*   c                     t           )z&Abstract getter for the object client.rZ   r\   s    r+   clientz_PropertyMixin.client   r^   r*   c                     t           )z,Abstract getter for the object user_project.rZ   r\   s    r+   user_projectz_PropertyMixin.user_project   r^   r*   c                     || j         }|S )a  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.
        )r`   )rW   r`   s     r+   _require_clientz_PropertyMixin._require_client   s     >[Fr*   c                     i S )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_headersz"_PropertyMixin._encryption_headers   s	     	r*   c                 ,    i }| j         
| j         |d<   |S )zDefault query parameters.NuserProject)rb   )rW   paramss     r+   _query_paramsz_PropertyMixin._query_params   s$     ($($5F=!r*   noAclc                 4   |                      |          }| j        }||d<   t          |||||           |||d<   |                                 }t	          |||           |                    | j        |||	|
|           }|                     |           dS )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)r   r   )query_paramsheaderstimeoutretry_target_object)rd   rj    _add_generation_match_parametersrf   _add_etag_match_headers_get_resourcer]   _set_properties)rW   r`   rm   r   r   r   r   r   r   rr   rs   soft_deletedrp   rq   api_responses                  r+   reloadz_PropertyMixin.reload   s    D %%f--) &0\"( 3$;$;(C	
 	
 	
 	
 #*6L'**,,=DU	
 	
 	
 	
 ++I% , 
 
 	\*****r*   c                 N    | j                             |           || j        |<   dS )a  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   rO   values      r+   _patch_propertyz_PropertyMixin._patch_property6  s-     	$!&r*   c                 :    || _         t                      | _        dS )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+   rx   z_PropertyMixin._set_propertiesH  s     !r*   Fc	                                           |          } j        }	d|	d<   |r||	d<   t          |	||||            fd j        D             }
|                     j        |
|	 ||          }                     |           dS )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
        fullrm   overrideUnlockedRetentionrn   c                 ,    i | ]}|j         |         S r)   )rT   ).0keyrW   s     r+   
<dictcomp>z(_PropertyMixin.patch.<locals>.<dictcomp>  s#    QQQCS$"23"7QQQr*   )rp   rt   rr   rs   N)rd   rj   ru   rV   _patch_resourcer]   rx   )rW   r`   r   r   r   r   rr   rs   override_unlocked_retentionrp   update_propertiesrz   s   `           r+   patchz_PropertyMixin.patchR  s    l %%f--) &,\"& 	T8SL45( 3$;$;(C	
 	
 	
 	
 RQQQ4=QQQ --I% . 
 
 	\*****r*   c	                     |                      |          }| j        }	d|	d<   |r||	d<   t          |	||||           |                    | j        | j        |	|||           }
|                     |
           dS )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   rm   r   rn   )rp   rr   rs   rt   N)rd   rj   ru   _put_resourcer]   rT   rx   )rW   r`   r   r   r   r   rr   rs   r   rp   rz   s              r+   updatez_PropertyMixin.update  s    l %%f--)%+\"& 	T8SL45( 3$;$;(C	
 	
 	
 	
 ++I% , 
 
 	\*****r*   r$   )__name__
__module____qualname____doc__rX   propertyr]   r`   rb   rd   rf   rj   r	   r
   r{   r   rx   r   r   r   r)   r*   r+   rR   rR      s}       
 
   
 " " X" " " X" " " X"  
 
 
   X   $ $$( \+ \+ \+ \+|' ' '$     $ $$( 7$)O+ O+ O+ O+f   $ $$( 7$)L+ L+ L+ L+ L+ L+r*   rR   c                 8      fd} fd}t          ||          S )zHCreate a property descriptor around the :class:`_PropertyMixin` helpers.c                 8    | j                                       S )zScalar property getter.)rT   r'   )rW   	fieldnames    r+   _getterz!_scalar_property.<locals>._getter  s    ##I...r*   c                 4    |                      |           dS )zScalar property setter.N)r   )rW   r~   r   s     r+   _setterz!_scalar_property.<locals>._setter  s    Y.....r*   )r   )r   r   r   s   `  r+   _scalar_propertyr     sG    / / / / // / / / / GW%%%r*       c                     |                      |          }t          |          dk    r?|                    |           |                      |          }t          |          dk    =dS dS )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      sf     011E
e**q..""#455 e**q......r*   c                     t                      }t          | |           |                                }t          j        |          S )a  Get 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     s=     uuH-222??$$LL)))r*   c                     t           D ]L\  }}|                    |          }|0t          |t                    r|g}d                    |          | |<   MdS )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)rq   match_parameterssnakecase_nameheader_namer~   s        r+   rv   rv   %  sk     (> 4 4# $$^44%%%  #'99U#3#3GK 4 4r*   c                     t           D ]s\  }}|                    |          }|Wt          | t                    r|                     ||f           It          | t
                    r|| |<   dt          d          tdS )ab  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dictrN   )
parametersr   r   camelcase_namer~   s        r+   ru   ru   7  s     +G  & $$^44*d++ 	!!>5"9::::J-- -2
>** !K    r*   c                     t          d |                                 D                       dk    rZd |                                 D             }d                    |dd                   }|d         }d| d| }t	          |          dS )	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      K   | ]}|d uV  	d S r$   r)   )r   args     r+   	<genexpr>z._raise_if_more_than_one_set.<locals>.<genexpr>[  s&      
6
6s3d?
6
6
6
6
6
6r*      c                     g | ]}d | d 	S )'r)   )r   rO   s     r+   
<listcomp>z/_raise_if_more_than_one_set.<locals>.<listcomp>\  s     >>>D>>>r*   r   NrK   zPass at most one of z and )sumvalueskeysr   rN   )kwargsescaped_keyskeys_but_lastlast_keymsgs        r+   _raise_if_more_than_one_setr   S  s     
6
6fmmoo
6
6
666::>>>>>		,ss"344#C]CCCCoo ;:r*   c                 N    t          |           }|j        r	|j        r| S | d|  S )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   r:   r9   )hostr:   	url_partss      r+   _bucket_bound_hostname_urlr   f  s=     I I, r*   c                     | |t          d          | ,t          j        | j        | j        | j        | j                  S |t          j        |          S t          j        d          S )a~  Convert google.api.core.Retry to google.resumable_media.RetryStrategy.

    Custom predicates are not translated.

    :type retry: google.api_core.Retry
    :param retry: (Optional) The google.api_core.Retry object to translate.

    :type num_retries: int
    :param num_retries: (Optional) The number of retries desired. This is
        supported for backwards compatibility and is mutually exclusive with
        `retry`.

    :rtype: google.resumable_media.RetryStrategy
    :returns: A RetryStrategy with all applicable attributes copied from input,
              or a RetryStrategy with max_retries set to 0 if None was input.
    Nz6num_retries and retry arguments are mutually exclusive)	max_sleepmax_cumulative_retryinitial_delay
multiplier)max_retriesr   )rN   r   RetryStrategy_maximum	_deadline_initial_multiplier)rs   num_retriess     r+   (_api_core_retry_to_resumable_media_retryr   z  s    $ [4QRRR		,n!&.(	
 
 
 	
 
	 ,EEEE,;;;;r*   c                  >    dt          t                                z   S )Nzgccl-invocation-id/)r   r   r)   r*   r+   _get_invocation_idr     s     3uww<<//r*   application/json; charset=UTF-8c                 R    |  dt                       }|r|d| z  }dd| |||p|d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     sc    ( &>>(:(<(<>> 87g777 %* .$!6!F,  r*   )F)r   r$   )r   NN)9r   r   datetimehashlibr   r%   urllib.parser   r   uuidr   googler   google.authr   google.cloud.storage.constantsr	   google.cloud.storage.retryr
   r   r(   r/   _API_VERSION_OVERRIDE_ENV_VAR_DEFAULT_UNIVERSE_DOMAIN_STORAGE_HOST_TEMPLATEformatr1   r0   r.   _API_VERSIONr   r   _NUM_RETRIES_MESSAGEnow_NOWtimezoneutc_UTCr,   r2   r4   rA   rE   rI   rP   objectrR   r   r   r   rv   ru   r   r   r   r   r   r)   r*   r+   <module>r      s   
         				 ! ! ! ! ! ! # # # # # #       " " " " " " ( ( ( ( ( ( ; ; ; ; ; ; 4 4 4 4 4 4 P P P P P P 3  >!8  O 6  O+ 4 3::, ;    ry6== - 	     : : :       D D D    $[+ [+ [+ [+ [+V [+ [+ [+|
& & &6 6 6 6** * * 4 4 4$  8  &       (< < < <D0 0 0 3	           r*   