bgL+dZgdZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z m Z ddl Z eddddd ZGd d ejZGd d ejZejdZde_eeZejZeedddde ee eejfdeddfdZGddejZ 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: ├┬ F2: │└ # F2 [32 B] ├┬ D2: │├┬ T4: ││└ # T4 [35 B] │├┬ D2: ││├┬ T4: │││└ # T4 [50 B] ││├┬ D2: │││└ # D2 [84 B] ││└ # D2 [413 B] │└ # D2 [763 B] └ # M1 [813 B] )adapterloggertraceN)partial)TextIOUnion|+`)│u├┬└c6eZdZdZdZdZdZdZdZdZ 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||_dSN)r)selfrs \/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/dill/logger.py__init__zTraceAdapter.__init__ts  ctd|}|||j|dS)Nz%(prefix)s%(message)s%(suffix)shandler)TraceFormatter setFormatterr addHandler)rr formatters rrzTraceAdapter.addHandlervsE"#DgVVV Y''' w'''''rc:|j|dSr)r removeHandler)rrs rrzTraceAdapter.removeHandlerzs !!'*****rc ||fSr)rmsgkwargss rprocesszTraceAdapter.process|s F{rctj|dsdS|tjrd|_g|_dSd|_dS)NF)child)dill_dillis_dill isEnabledForloggingINFO _trace_depth _size_stack)rpicklers r trace_setupzTraceAdapter.trace_setups`z!!'!77  F   W\ * * (#$G "$G   #'G rct|dstj|g|Ri|dS|jdS|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)hasattrrinfor.get startswith_filetellframer current_frameAttributeErrorlen TypeErrorr/appendpop) rr0r"argsr#r3 pushed_objr5frames rrzTraceAdapter.tracesw//  K -d - - -f - - - F   ' F 7B''^^C((  =%%''DN0E # $! # # #E " # *    D    %#**40000+//111 $f  &  A %  -gw #''''''' &  A %  & &s6%CBCB<9C;B<<CCCN) __name__ __module__ __qualname____doc__rrrr$r1rr!rrrrbsx"(((+++((( & & & & &rrc2eZdZdZddfd ZfdZxZS)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). NrcVtj|i| |jj}|tn##t$rt j}YnwxYw tj|j }|tjdj k|_ dS#t$r d|_ YdSwxYw)Nzutf-8F) superrstreamencodingr?localegetpreferredencodingcodecslookupnameis_utf8 LookupError)rrrDr#rO __class__s rrzTraceFormatter.__init__s$)&))) 5~.H$$  5 5 5244HHH 5 E}X..3H% g(>(>(CCDLLL ! ! ! DLLLL !s!2AABB('B(cdddd}t|dddkru|jdr|jdz dzdz}n|jdkrd }n|jd z dzd z}|js|t d z}|d z|d<t|drNttj |j d dz}|j |dzz }d||r d|dzndfz|d<t| |t|S)N)prefixsuffixr6rr4r'r rr u├┬- rZr5 z [%d %sB]KMGTPir[)getattrr"r:r6rU translate ASCII_MAPr7intmathlogr5varsupdaterMformat)rrecordfieldsrZpowerr5rWs rrjzTraceFormatter.formatsL"-- 67A & & * *z$$S)) = ,*E1E9"" ,*E1H<< ;)))44s:%|F8  66 " " [a0011R7E;%(*D*dE4YGENS4H4HWY-ZZF8  V F###ww~~f%%%r)rGrHrIrJrrj __classcell__)rWs@rrrsq '+ E E E E E E E&&&&&&&&&rrr(Fa)modeargrpreturnct|tst||St|r t jn t jdS)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: ├┬ D2: │└ # 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) isinstancebool TraceManagerrsetLevelr,r-WARNING)rqrps rrrsON c4 140000 OOCrs""H ) ( (     MM#c#cJJ K K PF&F&F&F&F&7(F&F&F&P'&'&'&'&'&W&'&'&'&R  6 " " ,v  ''))>""")>C)>)>)>uT63 34)>c)>TX)>)>)>)>V%%%%%:4%%%%%r