o
    Á¿ií  ã                   @   sŠ   d dl Z d dlZ ddlmZ ddlmZ ddlmZ e jZe jj	Z
e jjZdefdd„Zdeeef fd	d
„Zdd„ Zdd„ Zdd„ ZdS )é    Né   )ÚTracedGreenlet)Ú
TracedIMap)ÚTracedIMapUnorderedÚreturnc                   C   s   t tddƒS )NÚ__version__Ú )ÚgetattrÚgevent© r   r   úY/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/contrib/internal/gevent/patch.pyÚget_version   s   r   c                   C   s   ddiS )Nr
   z>=21.1.2r   r   r   r   r   Ú_supported_versions   s   r   c                   C   s&   t tddƒrdS dt_ttttƒ dS )a
  
    Patch the gevent module so that all references to the
    internal ``Greenlet`` class points to the ``DatadogGreenlet``
    class.

    This action ensures that if a user extends the ``Greenlet``
    class, the ``TracedGreenlet`` is used as a parent class.
    Ú__datadog_patchFNT)r	   r
   r   Ú_replacer   r   r   r   r   r   r   Úpatch   s   	r   c                   C   s&   t tddƒsdS dt_ttttƒ dS )zÀ
    Restore the original ``Greenlet``. This function must be invoked
    before executing application code, otherwise the ``DatadogGreenlet``
    class may be used during initialization.
    r   FN)r	   r
   r   r   Ú
__GreenletÚ__IMapÚ__IMapUnorderedr   r   r   r   Úunpatch&   s   r   c                 C   sh   | t j_| t jj_| t j_| t j_t jjt _t jjjt _t jjjt _|t j_	|t j_	|t j_
|t j_
dS )zU
    Utility function that replace the gevent Greenlet class with the given one.
    N)r
   ÚgreenletÚGreenletÚpoolÚGroupÚgreenlet_classÚ_imapÚspawnÚspawn_laterÚIMapÚIMapUnordered)Úg_classÚ
imap_classÚimap_unordered_classr   r   r   r   3   s   

r   )r
   Úgevent.poolr   r   r   r   r   r   r   r   r   r   r   Ústrr   Údictr   r   r   r   r   r   r   r   Ú<module>   s    