
    j                         d dl Z d dlZd dlmZmZ d dlmZmZmZ d dl	mZ
  G d de          ZdefdZd	ej        ej                 defd
ZdS )    N)
exceptionstypes)basebinary
structured)r   c                   X   e Zd ZdZdej        ej                 fdZ	 dde	j
        dej        eef         dej        eef         dej        ej                 d	e	j
        f
d
Z	 	 dde	j
        dej        e         dej        ej                 d	ej        ej        eef         ef         fdZdS )HTTPMarshallerzk
    HTTP Marshaller class.
    API of this class designed to work with CloudEvent (upstream and v0.1)
    
convertersc                 J    d |D             | _         d |D             | _        dS )z
        CloudEvent HTTP marshaller constructor
        :param converters: a list of HTTP-to-CloudEvent-to-HTTP constructors
        c                     g | ]}|S  r   .0cs     e/DATA/AppData/hermes/projects/honcho/.venv/lib/python3.11/site-packages/cloudevents/sdk/marshaller.py
<listcomp>z+HTTPMarshaller.__init__.<locals>.<listcomp>"   s    <S<S<S1Q<S<S<S    c                     i | ]
}|j         |S r   )TYPEr   s     r   
<dictcomp>z+HTTPMarshaller.__init__.<locals>.<dictcomp>#   s/     J
 J
 J
AFAJ
 J
 J
r   N)http_convertershttp_converters_by_type)selfr
   s     r   __init__zHTTPMarshaller.__init__   sG    
 =T<S
<S<S<SJ
 J
)J
 J
 J
$$$r   Neventheadersbodydata_unmarshallerreturnc                    |st           j        }t          |          st          j                    d |                                D             }|                    dd          }| j        D ]H}|                    ||          r/|	                    |          r|
                    ||||          c S It          j        d                    || j                            )aX  
        Reads a CloudEvent from an HTTP headers and request body
        :param event: CloudEvent placeholder
        :param headers: a dict-like HTTP headers
        :param body: an HTTP request body as a string or bytes
        :param data_unmarshaller: a callable-like unmarshaller the CloudEvent data
        :return: a CloudEvent
        c                 >    i | ]\  }}|                                 |S r   )lower)r   keyvalues      r   r   z.HTTPMarshaller.FromRequest.<locals>.<dictcomp><   s&    HHH*#u399;;HHHr   zcontent-typeN)r   z'No registered marshaller for {0} in {1})jsonloadscallabler   InvalidDataUnmarshalleritemsgetr   can_readevent_supportedreadUnsupportedEventConverterformat)r   r   r   r   r   content_typecnvrtrs          r   FromRequestzHTTPMarshaller.FromRequest'   s    ! 	+ $
)** 	74666 IHHHH{{>488* 	L 	LFg    L((//L {{5'49JKKKKK25<<d2 
 
 	
r   converter_typedata_marshallerc                     |"t          |          st          j                    || j        d         j        }|| j        v r#| j        |         }|                    ||          S t          j        |          )aP  
        Writes a CloudEvent into a HTTP-ready form of headers and request body
        :param event: CloudEvent
        :param converter_type: a type of CloudEvent-to-HTTP converter
        :param data_marshaller: a callable-like marshaller CloudEvent data
        :return: dict of HTTP headers and stream of HTTP request body
        Nr   )r'   r   InvalidDataMarshallerr   r   r   writeNoSuchConverter)r   r   r3   r4   r1   s        r   	ToRequestzHTTPMarshaller.ToRequestK   s|     &x/H/H&2444!!1!49NT9991.AF<<777(888r   )N)NN)__name__
__module____qualname____doc__typingSequencer   	Converterr   
event_base	BaseEventMappingstrUnionbytesOptionalr   UnmarshallerTyper2   MarshallerTypeTupleDictr9   r   r   r   r	   r	      s+        

6?4>#B 
 
 
 
 FJ"
 "
#"
 S)"
 l3:&	"

 "?5+AB"
 
	"
 "
 "
 "
N 04AE	9 9#9 ,9  )=>	9
 
fk#s(+U2	39 9 9 9 9 9r   r	   r   c                  h    t          t          j                    t          j                    g          S )z
    Creates the default HTTP marshaller with both structured and binary converters.

    :return: an instance of HTTP marshaller
    )r	   r   NewJSONHTTPCloudEventConverterr    NewBinaryHTTPCloudEventConverterr   r   r   NewDefaultHTTPMarshallerrO   e   s3     577355	
  r   r
   c                      t          |           S )z
    Creates the default HTTP marshaller with both structured and binary converters.

    :param converters: a list of CloudEvent-to-HTTP-to-CloudEvent converters

    :return: an instance of HTTP marshaller
    )r	   )r
   s    r   NewHTTPMarshallerrQ   s   s     *%%%r   )r%   r>   cloudevents.sdkr   r   cloudevents.sdk.convertersr   r   r   cloudevents.sdk.eventrA   objectr	   rO   r?   r@   rQ   r   r   r   <module>rV      s      - - - - - - - - ? ? ? ? ? ? ? ? ? ? 4 4 4 4 4 4K9 K9 K9 K9 K9V K9 K9 K9\.    
&/
&
& 
& 
& 
& 
& 
&r   