§
    ðyIf~+  ã                   óÒ  — d Z g d¢ZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
mZmZ ddlZe                     ddddd	œ¦  «        Z G d
„ dej        ¦  «        Z G d„ dej        ¦  «        Z ej        d¦  «        Zde_         ee¦  «        Z ej        ¦   «         Ze                     e¦  «         dddœdeeeeej        f         deddfd„Z G d„ dej        ¦  «        Z dS )uo  
Logging utilities for dill.

The 'logger' object is dill's top-level logger.

The 'adapter' object wraps the logger and implements a 'trace()' method that
generates a detailed tree-style trace for the pickling call at log level INFO.

The 'trace()' function sets and resets dill's logger log level, enabling and
disabling the pickling trace.

The trace shows a tree structure depicting the depth of each object serialized
*with dill save functions*, but not the ones that use save functions from
'pickle._Pickler.dispatch'. If the information is available, it also displays
the size in bytes that the object contributed to the pickle stream (including
its child objects).  Sample trace output:

    >>> import dill, dill.tests
    >>> dill.detect.trace(True)
    >>> dill.dump_session(main=dill.tests)
    â”¬ M1: <module 'dill.tests' from '.../dill/tests/__init__.py'>
    â”œâ”¬ F2: <function _import_module at 0x7f0d2dce1b80>
    â”‚â”” # F2 [32 B]
    â”œâ”¬ D2: <dict object at 0x7f0d2e98a540>
    â”‚â”œâ”¬ T4: <class '_frozen_importlib.ModuleSpec'>
    â”‚â”‚â”” # T4 [35 B]
    â”‚â”œâ”¬ D2: <dict object at 0x7f0d2ef0e8c0>
    â”‚â”‚â”œâ”¬ T4: <class '_frozen_importlib_external.SourceFileLoader'>
    â”‚â”‚â”‚â”” # T4 [50 B]
    â”‚â”‚â”œâ”¬ D2: <dict object at 0x7f0d2e988a40>
    â”‚â”‚â”‚â”” # D2 [84 B]
    â”‚â”‚â”” # D2 [413 B]
    â”‚â”” # D2 [763 B]
    â”” # M1 [813 B]
)ÚadapterÚloggerÚtraceé    N)Úpartial)ÚTextIOÚUnionú|ú+ú`)õ   â”‚u   â”œõ   â”¬õ   â””c                   ó6   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	dS )	ÚTraceAdaptera   
    Tracks object tree depth and calculates pickled object size.

    A single instance of this wraps the module's logger, as the logging API
    doesn't allow setting it directly with a custom Logger subclass.  The added
    'trace()' method receives a pickle instance as the first argument and
    creates extra values to be added in the LogRecord from it, then calls
    'info()'.

    Usage of logger with 'trace()' method:

    >>> from dill.logger import adapter as logger  #NOTE: not dill.logger.logger
    >>> ...
    >>> def save_atype(pickler, obj):
    >>>     logger.trace(pickler, "Message with %s and %r etc. placeholders", 'text', obj)
    >>>     ...
    c                 ó   — || _         d S ©N)r   )Úselfr   s     ú?/var/www/piapp/venv/lib/python3.11/site-packages/dill/logger.pyÚ__init__zTraceAdapter.__init__t   s   € ØˆŒˆˆó    c                 ó†   — t          d|¬¦  «        }|                     |¦  «         | j                             |¦  «         d S )Nz%(prefix)s%(message)s%(suffix)s©Úhandler)ÚTraceFormatterÚsetFormatterr   Ú
addHandler)r   r   Ú	formatters      r   r   zTraceAdapter.addHandlerv   sE   € Ý"Ð#DÈgÐVÑVÔVˆ	Ø×Ò˜YÑ'Ô'Ð'ØŒ×Ò˜wÑ'Ô'Ð'Ð'Ð'r   c                 ó:   — | j                              |¦  «         d S r   )r   ÚremoveHandler)r   r   s     r   r   zTraceAdapter.removeHandlerz   s   € ØŒ×!Ò! 'Ñ*Ô*Ð*Ð*Ð*r   c                 ó
   — ||fS r   © )r   ÚmsgÚkwargss      r   ÚprocesszTraceAdapter.process|   s   € à�Fˆ{Ðr   c                 ó¸   — t           j                             |d¬¦  «        sd S |                      t          j        ¦  «        rd|_        g |_        d S d |_        d S )NF)Úchildé   )ÚdillÚ_dillÚis_dillÚisEnabledForÚloggingÚINFOÚ_trace_depthÚ_size_stack)r   Úpicklers     r   Útrace_setupzTraceAdapter.trace_setup   s`   € åŒz×!Ò! '°Ð!Ñ7Ô7ð 	ØˆFØ×Ò�Wœ\Ñ*Ô*ð 	(Ø#$ˆGÔ Ø"$ˆGÔÐÐà#'ˆGÔ Ð Ð r   c                 ó¾  — t          |d¦  «        st          j        |g|¢R i |¤Ž d S |j        €d S |                     di ¦  «        }|                     d¦  «        }d }	 |j                             ¦   «         }|j        j	        }	 ||                     ¦   «         z  }n"# t          $ r |t          |¦  «        z  }Y nw xY wn# t          t          f$ r Y nw xY w|�>|s|j                             |¦  «         n!||j                             ¦   «         z  }||d<   |r|xj        dz  c_        |j        |d<   ||d<    | j        |g|¢R i |¤Ž |s|xj        dz  c_        d S d S )Nr.   Úextraú#Úsizer'   Údepth)Úhasattrr   Úinfor.   ÚgetÚ
startswithÚ_fileÚtellÚframerÚcurrent_frameÚAttributeErrorÚlenÚ	TypeErrorr/   ÚappendÚpop)	r   r0   r"   Úargsr#   r3   Ú
pushed_objr5   Úframes	            r   r   zTraceAdapter.traceˆ   sË  € Ý�w Ñ/Ô/ð 	ÝŒK˜Ð-˜dÐ-Ð-Ð- fÐ-Ð-Ð-ØˆFØÔÐ'ØˆFØ—
’
˜7 BÑ'Ô'ˆØ—^’^ CÑ(Ô(ˆ
Øˆð
	à”=×%Ò%Ñ'Ô'ˆDØ”NÔ0ˆEð#Ø˜Ÿ
š
™œÑ$��øÝ!ð #ð #ð #à�˜E™
œ
Ñ"���ð#øøøøøõ ¥	Ð*ð 	ð 	ð 	ØˆDð	øøøàÐØð %ØÔ#×*Ò*¨4Ñ0Ô0Ð0Ð0à˜Ô+×/Ò/Ñ1Ô1Ñ1�Ø $��f‘Øð 	&ØÐ Ô  AÑ%Ð Ô Ø Ô-ˆˆg‰Øˆˆw‰ØˆŒ	�#Ð'˜Ð'Ð'Ð' Ð'Ð'Ð'Øð 	&ØÐ Ô  AÑ%Ð Ô Ð Ð ð	&ð 	&s6   Á%C  ÂB ÂC  ÂB<Â9C  Â;B<Â<C  Ã CÃCN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r$   r1   r   r!   r   r   r   r   b   sx   € € € € € ðð ð"ð ð ð(ð (ð (ð+ð +ð +ðð ð ð(ð (ð (ð &ð  &ð  &ð  &ð  &r   r   c                   ó2   ‡ — e Zd ZdZddœˆ fd„
Zˆ fd„Zˆ xZS )r   zÌ
    Generates message prefix and suffix from record.

    This Formatter adds prefix and suffix strings to the log message in trace
    mode (an also provides empty string defaults for normal logs).
    Nr   c                óV  •—  t          ¦   «         j        |i |¤Ž 	 |j        j        }|€t          ‚n## t          $ r t          j        ¦   «         }Y nw xY w	 t          j        |¦  «        j	        }|t          j        d¦  «        j	        k    | _
        d S # t          $ r d| _
        Y d S w xY w)Nzutf-8F)Úsuperr   ÚstreamÚencodingr?   ÚlocaleÚgetpreferredencodingÚcodecsÚlookupÚnameÚis_utf8ÚLookupError)r   r   rD   r#   rO   Ú	__class__s        €r   r   zTraceFormatter.__init__±   sÍ   ø€ Ø�‰ŒÔ˜$Ð) &Ð)Ð)Ð)ð	5Ø”~Ô.ˆHØÐÝ$Ð$ð  øåð 	5ð 	5ð 	5ÝÔ2Ñ4Ô4ˆHˆHˆHð	5øøøð	EÝ”} XÑ.Ô.Ô3ˆHð %­¬°gÑ(>Ô(>Ô(CÒCˆDŒLˆLˆLøõ ð 	!ð 	!ð 	!Ø ˆDŒLˆLˆLˆLð	!øøøs!   œ2 ²AÁAÁB ÂB(Â'B(c                 óˆ  •— dddœ}t          |dd¦  «        dk    ru|j                             d¦  «        r|j        dz
  dz  dz   }n|j        dk    rd	}n|j        d
z
  dz  dz   }| j        s|                     t          ¦  «        dz   }|dz   |d<   t          |d¦  «        r`|j        �Y|j        dk    rNt          t          j        |j        d
¦  «        ¦  «        dz  }|j        |dz  z	  }d||rd|         dz   ndfz  |d<   t          |¦  «                             |¦  «         t          ¦   «                              |¦  «        S )NÚ )ÚprefixÚsuffixr6   r   r4   r'   r   r   r   é   u   â”œâ”¬ú-ú rZ   r5   é
   z	 [%d %sB]ÚKMGTPÚir[   )Úgetattrr"   r:   r6   rU   Ú	translateÚ	ASCII_MAPr7   r5   ÚintÚmathÚlogÚvarsÚupdaterM   Úformat)r   ÚrecordÚfieldsrZ   Úpowerr5   rW   s         €r   rj   zTraceFormatter.format¿   s`  ø€ Ø¨"Ð-Ð-ˆÝ�6˜7 AÑ&Ô&¨Ò*Ð*ØŒz×$Ò$ SÑ)Ô)ð =Ø œ,¨Ñ*¨EÑ1°EÑ9��Ø” Ò"Ð"Ø��à œ,¨Ñ*¨EÑ1°HÑ<�Ø”<ð ;Ø×)Ò)­)Ñ4Ô4°sÑ:�Ø%¨™|ˆF�8ÑÝ�6˜6Ñ"Ô"ð 	[ v¤{Ð'>À6Ä;ÐRSÒCSÐCSå�œ ¤¨aÑ0Ô0Ñ1Ô1°RÑ7ˆEØ”; %¨¡(Ñ*ˆDØ*¨dÈEÐ4Y°G¸E´NÀSÑ4HÐ4HÐWYÐ-ZÑZˆF�8ÑÝˆV‰Œ×Ò˜FÑ#Ô#Ð#Ý‰wŒw�~Š~˜fÑ%Ô%Ð%r   )rG   rH   rI   rJ   r   rj   Ú__classcell__)rW   s   @r   r   r   ª   sq   ø€ € € € € ðð ð '+ð Eð Eð Eð Eð Eð Eð Eð&ð &ð &ð &ð &ð &ð &ð &ð &r   r   r(   FÚa)ÚmodeÚargrp   Úreturnc                ó¶   — t          | t          ¦  «        st          | |¬¦  «        S t                               | rt
          j        nt
          j        ¦  «         dS )u}  print a trace through the stack when pickling; useful for debugging

    With a single boolean argument, enable or disable the tracing.

    Example usage:

        >>> import dill
        >>> dill.detect.trace(True)
        >>> dill.dump_session()

    Alternatively, ``trace()`` can be used as a context manager. With no
    arguments, it just takes care of restoring the tracing state on exit.
    Either a file handle, or a file name and (optionally) a file mode may be
    specitfied to redirect the tracing output in the ``with`` block context. A
    log function is yielded by the manager so the user can write extra
    information to the file.

    Example usage:

        >>> from dill import detect
        >>> D = {'a': 42, 'b': {'x': None}}
        >>> with detect.trace():
        >>>     dumps(D)
        â”¬ D2: <dict object at 0x7f2721804800>
        â”œâ”¬ D2: <dict object at 0x7f27217f5c40>
        â”‚â”” # D2 [8 B]
        â”” # D2 [22 B]
        >>> squared = lambda x: x**2
        >>> with detect.trace('output.txt', mode='w') as log:
        >>>     log("> D = %r", D)
        >>>     dumps(D)
        >>>     log("> squared = %r", squared)
        >>>     dumps(squared)

    Arguments:
        arg: a boolean value, or an optional file-like or path-like object for the context manager
        mode: mode string for ``open()`` if a file name is passed as the first argument
    )Úfilerp   N)Ú
isinstanceÚboolÚTraceManagerr   ÚsetLevelr,   r-   ÚWARNING)rq   rp   s     r   r   r   Ù   sO   € õN �c�4Ñ Ô ð 1Ý ¨4Ð0Ñ0Ô0Ð0Ý
‡O‚O CÐ<•G”L�L­W¬_Ñ=Ô=Ð=Ð=Ð=r   c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )rw   zDcontext manager version of trace(); can redirect the trace to a filec                 ó^   — || _         || _        |d u| _        t          |d¦  «        | _        d S )NÚwrite)rt   rp   Úredirectr7   Úfile_is_stream)r   rt   rp   s      r   r   zTraceManager.__init__  s4   € ØˆŒ	ØˆŒ	Ø DÐ(ˆŒÝ% d¨GÑ4Ô4ˆÔÐÐr   c                 óî  — | j         r¡t                               ¦   «          | j        rt	          j        | j        ¦  «        | _        n$t	          j        | j        | j	        ¦  «        | _        t                               t          ¦  «         t                               | j        ¦  «         t                               ¦   «         | _        t                               t          j        ¦  «         t          j        S r   )r}   Ústderr_handlerÚflushr~   r,   ÚStreamHandlerrt   r   ÚFileHandlerrp   r   r   r   ÚgetEffectiveLevelÚ	old_levelrx   r-   r8   )r   s    r   Ú	__enter__zTraceManager.__enter__  s³   € ØŒ=ð 	-Ý× Ò Ñ"Ô"Ð"ØÔ"ð IÝ&Ô4°T´YÑ?Ô?�”�å&Ô2°4´9¸d¼iÑHÔH�”Ý×!Ò!¥.Ñ1Ô1Ð1Ý×Ò˜tœ|Ñ,Ô,Ð,Ý ×2Ò2Ñ4Ô4ˆŒÝ×Ò�œÑ&Ô&Ð&ÝŒ|Ðr   c                 ó  — t                                | j        ¦  «         | j        r`t                                | j        ¦  «         t                                t          ¦  «         | j        s| j         	                    ¦   «          d S d S d S r   )
r   rx   r…   r}   r   r   r   r€   r~   Úclose)r   Úexc_infos     r   Ú__exit__zTraceManager.__exit__  s…   € Ý×Ò˜œÑ(Ô(Ð(ØŒ=ð 	%Ý×!Ò! $¤,Ñ/Ô/Ð/Ý×Ò�~Ñ.Ô.Ð.ØÔ&ð %Ø”×"Ò"Ñ$Ô$Ð$Ð$Ð$ð		%ð 	%ð%ð %r   N)rG   rH   rI   rJ   r   r†   rŠ   r!   r   r   rw   rw     sG   € € € € € ØNÐNð5ð 5ð 5ð
ð ð ð%ð %ð %ð %ð %r   rw   r   )!rJ   Ú__all__rR   Ú
contextlibrP   r,   rf   ÚosÚ	functoolsr   Útypingr   r   r(   ÚstrÚ	maketransrd   ÚLoggerAdapterr   Ú	Formatterr   Ú	getLoggerr   Ú	propagater   Ú_StderrHandlerr€   r   rv   ÚPathLiker   ÚAbstractContextManagerrw   r!   r   r   ú<module>r™      sß  ðð"ð "ðH )Ð
(Ð
(€à €€€Ø Ð Ð Ð Ø €€€Ø €€€Ø €€€Ø 	€	€	€	Ø Ð Ð Ð Ð Ð Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à €€€ð �MŠM #¨c¸#ÀcÐJÐJÑKÔK€	ðPF&ð F&ð F&ð F&ð F&�7Ô(ñ F&ô F&ð F&ðP'&ð '&ð '&ð '&ð '&�WÔ&ñ '&ô '&ð '&ðR 
ˆÔ	˜6Ñ	"Ô	"€Ø€Ô Ø
ˆ,�vÑ
Ô
€Ø'�Ô'Ñ)Ô)€Ø × Ò �>Ñ "Ô "Ð "ð)>ÈCð )>ð )>ð )>ˆu�T˜6 3¨¬Ð3Ô4ð )>Àcð )>ÐTXð )>ð )>ð )>ð )>ðV%ð %ð %ð %ð %�:Ô4ñ %ô %ð %ð %ð %r   