a
    !f2                     @   s$   d Z ddlmZ G dd deZdS )z>Class for representing a single entity in the Cloud Datastore.    )_ensure_tuple_or_listc                       sZ   e Zd ZdZd fdd	Z fddZdd	 Zed
d Zedd Z	 fddZ
  ZS )Entityal  Entities are akin to rows in a relational database

    An entity storing the actual instance of data.

    Each entity is officially represented with a
    :class:`gcloud.datastore.key.Key` class, however it is possible that
    you might create an Entity with only a partial Key (that is, a Key
    with a Kind, and possibly a parent, but without an ID).  In such a
    case, the datastore service will automatically assign an ID to the
    partial key.

    Entities in this API act like dictionaries with extras built in that
    allow you to delete or persist the data stored on the entity.

    Entities are mutable and act like a subclass of a dictionary.
    This means you could take an existing entity and change the key
    to duplicate the object.

    Use :func:`gcloud.datastore.get` to retrieve an existing entity.

      >>> from gcloud import datastore
      >>> client = datastore.Client()
      >>> client.get(key)
      <Entity[{'kind': 'EntityKind', id: 1234}] {'property': 'value'}>

    You can the set values on the entity just like you would on any
    other dictionary.

    >>> entity['age'] = 20
    >>> entity['name'] = 'JJ'
    >>> entity
    <Entity[{'kind': 'EntityKind', id: 1234}] {'age': 20, 'name': 'JJ'}>

    And you can convert an entity to a regular Python dictionary with the
    ``dict`` builtin:

    >>> dict(entity)
    {'age': 20, 'name': 'JJ'}

    .. note::

       When saving an entity to the backend, values which are "text"
       (``unicode`` in Python2, ``str`` in Python3) will be saved using
       the 'text_value' field, after being encoded to UTF-8.  When
       retrieved from the back-end, such values will be decoded to "text"
       again.  Values which are "bytes" (``str`` in Python2, ``bytes`` in
       Python3), will be saved using the 'blob_value' field, without
       any decoding / encoding step.

    :type key: :class:`gcloud.datastore.key.Key`
    :param key: Optional key to be set on entity.

    :type exclude_from_indexes: tuple of string
    :param exclude_from_indexes: Names of fields whose values are not to be
                                 indexed for this entity.
    N c                    s.   t t|   || _ttd|| _i | _d S )Nexclude_from_indexes)superr   __init__keysetr   _exclude_from_indexes	_meanings)selfr   r   	__class__r   X/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/datastore/entity.pyr   O   s    zEntity.__init__c                    sB   t |tsdS | j|jko@| j|jko@| j|jko@tt| |S )zCompare two entities for equality.

        Entities compare equal if their keys compare equal, and their
        properties compare equal.

        :rtype: boolean
        :returns: True if the entities compare equal, else False.
        F)
isinstancer   r   r
   r   r   __eq__r   otherr   r   r   r   X   s    	


zEntity.__eq__c                 C   s   |  | S )zCompare two entities for inequality.

        Entities compare equal if their keys compare equal, and their
        properties compare equal.

        :rtype: boolean
        :returns: False if the entities compare equal, else True.
        )r   r   r   r   r   __ne__i   s    	zEntity.__ne__c                 C   s   | j r| j jS dS )a;  Get the kind of the current entity.

        .. note::
          This relies entirely on the :class:`gcloud.datastore.key.Key`
          set on the entity.  That means that we're not storing the kind
          of the entity at all, just the properties and a pointer to a
          Key which knows its Kind.
        N)r   kindr   r   r   r   r   t   s    
zEntity.kindc                 C   s
   t | jS )zNames of fields which are *not* to be indexed for this entity.

        :rtype: sequence of field names
        :returns: The set of fields excluded from indexes.
        )	frozensetr
   r   r   r   r   r      s    zEntity.exclude_from_indexesc                    s6   | j r d| j jtt|  f S dtt|   S d S )Nz<Entity%s %s>z<Entity %s>)r   pathr   r   __repr__r   r   r   r   r      s
    zEntity.__repr__)Nr   )__name__
__module____qualname____doc__r   r   r   propertyr   r   r   __classcell__r   r   r   r   r      s   9	

r   N)r   Zgcloud._helpersr   dictr   r   r   r   r   <module>   s   