3 UˆŠZtã @sXdZddlZyddlmZWn ek r<ddlmZYnXGdd„dƒZdd„ZdS) z* This module implements the SmartIO class éN)ÚStringIO)ÚBytesIOc@s:eZdZdZddd„Zdd„Zdd „Zd d „Zd d „ZdS)ÚSmartIOa´ The SmartIO class allows one to put a cap on the memory consumption. StringIO objects are very fast, because they are stored in memory, but if they are too big the memory footprint becomes noticeable. The write method of a SmartIO determines if the data that is to be added to the (initially) StrintIO object does not exceed a certain threshold; if it does, it switches the storage to a temporary disk file é@rcCs$||_tƒ|_|rd|_nd|_dS)Nér)Ú _max_mem_sizerÚ_ioÚ_fixed)ÚselfÚ max_mem_sizeZ force_mem©r ú/usr/lib/python3.6/SmartIO.pyÚ__init__s zSmartIO.__init__cCs ||_dS)N)r)r r r r r Úset_max_mem_size'szSmartIO.set_max_mem_sizecCs|jS)N)r)r r r r Úget_max_mem_size*szSmartIO.get_max_mem_sizecCsP|js@t|ƒ|jjƒ|jkr@tƒ}|j|jjƒƒd|_||_|jj|ƒdS)Nr)r ÚlenrÚtellrÚ _tempfileÚwriteÚgetvalue)r ÚdataZtmpfiler r r r-sz SmartIO.writecCs t|j|ƒS)N)Úgetattrr)r Únamer r r Ú __getattr__9szSmartIO.__getattr__N)rr) Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrr r r r rs   rcCs6ddl}|jdtjƒd\}}tj|ƒtj|dƒS)Nrz_rhn_transports-%d-)Úprefixzwb+)ÚtempfileZmkstempÚosÚgetpidÚunlinkÚfdopen)rÚfdZfnamer r r r=s  r) rr Z cStringIOrÚ ImportErrorÚiorrrr r r r Ú s+