o
    i#                     @  s   U d dl mZ d dlZd dlmZ d dlmZ d dlmZmZm	Z	m
Z
mZmZmZ ddlmZmZ ddlmZ dd	lmZ d
gZe Zded< edZG dd
 d
ee ZdS )    )annotationsN)	b64decode)datetime)castUnionAnyOptionalDictTypeVarGeneric   )_convert_to_isoformatTZ_UTC)_get_json_content)NULL
CloudEventr   _UnsetDataTypec                	   @  s   e Zd ZU dZded< 	 ded< 	 dZded< 	 ded< 	 ded	< 	 d
ed< 	 ded< 	 ded< 	 ded< 	 ded< 	 ddeddddddd#ddZd$ddZe	d%dd Z
e	d&d!d"ZdS )'r   a  Properties of the CloudEvent 1.0 Schema.
    All required parameters must be populated in order to send to Azure.

    :param source: Required. Identifies the context in which an event happened. The combination of id and source must
     be unique for each distinct event. If publishing to a domain topic, source must be the domain topic name.
    :type source: str
    :param type: Required. Type of event related to the originating occurrence.
    :type type: str
    :keyword specversion: Optional. The version of the CloudEvent spec. Defaults to "1.0"
    :paramtype specversion: str
    :keyword data: Optional. Event data specific to the event type.
    :paramtype data: object
    :keyword time: Optional. The time (in UTC) the event was generated.
    :paramtype time: ~datetime.datetime
    :keyword dataschema: Optional. Identifies the schema that data adheres to.
    :paramtype dataschema: str
    :keyword datacontenttype: Optional. Content type of data value.
    :paramtype datacontenttype: str
    :keyword subject: Optional. This describes the subject of the event in the context of the event producer
     (identified by source).
    :paramtype subject: str
    :keyword id: Optional. An identifier for the event. The combination of id and source must be
     unique for each distinct event. If not provided, a random UUID will be generated and used.
    :paramtype id: Optional[str]
    :keyword extensions: Optional. A CloudEvent MAY include any number of additional context attributes
     with distinct names represented as key - value pairs. Each extension must be alphanumeric, lower cased
     and must not exceed the length of 20 characters.
    :paramtype extensions: Optional[dict]
    strsourcetypez1.0specversionidOptional[DataType]dataOptional[datetime]timeOptional[str]
dataschemadatacontenttypesubjectOptional[Dict[str, Any]]
extensionsN)r   r   r   r   r   r    r   r"   kwargsr   returnNonec                K  s   || _ || _|r|| _|r|ntt | _|  |tu r#t	t
| _n|| _|| _|| _|| _|	| _|
| _| jrL| j D ]}| rG| sKtdq=|r_d| }td| dd d S )Nz<Extension attributes should be lower cased and alphanumeric.z, zUnexpected keyword arguments z. zDAny extension attributes must be passed explicitly using extensions.)r   r   r   r   uuiduuid4r   r   r   nowr   r   r   r   r    r   r"   keysislowerisalnum
ValueErrorjoin)selfr   r   r   r   r   r   r   r    r   r"   r#   key	remaining r1   K/home/app/Keep/.python/lib/python3.10/site-packages/azure/core/messaging.py__init__[   s6   
zCloudEvent.__init__c                 C  s$   d | j| j| j| j| jd d S )Nz>CloudEvent(source={}, type={}, specversion={}, id={}, time={})i   )formatr   r   r   r   r   )r.   r1   r1   r2   __repr__   s
   zCloudEvent.__repr__eventDict[str, Any]CloudEvent[DataType]c           	   
     sH  i }g dd v rd v rt dd v r& d}|dur!|nt|d< nd v r:tttttf  d|d< dD ]}| v rQ |}|durM|nt||< q<fdd  D }|rc||d	< z| d d
 d  d  dt	 dd|}W |S  t
y } zt fdddD rt d|t d|d}~ww )a  Returns the deserialized CloudEvent object when a dict is provided.

        :param event: The dict representation of the event which needs to be deserialized.
        :type event: dict
        :rtype: CloudEvent
        :return: The deserialized CloudEvent object.
        )
r   data_base64r   r   r   r   r   r   r   r    r   r9   z@Invalid input. Only one of data and data_base64 must be present.N)r   r   r    c                   s   i | ]\}}| vr||qS r1   r1   ).0kv)reserved_attrr1   r2   
<dictcomp>   s    z(CloudEvent.from_dict.<locals>.<dictcomp>r"   r   r   r   r   r   )r   r   r   r   r   c                 3  s    | ]}| v V  qd S )Nr1   )r:   r/   )r6   r1   r2   	<genexpr>   s
    
z'CloudEvent.from_dict.<locals>.<genexpr>)r    Z	eventTyper   ZdataVersionr   Z	eventTimezThe event you are trying to parse follows the Eventgrid Schema. You can parse EventGrid events using EventGridEvent.from_dict method in the azure-eventgrid library.zThe event does not conform to the cloud event spec https://github.com/cloudevents/spec. The `source` and `type` params are required.r1   )r,   getr   r   r   r   r   bytesitemsr   KeyErrorall)	clsr6   r#   r   itemvalr"   Z	event_objerrr1   )r6   r=   r2   	from_dict   sX   	
 
zCloudEvent.from_dictc                 C  s   t |}t|S )a  Returns the deserialized CloudEvent object when a json payload is provided.

        :param event: The json string that should be converted into a CloudEvent. This can also be
         a storage QueueMessage, eventhub's EventData or ServiceBusMessage
        :type event: object
        :rtype: CloudEvent
        :return: The deserialized CloudEvent object.
        :raises ValueError: If the provided JSON is invalid.
        )r   r   rI   )rE   r6   Z
dict_eventr1   r1   r2   	from_json   s   
zCloudEvent.from_json)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   r   r"   r!   r#   r   r$   r%   )r$   r   )r6   r7   r$   r8   )r6   r   r$   r8   )__name__
__module____qualname____doc____annotations__r   r   r3   r5   classmethodrI   rJ   r1   r1   r1   r2   r      sH   
 	
.J)
__future__r   r&   base64r   r   typingr   r   r   r   r	   r
   r   Zutils._utilsr   r   Zutils._messaging_sharedr   Zserializationr   __all__objectr   rO   r   r   r1   r1   r1   r2   <module>   s   $