o
    ;i%                     @   s   d Z ddlZddlZddlmZ dZdZedZG dd de	Z
G d	d
 d
eZG dd deZG dd dZG dd dZG dd dZdd ZdS )u  
Vendored version of tblib v3.0.0.

We vendor only tblib/__init__.py because we don't use tblib's pickling features (we use cloudpickle instead).

---

BSD 2-Clause License

Copyright (c) 2013-2023, Ionel Cristian Mărieș. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    N)CodeTypez3.0.0)	TracebackTracebackParseErrorFrameCodezO^\s*File "(?P<co_filename>.+)", line (?P<tb_lineno>\d+)(, in (?P<co_name>.+))?$c                   @   s   e Zd ZdZdd ZdS )	_AttrDict c                 C   s$   z| | W S  t y   t|d w N)KeyErrorAttributeError)selfnamer   r   G/home/ubuntu/.local/lib/python3.10/site-packages/modal/_vendor/tblib.py__getattr__*   s
   

z_AttrDict.__getattr__N)__name__
__module____qualname__	__slots__r   r   r   r   r   r   '   s    r   c                   @      e Zd ZdS )__traceback_makerNr   r   r   r   r   r   r   r   2       r   c                   @   r   )r   Nr   r   r   r   r   r   6   r   r   c                   @   s   e Zd ZdZdZdd ZdS )r   zw
    Class that replicates just enough of the builtin Code object to enable serialization and traceback rendering.
    Nc                 C   s>   |j | _ |j| _d| _d| _d| _d| _d| _d| _d| _d S )Nr   r   @   )	co_filenameco_nameco_argcountco_kwonlyargcountco_varnames
co_nlocalsco_stacksizeco_flagsco_firstlineno)r   coder   r   r   __init__A   s   
zCode.__init__)r   r   r   __doc__co_coder#   r   r   r   r   r   :   s    r   c                   @   s&   e Zd ZdZddddZdd ZdS )r   a  
    Class that replicates just enough of the builtin Frame object to enable serialization and traceback rendering.

    Args:

        get_locals (callable): A function that take a frame argument and returns a dict.

            See :class:`Traceback` class for example.
    N
get_localsc                C   sD   |d u ri n||| _ dd |j D | _t|j| _|j| _d S )Nc                 S   s   i | ]\}}|d v r||qS )__file__r   r   ).0kvr   r   r   
<dictcomp>Z   s    z"Frame.__init__.<locals>.<dictcomp>)f_locals	f_globalsitemsr   f_codef_lineno)r   framer'   r   r   r   r#   X   s   zFrame.__init__c                 C   s   dS )z
        For compatibility with PyPy 3.5;
        clear() was added to frame in Python 3.4
        and is called by traceback.clear_frames(), which
        in turn is called by unittest.TestCase.assertRaises
        Nr   )r   r   r   r   clear^   s    zFrame.clear)r   r   r   r$   r#   r4   r   r   r   r   r   M   s    
r   c                   @   sT   e Zd ZdZdZddddZdd ZeZdd	 ZeZ	e
d
d Ze
dddZdS )r   a'  
    Class that wraps builtin Traceback objects.

    Args:
        get_locals (callable): A function that take a frame argument and returns a dict.

            Ideally you will only return exactly what you need, and only with simple types that can be json serializable.

            Example:

            .. code:: python

                def get_locals(frame):
                    if frame.f_locals.get("__tracebackhide__"):
                        return {"__tracebackhide__": True}
                    else:
                        return {}
    Nr&   c                C   s|   t |j|d| _t|j| _|j}| }t| }|d ur<t|}t |j|d|_t|j|_||_|}|j}|d usd S d S )Nr&   )r   tb_frameint	tb_linenotb_nexttypeobject__new__)r   tbr'   prev_tracebackcls	tracebackr   r   r   r#   }   s   
zTraceback.__init__c                 C   s  | }d}d}|r|j j}td|jd  d |j jjd}t|dr.|jd|j|jddd	}ntd|j	|j
|j|j|j|j|j|j|j|j|j|jdd}zt|t|j jt|j j W n  ty|   t d
 j}|du rp|}|durw||_|}~Y nw |j}|sz|W ~~S ~~w )zm
        Convert to a builtin Traceback object that is usable for raising or rendering a stacktrace.
        N
   zraise __traceback_makerexecreplacer   r   )r   r   r   co_freevarsco_cellvars   )r5   r1   compiler7   r   hasattrrC   r   r   r   r   r   r    r%   	co_constsco_namesr   r!   	co_lnotabrB   dictr/   r.   	Exceptionsysexc_infor8   )r   currenttop_tbr<   r1   r"   next_tbr   r   r   as_traceback   sX    
 	&zTraceback.as_tracebackc                 C   sX   | j du rd}n| j  }| jjj| jjjd}| jj| jj|| jjd}|| j	|dS )z
        Converts to a dictionary representation. You can serialize the result to JSON as it only has
        builtin objects like dicts, lists, ints or strings.
        Nr   r   r/   r.   r1   r2   r5   r7   r8   )
r8   as_dictr5   r1   r   r   r/   r.   r2   r7   )r   r8   r"   r3   r   r   r   rW      s   

zTraceback.as_dictc                 C   s   |d r|  |d }nd}t|d d d |d d d d}t|d d |d d	i ||d d
 d}t||d |d}| |tdS )zj
        Creates an instance from a dictionary with the same structure as ``.as_dict()`` returns.
        r8   Nr5   r1   r   r   rT   r/   r.   r2   rU   r7   rV   r&   )	from_dictr   getget_all_locals)r>   dctr8   r"   r3   r<   r   r   r   rX      s&   

zTraceback.from_dictTc           	      C   s   g }|}|  D ](}| }|r|dkrd}qt|}|r&||  q|dr,q|r0 nq|rZd}t|D ]}t|t|t|d ddi t|t	|d d	|d
}q9| |S t
d| )z
        Creates an instance by parsing a stacktrace. Strict means that parsing stops when lines are not indented by at least two spaces
        anymore.
        z"Traceback (most recent call last):Fz  Nr   ?r(   r7   rU   )r5   r8   z Could not find any frames in %r.)
splitlinesrstripFRAME_REmatchappend	groupdict
startswithreversedr   r6   r   )	r>   stringstrictframesheaderlineframe_matchpreviousr3   r   r   r   from_string   sF   



zTraceback.from_string)T)r   r   r   r$   r8   r#   rS   to_tracebackrW   to_dictclassmethodrX   rl   r   r   r   r   r   g   s    3
r   c                 C   s
   t | jS r	   )rL   r.   )r3   r   r   r   rZ   &  s   
rZ   )r$   rerN   typesr   __version____all__rG   r_   rL   r   rM   r   r   r   r   r   rZ   r   r   r   r   <module>   s    
 @