
    Bfc                         d Z ddlmZ ddlmZ ddlmZ ddlmZ  G d de          Z	 G d d	e          Z
 G d
 de
          Z G d de          Z G d de
          ZdS )z%Manage access to objects and buckets.    ) _add_generation_match_parameters)_DEFAULT_TIMEOUT)DEFAULT_RETRY))DEFAULT_RETRY_IF_METAGENERATION_SPECIFIEDc                   h    e Zd ZdZdZdZdZddZd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd ZdS )
_ACLEntitya  Class representing a set of roles for an entity.

    This is a helper class that you likely won't ever construct
    outside of using the factor methods on the :class:`ACL` object.

    :type entity_type: str
    :param entity_type: The type of entity (ie, 'group' or 'user').

    :type identifier: str
    :param identifier: (Optional) The ID or e-mail of the entity. For the special
                       entity types (like 'allUsers').
    READERWRITEROWNERNc                 J    || _         t          g           | _        || _        d S N)
identifiersetrolestype)selfentity_typer   s      g/home/panchajanya/Development/work/volatility3/lib/python3.11/site-packages/google/cloud/storage/acl.py__init__z_ACLEntity.__init__)   s!    $WW
			    c                 d    | j         st          | j                  S d                    |           S )Nz{acl.type}-{acl.identifier})acl)r   strr   formatr   s    r   __str__z_ACLEntity.__str__.   s2     	Bty>>!077D7AAAr   c                 D    d|  dd                     | j                   dS )Nz<ACL Entity: z (z, z)>)joinr   r   s    r   __repr__z_ACLEntity.__repr__4   s)    @t@@tyy'<'<@@@@r   c                     | j         S )zGet the list of roles permitted by this entity.

        :rtype: list of strings
        :returns: The list of roles associated with this entity.
        )r   r   s    r   	get_rolesz_ACLEntity.get_roles7   s     zr   c                 :    | j                             |           dS )zoAdd a role to the entity.

        :type role: str
        :param role: The role to add to the entity.
        N)r   addr   roles     r   grantz_ACLEntity.grant?   s     	
tr   c                 P    || j         v r| j                             |           dS dS )zyRemove a role from the entity.

        :type role: str
        :param role: The role to remove from the entity.
        N)r   remover$   s     r   revokez_ACLEntity.revokeG   s5     4:Jd##### r   c                 D    |                      t          j                   dS )z(Grant read access to the current entity.N)r&   r   READER_ROLEr   s    r   
grant_readz_ACLEntity.grant_readP       

:)*****r   c                 D    |                      t          j                   dS )z)Grant write access to the current entity.N)r&   r   WRITER_ROLEr   s    r   grant_writez_ACLEntity.grant_writeT   r-   r   c                 D    |                      t          j                   dS )z)Grant owner access to the current entity.N)r&   r   
OWNER_ROLEr   s    r   grant_ownerz_ACLEntity.grant_ownerX   s    

:()))))r   c                 D    |                      t          j                   dS )z+Revoke read access from the current entity.N)r)   r   r+   r   s    r   revoke_readz_ACLEntity.revoke_read\       J*+++++r   c                 D    |                      t          j                   dS )z,Revoke write access from the current entity.N)r)   r   r/   r   s    r   revoke_writez_ACLEntity.revoke_write`   r6   r   c                 D    |                      t          j                   dS )z,Revoke owner access from the current entity.N)r)   r   r2   r   s    r   revoke_ownerz_ACLEntity.revoke_ownerd   s    J)*****r   r   )__name__
__module____qualname____doc__r+   r/   r2   r   r   r   r!   r&   r)   r,   r0   r3   r5   r8   r:    r   r   r   r      s          KKJ       
B B BA A A    $ $ $+ + ++ + +* * *, , ,, , ,+ + + + +r   r   c                   R   e Zd ZdZdZdZdddddd	d
Z eg d          Z	 dZ	dZ
dZdZd ZefdZed             Zd Zd Zd Zd Zd%dZd Zd%dZd Zd Zd Zd Zd Zd Zed             Z d Z!dee"fd Z#ddddee$fd!Z%ddddddee$fd"Z&dddddee$fd#Z'dddddee$fd$Z(dS )&ACLz7Container class representing a list of access controls.r   predefinedAclprojectPrivate
publicReadpublicReadWriteauthenticatedReadbucketOwnerReadbucketOwnerFullControl)zproject-privatezpublic-readzpublic-read-writezauthenticated-readzbucket-owner-readzbucket-owner-full-control)privaterC   rD   rE   rF   rG   rH   FNc                     i | _         d S r   )entitiesr   s    r   r   zACL.__init__   s    r   c                 D    | j         s|                     |           dS dS )zLoad if not already loaded.

        :type timeout: float or tuple
        :param timeout:
            (Optional) The amount of time, in seconds, to wait
            for the server response.  See: :ref:`configuring_timeouts`
        )timeoutN)loadedreload)r   rM   s     r   _ensure_loadedzACL._ensure_loaded   s2     { 	)KKK(((((	) 	)r   c                 v    | j                             ||          }|r|| j        vrt          d|           |S )a:  Ensures predefined is in list of predefined json values

        :type predefined: str
        :param predefined: name of a predefined acl

        :type predefined: str
        :param predefined: validated JSON name of predefined acl

        :raises: :exc: `ValueError`: If predefined is not a valid acl
        zInvalid predefined ACL: )PREDEFINED_XML_ACLSgetPREDEFINED_JSON_ACLS
ValueError)cls
predefineds     r   validate_predefinedzACL.validate_predefined   sO     ,00ZHH
 	F*C,DDDD
DDEEEr   c                 F    | j                                          d| _        dS )z@Remove all entities from the ACL, and clear the ``loaded`` flag.FN)rK   clearrN   r   s    r   resetz	ACL.reset   s!    r   c              #      K   |                                   | j                                        D ]/}|                                D ]}|rt	          |          |dV  0d S )N)entityr%   )rP   rK   valuesr!   r   )r   r]   r%   s      r   __iter__zACL.__iter__   s      m**,, 	@ 	@F((** @ @ @%([[$?????@	@ 	@r   c                 r   |d         }|d         }|dk    r|                                  }nO|dk    r|                                 }n4d|v r0|                    dd          \  }}|                     ||          }t	          |t
                    st          d|           |                    |           |S )	a  Build an _ACLEntity object from a dictionary of data.

        An entity is a mutable object that represents a list of roles
        belonging to either a user or group or the special types for all
        users and all authenticated users.

        :type entity_dict: dict
        :param entity_dict: Dictionary full of data from an ACL lookup.

        :rtype: :class:`_ACLEntity`
        :returns: An Entity constructed from the dictionary.
        r]   r%   allUsersallAuthenticatedUsers-   r   r   zInvalid dictionary: )allall_authenticatedsplitr]   
isinstancer   rU   r&   )r   entity_dictr]   r%   r   r   s         r   entity_from_dictzACL.entity_from_dict   s     X&6"ZXXZZFF...++--FFF]]&,ll3&:&:#K[[[Z[PPF&*-- 	CAKAABBBTr   c                 V    |                                   t          |          | j        v S )a  Returns whether or not this ACL has any entries for an entity.

        :type entity: :class:`_ACLEntity`
        :param entity: The entity to check for existence in this ACL.

        :rtype: bool
        :returns: True of the entity exists in the ACL.
        )rP   r   rK   r   r]   s     r   
has_entityzACL.has_entity   s)     	6{{dm++r   c                 z    |                                   | j                            t          |          |          S )a  Gets an entity object from the ACL.

        :type entity: :class:`_ACLEntity` or string
        :param entity: The entity to get lookup in the ACL.

        :type default: anything
        :param default: This value will be returned if the entity
                        doesn't exist.

        :rtype: :class:`_ACLEntity`
        :returns: The corresponding entity or the value provided
                  to ``default``.
        )rP   rK   rS   r   )r   r]   defaults      r   
get_entityzACL.get_entity   s4     	}  Vg666r   c                 \    |                                   || j        t          |          <   dS )zAdd an entity to the ACL.

        :type entity: :class:`_ACLEntity`
        :param entity: The entity to add to this ACL.
        N)rP   rK   r   rm   s     r   
add_entityzACL.add_entity   s.     	%+c&kk"""r   c                     t          ||          }|                     |          r|                     |          }n|                     |           |S )a  Factory method for creating an Entity.

        If an entity with the same type and identifier already exists,
        this will return a reference to that entity.  If not, it will
        create a new one and add it to the list of known entities for
        this ACL.

        :type entity_type: str
        :param entity_type: The type of entity to create
                            (ie, ``user``, ``group``, etc)

        :type identifier: str
        :param identifier: The ID of the entity (if applicable).
                           This can be either an ID or an e-mail address.

        :rtype: :class:`_ACLEntity`
        :returns: A new Entity or a reference to an existing identical entity.
        re   )r   rn   rq   rs   )r   r   r   r]   s       r   r]   z
ACL.entity  sT    & 
KKK??6"" 	$__V,,FFOOF###r   c                 0    |                      d|          S )zFactory method for a user Entity.

        :type identifier: str
        :param identifier: An id or e-mail for this particular user.

        :rtype: :class:`_ACLEntity`
        :returns: An Entity corresponding to this user.
        userr   r]   r   r   s     r   rv   zACL.user  s     {{6j{999r   c                 0    |                      d|          S )zFactory method for a group Entity.

        :type identifier: str
        :param identifier: An id or e-mail for this particular group.

        :rtype: :class:`_ACLEntity`
        :returns: An Entity corresponding to this group.
        grouprw   rx   ry   s     r   r{   z	ACL.group'  s     {{7z{:::r   c                 0    |                      d|          S )zFactory method for a domain Entity.

        :type domain: str
        :param domain: The domain for this entity.

        :rtype: :class:`_ACLEntity`
        :returns: An entity corresponding to this domain.
        domainrw   rx   )r   r}   s     r   r}   z
ACL.domain2  s     {{8{777r   c                 ,    |                      d          S )zFactory method for an Entity representing all users.

        :rtype: :class:`_ACLEntity`
        :returns: An entity representing all users.
        ra   rx   r   s    r   rf   zACL.all=  s     {{:&&&r   c                 ,    |                      d          S )zFactory method for an Entity representing all authenticated users.

        :rtype: :class:`_ACLEntity`
        :returns: An entity representing all authenticated users.
        rb   rx   r   s    r   rg   zACL.all_authenticatedE  s     {{2333r   c                 v    |                                   t          | j                                                  S )zGet a list of all Entity objects.

        :rtype: list of :class:`_ACLEntity` objects
        :returns: A list of all Entity objects.
        )rP   listrK   r^   r   s    r   get_entitieszACL.get_entitiesM  s2     	DM((**+++r   c                     t           )z&Abstract getter for the object client.)NotImplementedErrorr   s    r   clientz
ACL.clientV  s
     "!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 ACL.

        :rtype: :class:`google.cloud.storage.client.Client`
        :returns: The client passed in or the currently bound client.
        )r   )r   r   s     r   _require_clientzACL._require_client[  s     >[Fr   c                 X   | j         }|                     |          }i }| j        
| j        |d<   | j                                         |                    ||||          }d| _        |                    dd          D ]*}|                     | 	                    |                     +dS )a  Reload the ACL data 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: (Optional) The client to use.  If not passed, falls back
                       to the ``client`` stored on the ACL's parent.
        :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: :class:`~google.api_core.retry.Retry`
        :param retry:
            (Optional) How to retry the RPC. See: :ref:`configuring_retries`
        NuserProjectquery_paramsrM   retryTitemsr?   )
reload_pathr   user_projectrK   rZ   _get_resourcerN   rS   rs   rk   )r   r   rM   r   pathr   foundentrys           r   rO   z
ACL.reloadj  s    $ %%f--(*.*;L'$$%	 % 
 
 YYw++ 	: 	:EOOD11%889999	: 	:r   c
                    |                      |          }ddi}
|g }||
| j        <   | j        
| j        |
d<   t          |
||||           | j        }|                    || j        t          |          i|
||	          }| j        	                                 |
                    | j        d          D ]*}|                     |                     |                     +d| _        dS )	a  Helper for :meth:`save` and :meth:`save_predefined`.

        :type acl: :class:`google.cloud.storage.acl.ACL`, or a compatible list.
        :param acl: The ACL object to save.  If left blank, this will save
                    current entries.

        :type predefined: str
        :param predefined: An identifier for a predefined ACL.  Must be one of the
            keys in :attr:`PREDEFINED_JSON_ACLS` If passed, `acl` must be None.

        :type client: :class:`~google.cloud.storage.client.Client` or
                      ``NoneType``
        :param client: (Optional) The client to use.  If not passed, falls back
                       to the ``client`` stored on the ACL's parent.

        :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`
        
projectionfullNr   )if_generation_matchif_generation_not_matchif_metageneration_matchif_metageneration_not_matchr   r?   T)r   _PREDEFINED_QUERY_PARAMr   r   	save_path_patch_resource_URL_PATH_ELEMr   rK   rZ   rS   rs   rk   rN   )r   r   rW   r   r   r   r   r   rM   r   r   r   resultr   s                 r   _savez	ACL._save  s   h %%f--$f-!C9CL56(*.*;L'( 3$;$;(C	
 	
 	
 	
 ~'' $s)),% ( 
 
 	ZZ 3R88 	: 	:EOOD11%889999r   c	                 f    |
| }|j         }	nd}	|	r |                     |d|||||||	  	         dS dS )a!  Save this ACL for the current bucket.

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

        :type acl: :class:`google.cloud.storage.acl.ACL`, or a compatible list.
        :param acl: The ACL object to save.  If left blank, this will save
                    current entries.

        :type client: :class:`~google.cloud.storage.client.Client` or
                      ``NoneType``
        :param client: (Optional) The client to use.  If not passed, falls back
                       to the ``client`` stored on the ACL's parent.

        :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`
        NTr   r   r   r   rM   r   )rN   r   )
r   r   r   r   r   r   r   rM   r   save_to_backends
             r   savezACL.save  so    b ;C!jOO"O 	JJ$7(?(?,G  
 
 
 
 
	 	r   c	                 l    |                      |          }|                     d||||||||	  	         dS )a  Save this ACL for the current bucket using a predefined ACL.

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

        :type predefined: str
        :param predefined: An identifier for a predefined ACL.  Must be one
                           of the keys in :attr:`PREDEFINED_JSON_ACLS`
                           or :attr:`PREDEFINED_XML_ACLS` (which will be
                           aliased to the corresponding JSON name).
                           If passed, `acl` must be None.

        :type client: :class:`~google.cloud.storage.client.Client` or
                      ``NoneType``
        :param client: (Optional) The client to use.  If not passed, falls back
                       to the ``client`` stored on the ACL's parent.

        :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`
        Nr   )rX   r   )	r   rW   r   r   r   r   r   rM   r   s	            r   save_predefinedzACL.save_predefined+  sX    h --j99


 3$;$;(C 	 
	
 
	
 
	
 
	
 
	
r   c           
      @    |                      g |||||||           dS )aI  Remove all ACL entries.

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

        Note that this won't actually remove *ALL* the rules, but it
        will remove all the non-default rules.  In short, you'll still
        have access to a bucket that you created even after you clear
        ACL rules with this method.

        :type client: :class:`~google.cloud.storage.client.Client` or
                      ``NoneType``
        :param client: (Optional) The client to use.  If not passed, falls back
                       to the ``client`` stored on the ACL's parent.

        :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`
        )r   r   r   r   r   rM   r   N)r   )r   r   r   r   r   r   rM   r   s           r   rZ   z	ACL.clearl  sB    b 			 3$;$;(C 	 		
 		
 		
 		
 		
r   r   ))r;   r<   r=   r>   r   r   rR   	frozensetrT   rN   r   r   r   r   r   rP   classmethodrX   r[   r_   rk   rn   rq   rs   r]   rv   r{   r}   rf   rg   r   propertyr   r   r   rO   r   r   r   r   rZ   r?   r   r   rA   rA   i   s       AAN- ,#.1.%=  %9	
 	
 	

 
 F KIL   &6 	) 	) 	) 	)   [   
@ @ @  @
, 
, 
,7 7 7 7", , ,   4	: 	: 	:	; 	; 	;	8 	8 	8' ' '4 4 4, , , " " X"   !*:- $: $: $: $:V ! $ $$( 7U U U Ur   $ $$( 7B B B BN   $ $$( 7?
 ?
 ?
 ?
F   $ $$( 7:
 :
 :
 :
 :
 :
r   rA   c                   z     e Zd ZdZ fdZed             Zed             Zed             Zed             Z	 xZ
S )	BucketACLzAn ACL specifically for a bucket.

    :type bucket: :class:`google.cloud.storage.bucket.Bucket`
    :param bucket: The bucket to which this ACL relates.
    c                 d    t          t          |                                            || _        d S r   )superr   r   bucket)r   r   	__class__s     r   r   zBucketACL.__init__  s*    i'')))r   c                     | j         j        S )z&The client bound to this ACL's bucket.)r   r   r   s    r   r   zBucketACL.client  s     {!!r   c                 .    | j         j         d| j         S )3Compute the path for GET API requests for this ACL./)r   r   r   r   s    r   r   zBucketACL.reload_path  s      +"::T%8:::r   c                     | j         j        S z5Compute the path for PATCH API requests for this ACL.)r   r   r   s    r   r   zBucketACL.save_path  s     {r   c                     | j         j        S z?Compute the user project charged for API requests for this ACL.)r   r   r   s    r   r   zBucketACL.user_project  s     {''r   r;   r<   r=   r>   r   r   r   r   r   r   __classcell__r   s   @r   r   r     s              " " X" ; ; X;     X  ( ( X( ( ( ( (r   r   c                       e Zd ZdZdZdZdS )DefaultObjectACLz9A class representing the default object ACL for a bucket.defaultObjectAclpredefinedDefaultObjectAclN)r;   r<   r=   r>   r   r   r?   r   r   r   r     s!        CC'N:r   r   c                   z     e Zd ZdZ fdZed             Zed             Zed             Zed             Z	 xZ
S )	ObjectACLzAn ACL specifically for a Cloud Storage object / blob.

    :type blob: :class:`google.cloud.storage.blob.Blob`
    :param blob: The blob that this ACL corresponds to.
    c                 d    t          t          |                                            || _        d S r   )r   r   r   blob)r   r   r   s     r   r   zObjectACL.__init__  s*    i'')))			r   c                     | j         j        S )z$The client bound to this ACL's blob.)r   r   r   s    r   r   zObjectACL.client  s     yr   c                      | j         j         dS )r   z/aclr   r   r   s    r   r   zObjectACL.reload_path  s     ).&&&&r   c                     | j         j        S r   r   r   s    r   r   zObjectACL.save_path  s     y~r   c                     | j         j        S r   )r   r   r   s    r   r   zObjectACL.user_project  s     y%%r   r   r   s   @r   r   r     s                  X  ' ' X'   X & & X& & & & &r   r   N)r>   google.cloud.storage._helpersr   google.cloud.storage.constantsr   google.cloud.storage.retryr   r   objectr   rA   r   r   r   r?   r   r   <module>r      sD   , + J J J J J J ; ; ; ; ; ; 4 4 4 4 4 4 P P P P P PO+ O+ O+ O+ O+ O+ O+ O+d}
 }
 }
 }
 }
& }
 }
 }
@( ( ( ( ( ( ( (@; ; ; ; ;y ; ; ;& & & & & & & & & &r   