o
    Mfc                     @   s   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 deZ	G dd	 d	eZ
G d
d de
ZG dd deZG d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                   @   s~   e Zd ZdZdZdZdZdddZdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zd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                 C   s   || _ tg | _|| _d S N)
identifiersetrolestype)selfentity_typer    r   Z/var/www/html/analyze/labelStudio/lib/python3.10/site-packages/google/cloud/storage/acl.py__init__)   s   

z_ACLEntity.__init__c                 C   s   | j st| jS dj| dS )Nz{acl.type}-{acl.identifier})acl)r   strr   formatr   r   r   r   __str__.   s   
z_ACLEntity.__str__c                 C   s   d|  dd | j dS )Nz<ACL Entity: z (z, z)>)joinr   r   r   r   r   __repr__4   s   z_ACLEntity.__repr__c                 C   s   | 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   r   r   r   	get_roles7   s   z_ACLEntity.get_rolesc                 C   s   | 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   roler   r   r   grant?   s   z_ACLEntity.grantc                 C   s   || 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   r   r   r   revokeG   s   
z_ACLEntity.revokec                 C      |  tj dS )z(Grant read access to the current entity.N)r   r   READER_ROLEr   r   r   r   
grant_readP      z_ACLEntity.grant_readc                 C   r"   )z)Grant write access to the current entity.N)r   r   WRITER_ROLEr   r   r   r   grant_writeT   r%   z_ACLEntity.grant_writec                 C   r"   )z)Grant owner access to the current entity.N)r   r   
OWNER_ROLEr   r   r   r   grant_ownerX   r%   z_ACLEntity.grant_ownerc                 C   r"   )z+Revoke read access from the current entity.N)r!   r   r#   r   r   r   r   revoke_read\   r%   z_ACLEntity.revoke_readc                 C   r"   )z,Revoke write access from the current entity.N)r!   r   r&   r   r   r   r   revoke_write`   r%   z_ACLEntity.revoke_writec                 C   r"   )z,Revoke owner access from the current entity.N)r!   r   r(   r   r   r   r   revoke_ownerd   r%   z_ACLEntity.revoke_ownerr
   )__name__
__module____qualname____doc__r#   r&   r(   r   r   r   r   r   r!   r$   r'   r)   r*   r+   r,   r   r   r   r   r      s"    
	r   c                   @   sX  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d ZefddZedd Zdd Zdd Zdd Zdd Zd<ddZdd Zd<d d!Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zed.d/ Z d0d1 Z!dee"fd2d3Z#ddddee$fd4d5Z%ddddddee$fd6d7Z&dddddee$fd8d9Z'dddddee$fd: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)privater3   r4   r5   r6   r7   r8   FNc                 C   s
   i | _ d S r
   )entitiesr   r   r   r   r      s   
zACL.__init__c                 C   s   | j s| j|d 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   r;   r   r   r   _ensure_loaded   s   zACL._ensure_loadedc                 C   s.   | 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
predefinedr   r   r   validate_predefined   s   zACL.validate_predefinedc                 C   s   | j   d| _dS )z@Remove all entities from the ACL, and clear the ``loaded`` flag.FN)r:   clearr<   r   r   r   r   reset   s   

z	ACL.resetc                 c   s@    |    | j D ]}| D ]}|rt||dV  qq
d S )N)entityr   )r>   r:   valuesr   r   )r   rH   r   r   r   r   __iter__   s   zACL.__iter__c                 C   s   |d }|d }|dkr|   }n|dkr|  }nd|v r-|dd\}}| j||d}t|ts9t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.
        rH   r   allUsersallAuthenticatedUsers-   r   r   zInvalid dictionary: )allall_authenticatedsplitrH   
isinstancer   rB   r   )r   entity_dictrH   r   r   r   r   r   r   entity_from_dict   s   



zACL.entity_from_dictc                 C   s   |    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.
        )r>   r   r:   r   rH   r   r   r   
has_entity   s   	zACL.has_entityc                 C   s   |    | 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``.
        )r>   r:   r@   r   )r   rH   defaultr   r   r   
get_entity   s   zACL.get_entityc                 C   s   |    || jt|< dS )zAdd an entity to the ACL.

        :type entity: :class:`_ACLEntity`
        :param entity: The entity to add to this ACL.
        N)r>   r:   r   rV   r   r   r   
add_entity   s   zACL.add_entityc                 C   s2   t ||d}| |r| |}|S | | |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.
        rO   )r   rW   rY   rZ   )r   r   r   rH   r   r   r   rH     s   


z
ACL.entityc                 C      | j d|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   rH   r   r   r   r   r   r\        	zACL.userc                 C   r[   )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.
        groupr]   r^   r_   r   r   r   ra   '  r`   z	ACL.groupc                 C   r[   )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.
        domainr]   r^   )r   rb   r   r   r   rb   2  r`   z
ACL.domainc                 C   
   |  dS )zFactory method for an Entity representing all users.

        :rtype: :class:`_ACLEntity`
        :returns: An entity representing all users.
        rK   r^   r   r   r   r   rP   =     
zACL.allc                 C   rc   )zFactory method for an Entity representing all authenticated users.

        :rtype: :class:`_ACLEntity`
        :returns: An entity representing all authenticated users.
        rL   r^   r   r   r   r   rQ   E  rd   zACL.all_authenticatedc                 C   s   |    t| j S )zGet a list of all Entity objects.

        :rtype: list of :class:`_ACLEntity` objects
        :returns: A list of all Entity objects.
        )r>   listr:   rI   r   r   r   r   get_entitiesM  s   zACL.get_entitiesc                 C   s   t )z&Abstract getter for the object client.)NotImplementedErrorr   r   r   r   clientV  s   z
ACL.clientc                 C   s   |du r| 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.
        N)rh   )r   rh   r   r   r   _require_client[  s   zACL._require_clientc                 C   sp   | j }| |}i }| jdur| j|d< | j  |j||||d}d| _|ddD ]
}| | 	| q+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_paramsr;   retryTitemsr   )
reload_pathri   user_projectr:   rF   _get_resourcer<   r@   rZ   rU   )r   rh   r;   rm   pathrl   foundentryr   r   r   r=   j  s    



z
ACL.reloadc
                 C   s   |  |}ddi}
|durg }||
| j< | jdur| j|
d< t|
||||d | j}|j|| jt|i|
||	d}| j	  |
| jdD ]
}| | | qEd| _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fullNrj   )if_generation_matchif_generation_not_matchif_metageneration_matchif_metageneration_not_matchrk   r   T)ri   _PREDEFINED_QUERY_PARAMrp   r   	save_path_patch_resource_URL_PATH_ELEMre   r:   rF   r@   rZ   rU   r<   )r   r   rD   rh   rw   rx   ry   rz   r;   rm   rl   rr   resultrt   r   r   r   _save  s4   
4




z	ACL._savec	           
      C   s@   |du r
| }|j }	nd}	|	r| j|d|||||||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rw   rx   ry   rz   r;   rm   )r<   r   )
r   r   rh   rw   rx   ry   rz   r;   rm   save_to_backendr   r   r   save  s"   1
zACL.savec	           	      C   s*   |  |}| jd||||||||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   )rE   r   )	r   rD   rh   rw   rx   ry   rz   r;   rm   r   r   r   save_predefined+  s   
4
zACL.save_predefinedc              
   C   s   | j g |||||||d 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`
        )rh   rw   rx   ry   rz   r;   rm   N)r   )r   rh   rw   rx   ry   rz   r;   rm   r   r   r   rF   l  s   1
z	ACL.clearr
   ))r-   r.   r/   r0   r~   r{   r?   	frozensetrA   r<   ro   r|   rp   r   r   r>   classmethodrE   rG   rJ   rU   rW   rY   rZ   rH   r\   ra   rb   rP   rQ   rf   propertyrh   ri   r   r=   r   r   r   r   rF   r   r   r   r   r1   i   s    

 

		
+
Y
G
Cr1   c                       P   e Zd ZdZ fddZedd Zedd Zedd	 Zed
d Z	  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                       t t|   || _d S r
   )superr   r   bucket)r   r   	__class__r   r   r        
zBucketACL.__init__c                 C      | j jS )z&The client bound to this ACL's bucket.)r   rh   r   r   r   r   rh        zBucketACL.clientc                 C   s   | j j d| j S )3Compute the path for GET API requests for this ACL./)r   rr   r~   r   r   r   r   ro     s   zBucketACL.reload_pathc                 C   r   z5Compute the path for PATCH API requests for this ACL.)r   rr   r   r   r   r   r|     r   zBucketACL.save_pathc                 C   r   z?Compute the user project charged for API requests for this ACL.)r   rp   r   r   r   r   rp     r   zBucketACL.user_projectr-   r.   r/   r0   r   r   rh   ro   r|   rp   __classcell__r   r   r   r   r         


r   c                   @   s   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/   r0   r~   r{   r   r   r   r   r     s    r   c                       r   )	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                    r   r
   )r   r   r   blob)r   r   r   r   r   r     r   zObjectACL.__init__c                 C   r   )z$The client bound to this ACL's blob.)r   rh   r   r   r   r   rh     r   zObjectACL.clientc                 C   s   | j j dS )r   z/aclr   rr   r   r   r   r   ro     s   zObjectACL.reload_pathc                 C   r   r   r   r   r   r   r   r|     r   zObjectACL.save_pathc                 C   r   r   )r   rp   r   r   r   r   rp     r   zObjectACL.user_projectr   r   r   r   r   r     r   r   N)r0   google.cloud.storage._helpersr   google.cloud.storage.constantsr   google.cloud.storage.retryr   r   objectr   r1   r   r   r   r   r   r   r   <module>   s   R    D 