a
    xd'                     @   s0  d dl mZ d dl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 erd d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ edZededef dZdZdZdZ G dd deZ!dd Z"dd Z#dd Z$d d! Z%d"d# Z&dS )$    )absolute_importN)wraps)Hub)reraise)capture_internal_exceptionsevent_from_exception)Integration)ignore_logger)MYPY)Any)Iterator)TypeVar)Optional)Callable)Client)ExcInfoTF.)boundz_wrapped_{}_z_inspect_{}Z_sentry_used_c                   @   s   e Zd ZdZedd ZdS )BeamIntegrationbeamc                     sh   ddl m} m} td td g d  D ]}t| t|t| | q,|j fdd}||_d S )Nr   )DoFnParDorootzbundle_processor.create)processZstart_bundleZfinish_bundlesetupc                    s   t | dds D ]h}t||s qt|}t ||}t |t|}t |tdst |tdst||| t||t| qd| _| |g|R i | d S )N_sentry_is_patchedFT)	getattrhasattrWRAPPED_FUNCformatINSPECT_FUNC	USED_FUNCsetattr_wrap_task_callr   )selffnargskwargs	func_namewrapped_funcprocess_funcZinspect_funcZfunction_patchesZold_init T/var/www/html/Ranjet/env/lib/python3.9/site-packages/sentry_sdk/integrations/beam.pysentry_init_pardo6   s    


z5BeamIntegration.setup_once.<locals>.sentry_init_pardo)	apache_beam.transforms.corer   r   r	   r#   r!   r    _wrap_inspect_call__init__)r   r   r)   r/   r-   r,   r.   
setup_once$   s    zBeamIntegration.setup_onceN)__name__
__module____qualname__
identifierstaticmethodr3   r-   r-   r-   r.   r   !   s   r   c                    s*   t |  sd S  fdd}t|td |S )Nc                    s   t  }t| |r t| |}n&t|  }t|  t| t| || zddlm} ||W S  ty   ddl	m
} || Y S 0 dS )zG
        Inspect function overrides the way Beam gets argspec.
        r   )get_function_args_defaults)getfullargspecN)r   r    r   r   r#   r$   r0   r9   ImportErrorZ apache_beam.typehints.decoratorsr:   )r%   r*   r+   r9   r:   r)   r-   r.   _inspectW   s    



z$_wrap_inspect_call.<locals>._inspectT)r   r#   r"   )clsr)   r=   r-   r<   r.   r1   Q   s
    
r1   c                    s.   t jj t fdd}t|td |S )z~
    Wrap task call with a try catch to get exceptions.
    Pass the client on to raise_exception so it can get rebinded.
    c                     sH   z| i |}W n t y,   t  Y n0 t|tjs>|S t| S )N)	Exceptionraise_exception
isinstancetypesGeneratorType_wrap_generator_call)r'   r(   genclientfuncr-   r.   _inner{   s    z_wrap_task_call.<locals>._innerT)r   currentrG   r   r#   r"   )rH   rI   r-   rF   r.   r$   s   s
    r$   c                 C   sT   | t}|du rdS |j}|du r(dS t| |jdddd\}}|j||d dS )z(
    Send Beam exception to Sentry.
    Nr   F)typeZhandled)Zclient_optionsZ	mechanism)hint)Zget_integrationr   rG   r   optionsZcapture_event)exc_infohubZintegrationrG   eventrL   r-   r-   r.   _capture_exception   s    

rQ   c                 C   s^   t j}|jdu r||  t }t  t|| W d   n1 sH0    Y  t|  dS )zI
    Raise an exception. If the client is not in the hub, rebind it.
    N)	r   rJ   rG   Zbind_clientsysrN   r   rQ   r   )rG   rO   rN   r-   r-   r.   r@      s    

(r@   c                 c   sD   zt | V  W q  ty$   Y q@Y q  ty<   t| Y q 0 q dS )z4
    Wrap the generator to handle any failures.
    N)nextStopIterationr?   r@   )rE   rG   r-   r-   r.   rD      s    rD   )'
__future__r   rR   rB   Zsentry_sdk._functoolsr   Zsentry_sdk.hubr   Zsentry_sdk._compatr   Zsentry_sdk.utilsr   r   Zsentry_sdk.integrationsr   Zsentry_sdk.integrations.loggingr	   Zsentry_sdk._typesr
   typingr   r   r   r   r   Zsentry_sdk.clientr   r   r   r   r   r!   r"   r   r1   r$   rQ   r@   rD   r-   r-   r-   r.   <module>   s8   0"