
    YjQ                        d dl mZ d dlZd dlmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlmZ dd	lmZ dd
lmZ ddgZ G d de
      Z G d de      Zy)    )annotationsN)cast   )HeadersLike)construct_type)SyncAPIResourceAsyncAPIResource)InvalidWebhookSignatureError)webhook_signature_matches)UnwrapWebhookEventWebhooksAsyncWebhooksc                  J    e Zd Zdd	 	 	 	 	 	 	 ddZddd	 	 	 	 	 	 	 	 	 ddZy)	r   Nsecretc          	         || j                   j                  }| j                  |||       t        t        t        t        t        j                  |                  S )KValidates that the given payload was sent by OpenAI and parses the payload.payloadheadersr   type_value)_clientwebhook_secretverify_signaturer   r   r   jsonloads)selfr   r   r   s       a/var/www/html/vmm-quimica/venv/lib/python3.12/site-packages/openai/resources/webhooks/webhooks.pyunwrapzWebhooks.unwrap   sT     >\\00FgwvN(jj)
 	
    ,  r   	tolerancec                   || j                   j                  }|t        d      t        ||||      st	        d      dya\  Validates whether or not the webhook payload was sent by OpenAI.

        Args:
            payload: The webhook payload
            headers: The webhook headers
            secret: The webhook secret (optional, will use client secret if not provided)
            tolerance: Maximum age of the webhook in seconds (default: 300 = 5 minutes)
        NzThe webhook secret must either be set using the env var, OPENAI_WEBHOOK_SECRET, on the client class, OpenAI(webhook_secret='123'), or passed to this functionr$   zAThe given webhook signature does not match the expected signaturer   r   
ValueError_webhook_signature_matchesr
   r   r   r   r   r%   s        r    r   zWebhooks.verify_signature(   sZ      >\\00F>` 
 *'76U^_.S `r"   r   str | bytesr   r   r   
str | Nonereturnr   
r   r-   r   r   r   r.   r%   intr/   None__name__
__module____qualname__r!   r    r"   r    r   r      so     "

 

 
 

4 " 
   
r"   c                  J    e Zd Zdd	 	 	 	 	 	 	 ddZddd	 	 	 	 	 	 	 	 	 ddZy)	r   Nr   c          	        || j                   j                  }| j                  |||       t        |t              r|j                  d      n|}t        t        t        t        t        j                  |                  S )r   r   zutf-8r   )r   r   r   
isinstancebytesdecoder   r   r   r   r   )r   r   r   r   bodys        r    r!   zAsyncWebhooks.unwrapH   sm     >\\00FgwvN*4We*Dw~~g&'(jj&
 	
r"   r#   r$   c                   || j                   j                  }|t        d      dt        ||||      st	        d      yr'   r(   r+   s        r    r   zAsyncWebhooks.verify_signature^   sX      >\\00F>` 
 *'76U^_./rss `r"   r,   r0   r3   r7   r"   r    r   r   G   su     "

 

 
 

6 "tt t
 t t 
tr"   )
__future__r   r   typingr   _typesr   _modelsr   	_resourcer   r	   _exceptionsr
   lib._webhooksr   r*   #types.webhooks.unwrap_webhook_eventr   __all__r   r   r7   r"   r    <module>rH      sH    #   ! % : 7 T E
'2 2j1t$ 1tr"   