
    j'*                        U d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
mZmZ d dlmZ d dlmZmZ dej        dej        ej        eeej        f                  fd	Ze
j        d
 e
j        eiZej        eej        f         ed<   ej        ej        dZ	 ddedej        ej                 defdZ 	 ddej!        e         dej        eef         dej        ej"                 defdZ#	 ddej!        e         dej        ej$        eef         ej%        eef         f         dej        ej        eef                  dej        ej"                 def
dZ&e
j        dfdededej        ej                 dej'        ej        eef         ef         fdZ(	 ddedej        ej                 dej'        ej        eef         ef         fdZ)	 ddedej        ej                 dej'        ej        eef         ef         fdZ*dej        dej        fdZ+dej!        e         dej$        eej        f         defdZ,dedej        eej        f         fdZ-dej        ej        eef                  dej        fdZ.dS )     N)
exceptions)AnyCloudEvent)
converters
marshallertypes)	is_binary)v1v03valuereturnc                 Z    | dS 	 t          j        | g|R i |S # t          $ r | cY S w xY w)a5  
    Serializes the given value into a JSON-encoded string.

    Given a None value returns None as is.
    Given a non-JSON-serializable value returns the value as is.

    :param value:  The value to be serialized into a JSON string.
    :returns: JSON string of the given value OR None OR given value.
    N)jsondumps	TypeError)r   argskwargss      a/DATA/AppData/hermes/projects/honcho/.venv/lib/python3.11/site-packages/cloudevents/conversion.py_best_effort_serialize_to_jsonr      sW     }tz%1$111&111   s    **c                     | S N )xs    r   <lambda>r   /   s         _default_marshaller_by_format)z1.0z0.3eventdata_marshallerc                 0    t          | |          d         S )a  
    Converts given `event` to a JSON string.

    :param event: A CloudEvent to be converted into a JSON string.
    :param data_marshaller: Callable function which will cast `event.data`
        into a JSON string.
    :returns: A JSON string representing the given event.
    r      )to_structuredr   r   s     r   to_jsonr#   6   s     @@@CCr   
event_typedatadata_unmarshallerc                 (    t          i |||           S )ay  
    Parses JSON string `data` into a CloudEvent.

    :param data: JSON string representation of a CloudEvent.
    :param data_unmarshaller: Callable function that casts `data` to a
        Python object.
    :param event_type: A concrete type of the event into which the data is
        deserialized.
    :returns: A CloudEvent parsed from the given JSON representation.
    )headersr%   r&   r$   )	from_http)r$   r%   r&   s      r   	from_jsonr*   E   s'     +	   r   r(   c                    ||dk    rd}t          |t          t          t          f          s$t	          j        dt          |                     d |                                D             }|t          }t          j
                    }t          |          r|                    dd          }n	 t          j        |          }n?# t          j        j        $ r( t	          j        d                    |                    w xY wt'          |d          r|                    d	d          }n't	          j        d
                    |                    |t	          j        d          t(                              |d          }|'t	          j        d                    |                    |                     |            |||          }|                                }	|	                    dd           |	                    dd            |	j        di |j         |j        }
|j        dk    s|j        dk    rd}
|                     |	|
          S )a  
    Parses CloudEvent `data` and `headers` into an instance of a given `event_type`.

    The method supports both binary and structured representations.

    :param headers: The HTTP request headers.
    :param data: The HTTP request body. If set to None, "" or b'', the returned
        event's `data` field will be set to None.
    :param data_unmarshaller: Callable function to map data to a python object
        e.g. lambda x: x or lambda x: json.loads(x)
    :param event_type: The actual type of CloudEvent to deserialize the event to.
    :returns: A CloudEvent instance parsed from the passed HTTP parameters of
        the specified type.
    Nr    zFExpected json of type (str, bytes, bytearray), but instead found type c                 >    i | ]\  }}|                                 |S r   )lower).0keyr   s      r   
<dictcomp>zfrom_http.<locals>.<dictcomp>|   s&    DDDjc5syy{{EDDDr   zce-specversionzdFailed to read specversion from both headers and data. The following can not be parsed as json: {!r}getspecversionznFailed to read specversion from both headers and data. The following deserialized data has no 'get' method: {}z*Failed to find specversion in HTTP requestzFound invalid specversion {})r&   r%   
extensionsr   )
isinstancestrbytes	bytearraycloud_exceptionsInvalidStructuredJSONtypeitems_json_or_stringr   NewDefaultHTTPMarshallerr   r2   r   loadsdecoderJSONDecodeErrorMissingRequiredFieldsformathasattr_obj_by_versionInvalidRequiredFieldsFromRequest
Propertiespopupdater4   r%   create)r$   r(   r%   r&   marshallr3   raw_ceevent_handlerr   attrsresult_datas              r   r)   r)   \   s   , |ts{{dS%344 
43&*4jj3 3
 
 	

 EDGMMOODDDG +244H kk"2D99	Z%%FF|+ 	 	 	"8@@Ft  	
 65!! 	 **]D99KK"8JJP&QW..  
 48
 
 	
 $''T::M4*11+>>
 
 	
   $:K !  E E	IIfd	IIlD!!!EL$$5#$$$/4zKzR5:,, UK000s   2C <DrC   c                 r   |t           |         }| d         t          vrt          j        d| d                    t          | d                              }| D ]}|                    || |                    |                                 |_        t          j                    	                    |||          S )a0  
    Returns a tuple of HTTP headers/body dicts representing this Cloud Event.

    :param format: The encoding format of the event.
    :param data_marshaller: Callable function that casts event.data into
        either a string or bytes.
    :returns: (http_headers: dict, http_body: bytes or str)
    Nr3   zUnsupported specversion: r   )
r   rE   r9   rF   Setget_datar%   r   r>   	ToRequest)r   rC   r   rN   attribute_names        r   _to_httprV      s     7?]?224>m(<>>
 
 	
 $E-$89;;M A A.%*?@@@@))M.00::v ;   r   c                 $    t          | |          S )a  
    Returns a tuple of HTTP headers/body dicts representing this Cloud Event.

    If event.data is a byte object, body will have a `data_base64` field instead of
    `data`.

    :param event: The event to be converted.
    :param data_marshaller: Callable function to cast event.data into
        either a string or bytes
    :returns: (http_headers: dict, http_body: bytes or str)
    r"   )rV   r"   s     r   r!   r!      s     %AAAAr   c                 :    t          | t          j        |          S )aI  
    Returns a tuple of HTTP headers/body dicts representing this Cloud Event.

    Uses Binary conversion format.

    :param event: The event to be converted.
    :param data_marshaller: Callable function to cast event.data into
        either a string or bytes.
    :returns: (http_headers: dict, http_body: bytes or str)
    )r   rC   r   )rV   r   
TypeBinaryr"   s     r   	to_binaryrZ      s'     $'   r   c                     t          | t          j                  r| j        S t          | t          j                  r|                                 S | S )a[  
    SHOULD convert any value into a JSON serialization friendly format.

    This function acts in a best-effort manner and MAY not actually encode the value
    if it does not know how to do that, or the value is already JSON-friendly.

    :param value: Value which MAY or MAY NOT be JSON serializable.
    :return: Possibly encoded value.
    )r5   enumEnumr   datetime	isoformat)r   s    r   "best_effort_encode_attribute_valuer`      sJ     %## {%*++ !   Lr   c                     d |                                 D             }|                     ||                    d                    S )a/  
    Constructs an Event object of a given `event_type` from
    a dict `event` representation.

    :param event: The event represented as a  dict.
    :param event_type: The type of the event to be constructed from the dict.
    :returns: The event of the specified type backed by the given dict.
    c                 @    i | ]\  }}|d k    |t          |          S )r%   )r`   )r/   	attr_name
attr_values      r   r1   zfrom_dict.<locals>.<dictcomp>  s<       !Iz 	5jAAr   r%   )
attributesr%   )r<   rK   r2   )r$   r   re   s      r   	from_dictrf     sO     %*[[]]  J
 
69J9JKKKr   c                 R      fd D             }                                  |d<   |S )z
    Converts given `event` to its canonical dictionary representation.

    :param event: The event to be converted into a dict.
    :returns: The canonical dict representation of the event.
    c                 <    i | ]}|                     |          S r   )r2   )r/   rU   r   s     r   r1   zto_dict.<locals>.<dictcomp>"  s'    TTTNneii77TTTr   r%   )rS   )r   results   ` r   to_dictrj     s7     UTTTeTTTF^^%%F6NMr   contentc                 |    | dS 	 t          j        |           S # t           j        t          t          f$ r | cY S w xY w)z
    Returns a JSON-decoded dictionary or a list of dictionaries if
    a valid JSON string is provided.

    Returns the same `content` in case of an error or `None` when no content provided.
    N)r   r?   rA   r   UnicodeDecodeError)rk   s    r   r=   r=   '  sR     tz'""" )-?@   s    ;;r   )/r^   r\   r   typingcloudeventsr   r9   cloudevents.abstractr   cloudevents.sdkr   r   r   cloudevents.sdk.convertersr   cloudevents.sdk.eventr	   r
   AnyOptionalUnionr7   r6   r   TypeStructuredrY   r   DictMarshallerType__annotations__EventrE   r#   TypeUnmarshallerTyper*   MappingSupportsDuplicateItemsr)   TuplerV   r!   rZ   r`   rf   rj   r=   r   r   r   <module>r      sy       6 6 6 6 6 6 . . . . . . 9 9 9 9 9 9 9 9 9 9 0 0 0 0 0 0 ) ) ) ) ) ) ) ):_V\%fj"89:   * {{9I v{30D+DE   
 (3955
 >BD DD_U%9:D D D D D$ BF M*
,sEz
" u'=> 	   : BFQ1 Q1M*Q1\sCx %">sCx"HHQ1
 /&,sEz2
3Q1 u'=>Q1 Q1 Q1 Q1 Q1l +=A  _U%9: \&+c3h'./	   B >BB BB_U%9:B \&+c3h'./B B B B& TX +1?5;O+P\&+c3h'./   (fj VZ    $LM*L>#vz/*L L L L L(	= 	V[fj%A 	 	 	 	_V\#u*56Z     r   