l#gddlZddlZddlZddlmZddlmZmZeje Z dZ de de fdZ ddde d eeeffd ZdS) N)iscoroutinefunction)UnionCallablect|d5}tj||ddddS#1swxYwYdS)Nwb)openpickledump)pathobjws X/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/utils/serialization.py_dumpr s dD  Q Cs 488r attrcfd}|S)z Make decorator to serialize an object or object's attribute :param path: path to file to serialize into :param attr: attribute name to serialize ctjfd}tjfd}tr|S|S)Nc|g|Ri|}t|}td|t||SNzWrite %r to %rgetattrloggerdebugrselfargskwargsresultr rfr s rwrapperz2serialize_attr..decorator..wrappers]Qt-d---f--F$%%C LL)3 5 5 5 $   McK|g|Ri|d{V}t|}td|t||Srrrs r async_wrapperz8serialize_attr..decorator..async_wrapper ss1T3D333F33333333F$%%C LL)3 5 5 5 $   Mr ) functoolswrapsr)rrr"rr s` r decoratorz!serialize_attr..decorators                         q ! ! ! r )r rr%s`` rserialize_attrr's** r )fallbackr(cd t|d5}tj|cdddS#1swxYwYnX#t$rtd|Yn1t $r%}td|Yd}~nd}~wwxYwt|r |n|S)z Restore an object from file :param path: path to read from :param fallback: return or call it if unserialization fails :return: rbNzCan't find %s to unserializez1Unserialize failed with %r. Returning an fallback) rr loadFileNotFoundErrorrwarning Exceptionerrorcallable)r r(res r unserializer3/sM $   ";q>> " " " " " " " " " " " " " " " " " ===5t<<<<< MMM H!LLLLLLLLM!(++ 988:::9s3?3 ?7?7?%B& B/BB)r#loggingr asynciortypingrr getLogger__name__rrstrr'objectr3r&r rr;s ''''''""""""""  8 $ $ Cs>CG::::h.>(?::::::r