????
Your IP : 3.138.86.166
�
��s(�������dZgd�ZddlZddlZddlZddlZddlZddlZddlm Z ddl
mZmZddl
Z
e�ddddd ���ZGd
�dej��ZGd�d
ej��Zejd��Zde_ee��Zej��Ze�e��ddd�deeeeejfdeddfd�ZGd�dej��Z dS)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�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z dS) �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��||_dS�N)r)�selfrs �\/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/dill/logger.py�__init__zTraceAdapter.__init__ts
�������c��td|���}|�|��|j�|��dS)Nz%(prefix)s%(message)s%(suffix)s��handler)�TraceFormatter�setFormatterr�
addHandler)rr� formatters rrzTraceAdapter.addHandlervsE��"�#D�g�V�V�V� ����Y�'�'�'�����w�'�'�'�'�'rc�:�|j�|��dSr)r�
removeHandler)rrs rrzTraceAdapter.removeHandlerzs����!�!�'�*�*�*�*�*rc�
�||fSr�)r�msg�kwargss r�processzTraceAdapter.process|s���F�{�rc��tj�|d���sdS|�tj��rd|_g|_dSd|_dS)NF)�child�)�dill�_dill�is_dill�isEnabledFor�logging�INFO�_trace_depth�_size_stack)r�picklers r�trace_setupzTraceAdapter.trace_setups`���z�!�!�'��!�7�7� ��F����W�\�*�*� (�#$�G� �"$�G����#'�G� � � rc��t|d��stj|g|�Ri|��dS|j�dS|�di��}|�d��}d} |j���}|jj } ||���z
}n"#t$r|t|��z
}YnwxYwn#ttf$rYnwxYw|�>|s|j
�|��n!||j
���z}||d<|r|xjdzc_|j|d<||d<|j|g|�Ri|��|s|xjdz
c_dSdS)Nr.�extra�#�sizer'�depth)�hasattrr�infor.�get�
startswith�_file�tell�framer�
current_frame�AttributeError�len� TypeErrorr/�append�pop) rr0r"�argsr#r3�
pushed_objr5�frames rrzTraceAdapter.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<�9C�;B<�<C�C�CN)
�__name__�
__module__�__qualname__�__doc__rrrr$r1rr!rrrrbsx��������"���(�(�(�+�+�+����(�(�(� &� &� &� &� &rrc�2��eZdZdZdd��fd�
Z�fd�Z�xZS)rz�
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).
Nrc�V��t��j|i|�� |jj}|�t�n##t$rtj��}YnwxYw tj|��j }|tjd��j k|_
dS#t$rd|_
YdSwxYw)Nzutf-8F)�superr�stream�encodingr?�locale�getpreferredencoding�codecs�lookup�name�is_utf8�LookupError)rrrDr#rO� __class__s �rrzTraceFormatter.__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��ddd�}t|dd��dkru|j�d��r|jdz
dzdz}n|jdkrd }n|jd
z
dzdz}|js|�t��dz}|d
z|d<t|d��rNttj
|jd
����dz}|j|dzz }d||rd|dzndfz|d<t|���
|��t���|��S)N�)�prefix�suffixr6rr4r'rrr
�u├┬�-� rZr5�
z [%d %sB]�KMGTP�ir[)�getattrr"r:r6rU� translate� ASCII_MAPr7�int�math�logr5�vars�updaterM�format)r�record�fieldsrZ�powerr5rWs �rrjzTraceFormatter.format�sL����"�-�-���6�7�A�&�&��*�*��z�$�$�S�)�)�
=� �,��*�E�1�E�9������"�"���� �,��*�E�1�H�<���<�
;��)�)�)�4�4�s�:��%��|�F�8���6�6�"�"� [������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)rGrHrIrJrrj�
__classcell__)rWs@rrr�sq���������'+�
E�
E�
E�
E�
E�
E�
E�&�&�&�&�&�&�&�&�&rrr(F�a)�mode�argrp�returnc��t|t��st||���St�|rt
jnt
j��dS)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
)�filerpN)�
isinstance�bool�TraceManagerr�setLevelr,r-�WARNING)rqrps rrr�sO��N�c�4� � �1���4�0�0�0�0�
�O�O�C�<�G�L�L�W�_�=�=�=�=�=rc�$�eZdZdZd�Zd�Zd�ZdS)rwzDcontext manager version of trace(); can redirect the trace to a filec�^�||_||_|du|_t|d��|_dS)N�write)rtrp�redirectr7�file_is_stream)rrtrps rrzTraceManager.__init__s4���� ��� ��D�(��
�%�d�G�4�4����rc���|jr�t���|jrt j|j��|_n$t j|j|j ��|_t�t��t�|j��t�
��|_t�tj��tjSr)r}�stderr_handler�flushr~r,�
StreamHandlerrtr�FileHandlerrprrr�getEffectiveLevel� old_levelrxr-r8)rs r� __enter__zTraceManager.__enter__s����=� -�� � �"�"�"��"�
I�&�4�T�Y�?�?����&�2�4�9�d�i�H�H����!�!�.�1�1�1����t�|�,�,�,� �2�2�4�4��������&�&�&��|�rc��t�|j��|jr`t�|j��t�t��|js|j� ��dSdSdSr)
rrxr�r}rrrr�r~�close)r�exc_infos r�__exit__zTraceManager.__exit__s��������(�(�(��=� %��!�!�$�,�/�/�/����~�.�.�.��&�
%���"�"�$�$�$�$�$� %� %�
%�
%rN)rGrHrIrJrr�r�r!rrrwrwsG������N�N�5�5�5�
���%�%�%�%�%rrwr)!rJ�__all__rR�
contextlibrPr,rf�os� functoolsr�typingrrr(�str� maketransrd�
LoggerAdapterr� Formatterr� getLoggerr� propagater�_StderrHandlerr�rrv�PathLiker�AbstractContextManagerrwr!rr�<module>r�s���"�"�H)�
(�
(��
�
�
�
�����
�
�
�
��������� � � � ������� � � � � � � � �����
�M�M�#�c�#�c�J�J�K�K� �PF&�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