Ë
    s0žjQ  ã                  ó¤   — 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       úZ/home/Script/Script_env/lib/python3.12/site-packages/openai/resources/webhooks/webhooks.pyÚunwrapzWebhooks.unwrap   sT   € ð ˆ>Ø—\‘\×0Ñ0ˆFà×Ñ g°wÀvÐÔNäÜÜÜ(Ü—j‘j Ó)ôó
ð 	
ó    é,  ©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)
        Nz�The 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Ñ0ˆFàˆ>Üð`óð ô
 *¨'°7À6ÐU^Õ_Ü.Ø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Ñ0ˆFà×Ñ g°wÀvÐÔNä*4°W¼eÔ*Dˆw�~‰~˜gÔ&È'ˆÜÜÜÜ(Ü—j‘j Ó&ôó
ð 	
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Ñ0ˆFàˆ>Üð`óð ðô
 *¨'°7À6ÐU^Õ_Ü.Ð/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"   