3 ÝPfã ã@s ddlmZGdd„deƒZdS)é)ÚBytesIOc@sBeZdZdZdd„Zdd„Zdd„Zdd „Zdd d „Zd d„Z d S)ÚCallbackFileWrapperav Small wrapper around a fp object which will tee everything read into a buffer, and when that file is closed it will execute a callback with the contents of that buffer. All attributes are proxied to the underlying file object. This class uses members with a double underscore (__) leading prefix so as not to accidentally shadow an attribute. cCstƒ|_||_||_dS)N)rÚ_CallbackFileWrapper__bufÚ_CallbackFileWrapper__fpÚ_CallbackFileWrapper__callback)ÚselfÚfpÚcallback©r ú!/usr/lib/python3.6/filewrapper.pyÚ__init__szCallbackFileWrapper.__init__cCs|jdƒ}t||ƒS)Nr)Ú__getattribute__Úgetattr)rÚnamerr r r Ú __getattr__s zCallbackFileWrapper.__getattr__cCsDy |jjdkStk r YnXy|jjStk r>YnXdS)NF)rrÚAttributeErrorÚclosed)rr r r Z__is_fp_closed!s z"CallbackFileWrapper.__is_fp_closedcCs |jr|j|jjƒƒd|_dS)N)rrÚgetvalue)rr r r Ú_close0szCallbackFileWrapper._closeNcCs,|jj|ƒ}|jj|ƒ|jƒr(|jƒ|S)N)rÚreadrÚwriteÚ"_CallbackFileWrapper__is_fp_closedr)rÚamtÚdatar r r r;s   zCallbackFileWrapper.readcCs@|jj|ƒ}|dkr |dkr |S|jj|ƒ|jƒr<|jƒ|S)Nés )rÚ _safe_readrrrr)rrrr r r rCs  zCallbackFileWrapper._safe_read)N) Ú__name__Ú __module__Ú __qualname__Ú__doc__r rrrrrr r r r rs   rN)ÚiorÚobjectrr r r r Ús