a
    !f                     @   s,   d Z ddlZddlmZ G dd deZdS )zDefine API Topics.    N)_rfc3339_to_datetimec                   @   sN   e Zd ZdZdZdddZedd Zedd Zed	d
 Z	e
dd ZdS )Messagea  Messages can be published to a topic and received by subscribers.

    See:
    https://cloud.google.com/pubsub/reference/rest/v1/PubsubMessage

    :type data: bytes
    :param data: the payload of the message

    :type message_id: string
    :param message_id: An ID assigned to the message by the API.

    :type attributes: dict or None
    :param attributes: Extra metadata associated by the publisher with the
                       message.
    Nc                 C   s   || _ || _|| _d S )N)data
message_id_attributes)selfr   r   
attributes r	   V/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/pubsub/message.py__init__(   s    zMessage.__init__c                 C   s   | j du ri | _ | j S )z'Lazily-constructed attribute dictionaryN)r   r   r	   r	   r
   r   -   s    
zMessage.attributesc                 C   s$   | j d}|du rtdt|S )a  Return sortable timestamp from attributes, if passed.

        Allows sorting messages in publication order (assuming consistent
        clocks across all publishers).

        :rtype: :class:`datetime.datetime`
        :returns: timestamp (in UTC timezone) parsed from RFC 3339 timestamp
        :raises: ValueError if timestamp not in ``attributes``, or if it does
                 not match the RFC 3339 format.
        	timestampNzNo timestamp)r   get
ValueErrorr   )r   Zstampr	   r	   r
   r   4   s    zMessage.timestampc                 C   s   | j S )z~Return server-set timestamp.

        :rtype: string
        :returns: timestamp (in UTC timezone) in RFC 3339 format
        )_service_timestampr   r	   r	   r
   service_timestampE   s    zMessage.service_timestampc                 C   s:   t |dd}| ||d |dd}|d|_|S )zFactory:  construct message from API representation.

        :type api_repr: dict or None
        :param api_repr: The API representation of the message

        :rtype: :class:`Message`
        :returns: The message created from the response.
        r       Z	messageIdr   )r   r   r   ZpublishTimestamp)base64	b64decoder   r   )clsZapi_reprr   instancer	   r	   r
   from_api_reprN   s    
zMessage.from_api_repr)N)__name__
__module____qualname____doc__r   r   propertyr   r   r   classmethodr   r	   r	   r	   r
   r      s   



r   )r   r   Zgcloud._helpersr   objectr   r	   r	   r	   r
   <module>   s   