a
    !f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').
    ZREADERZWRITERZOWNERNc                 C   s   || _ tg | _|| _d S N)
identifiersetrolestype)selfentity_typer    r   Y/var/www/html/python-backend/venv/lib/python3.9/site-packages/google/cloud/storage/acl.py__init__)   s    
z_ACLEntity.__init__c                 C   s    | j st| jS dj| dS 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 )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   s   |  tj dS )z(Grant read access to the current entity.N)r   r   READER_ROLEr   r   r   r   
grant_readP   s    z_ACLEntity.grant_readc                 C   s   |  tj dS )z)Grant write access to the current entity.N)r   r   WRITER_ROLEr   r   r   r   grant_writeT   s    z_ACLEntity.grant_writec                 C   s   |  tj dS )z)Grant owner access to the current entity.N)r   r   
OWNER_ROLEr   r   r   r   grant_ownerX   s    z_ACLEntity.grant_ownerc                 C   s   |  tj dS )z+Revoke read access from the current entity.N)r   r   r   r   r   r   r   revoke_read\   s    z_ACLEntity.revoke_readc                 C   s   |  tj dS )z,Revoke write access from the current entity.N)r   r   r!   r   r   r   r   revoke_write`   s    z_ACLEntity.revoke_writec                 C   s   |  tj dS )z,Revoke owner access from the current entity.N)r   r   r#   r   r   r   r   revoke_ownerd   s    z_ACLEntity.revoke_owner)N)__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                   @   sZ  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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   ZpredefinedAclprojectPrivate
publicReadpublicReadWriteauthenticatedReadbucketOwnerReadbucketOwnerFullControl)zproject-privatezpublic-readzpublic-read-writezauthenticated-readzbucket-owner-readzbucket-owner-full-control)privater-   r.   r/   r0   r1   r2   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 )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   r5   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)r4   clearr6   r   r   r   r   reset   s    
z	ACL.resetc                 c   s>   |    | j D ]&}| D ]}|rt||dV  qqd S )N)entityr   )r8   r4   valuesr   r   )r   rB   r   r   r   r   __iter__   s
    zACL.__iter__c                 C   s   |d }|d }|dkr"|   }n8|dkr4|  }n&d|v rZ|dd\}}| j||d}t|tsrt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.
        rB   r   allUsersallAuthenticatedUsers-   r   r   zInvalid dictionary: )allall_authenticatedsplitrB   
isinstancer   r<   r   )r   Zentity_dictrB   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.
        )r8   r   r4   r   rB   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``.
        )r8   r4   r:   r   )r   rB   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)r8   r4   r   rO   r   r   r   
add_entity   s    zACL.add_entityc                 C   s0   t ||d}| |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.
        rI   )r   rP   rR   rS   )r   r   r   rB   r   r   r   rB     s
    

z
ACL.entityc                 C   s   | 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   rB   r   r   r   r   r   rT     s    	zACL.userc                 C   s   | j d|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.
        grouprU   rV   rW   r   r   r   rX   (  s    	z	ACL.groupc                 C   s   | j d|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.
        domainrU   rV   )r   rY   r   r   r   rY   3  s    	z
ACL.domainc                 C   s
   |  dS )zFactory method for an Entity representing all users.

        :rtype: :class:`_ACLEntity`
        :returns: An entity representing all users.
        rE   rV   r   r   r   r   rJ   >  s    zACL.allc                 C   s
   |  dS )zFactory method for an Entity representing all authenticated users.

        :rtype: :class:`_ACLEntity`
        :returns: An entity representing all authenticated users.
        rF   rV   r   r   r   r   rK   F  s    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.
        )r8   listr4   rC   r   r   r   r   get_entitiesN  s    zACL.get_entitiesc                 C   s   t dS )z&Abstract getter for the object client.N)NotImplementedErrorr   r   r   r   clientW  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)r]   )r   r]   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 ]}| | 	| qVd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_paramsr5   retryTitemsr   )
reload_pathr^   user_projectr4   r@   Z_get_resourcer6   r:   rS   rN   )r   r]   r5   rb   pathra   foundentryr   r   r   r7   k  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 ]}| | | qd| _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`
        Z
projectionfullNr_   )if_generation_matchif_generation_not_matchif_metageneration_matchif_metageneration_not_matchr`   r   T)r^   _PREDEFINED_QUERY_PARAMre   r   	save_pathZ_patch_resource_URL_PATH_ELEMrZ   r4   r@   r:   rS   rN   r6   )r   r   r>   r]   rj   rk   rl   rm   r5   rb   ra   rf   resultrh   r   r   r   _save  s4    4




z	ACL._savec	           
      C   s<   |du r| }|j }	nd}	|	r8| j|d|||||||d	 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rj   rk   rl   rm   r5   rb   )r6   rr   )
r   r   r]   rj   rk   rl   rm   r5   rb   Z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`
        Nrs   )r?   rr   )	r   r>   r]   rj   rk   rl   rm   r5   rb   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`
        )r]   rj   rk   rl   rm   r5   rb   N)rt   )r   r]   rj   rk   rl   rm   r5   rb   r   r   r   r@   m  s    1z	ACL.clear)N)N))r(   r)   r*   r+   rp   rn   r9   	frozensetr;   r6   r]   rd   ro   re   r   r   r8   classmethodr?   rA   rD   rN   rP   rR   rS   rB   rT   rX   rY   rJ   rK   r[   propertyr^   r   r7   r   rr   rt   ru   r@   r   r   r   r   r,   i   s   

 
	
	
+
Y
G
Cr,   c                       sP   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                    s   t t|   || _d S r   )superry   r   bucket)r   r{   	__class__r   r   r     s    zBucketACL.__init__c                 C   s   | j jS )z&The client bound to this ACL's bucket.)r{   r]   r   r   r   r   r]     s    zBucketACL.clientc                 C   s   | j j d| j S )3Compute the path for GET API requests for this ACL./)r{   rf   rp   r   r   r   r   rd     s    zBucketACL.reload_pathc                 C   s   | j jS z5Compute the path for PATCH API requests for this ACL.)r{   rf   r   r   r   r   ro     s    zBucketACL.save_pathc                 C   s   | j jS z?Compute the user project charged for API requests for this ACL.)r{   re   r   r   r   r   re     s    zBucketACL.user_projectr(   r)   r*   r+   r   rx   r]   rd   ro   re   __classcell__r   r   r|   r   ry     s   


ry   c                   @   s   e Zd ZdZdZdZdS )DefaultObjectACLz9A class representing the default object ACL for a bucket.ZdefaultObjectAclZpredefinedDefaultObjectAclN)r(   r)   r*   r+   rp   rn   r   r   r   r   r     s   r   c                       sP   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 )	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                    s   t t|   || _d S r   )rz   r   r   blob)r   r   r|   r   r   r     s    zObjectACL.__init__c                 C   s   | j jS )z$The client bound to this ACL's blob.)r   r]   r   r   r   r   r]     s    zObjectACL.clientc                 C   s   | j j dS )r~   z/aclr   rf   r   r   r   r   rd     s    zObjectACL.reload_pathc                 C   s   | j jS r   r   r   r   r   r   ro     s    zObjectACL.save_pathc                 C   s   | j jS r   )r   re   r   r   r   r   re     s    zObjectACL.user_projectr   r   r   r|   r   r     s   


r   N)r+   Zgoogle.cloud.storage._helpersr   Zgoogle.cloud.storage.constantsr   Zgoogle.cloud.storage.retryr   r   objectr   r,   ry   r   r   r   r   r   r   <module>   s   R    E 