ó æQc@sNdZddlZddlmZddd„ƒYZdd„Zd„ZdS( s* This module implements the SmartIO class iÿÿÿÿN(tStringIOtSmartIOcBsAeZdZddd„Zd„Zd„Zd„Zd„ZRS(s´ 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 i@icCs4||_tƒ|_|r'd|_n d|_dS(Nii(t _max_mem_sizeRt_iot_fixed(tselft max_mem_sizet force_mem((s//usr/lib/python2.7/site-packages/rhn/SmartIO.pyt__init__s    cCs ||_dS(N(R(RR((s//usr/lib/python2.7/site-packages/rhn/SmartIO.pytset_max_mem_size%scCs|jS(N(R(R((s//usr/lib/python2.7/site-packages/rhn/SmartIO.pytget_max_mem_size(scCsv|jsbt|ƒ|jjƒ|jkrbtƒ}|j|jjƒƒd|_||_qbn|jj|ƒdS(Ni(RtlenRttellRt _tempfiletwritetgetvalue(Rtdatattmpfile((s//usr/lib/python2.7/site-packages/rhn/SmartIO.pyR+s "  cCst|j|ƒS(N(tgetattrR(Rtname((s//usr/lib/python2.7/site-packages/rhn/SmartIO.pyt __getattr__7s(t__name__t __module__t__doc__RR R RR(((s//usr/lib/python2.7/site-packages/rhn/SmartIO.pyRs    cCscddl}|stƒ}n|jddtjƒd|ƒ\}}tj|ƒtj|dƒS(Niÿÿÿÿtprefixs_rhn_transports-%d-tdirswb+(ttempfiletgetDefaultStoragetmkstemptostgetpidtunlinktfdopen(ttmpdirRtfdtfname((s//usr/lib/python2.7/site-packages/rhn/SmartIO.pyR ;s    cCs¢d}d}yt|ƒ}Wntk r0|SXx`|jƒD]R}|jdƒr>|jdƒ}t|ƒdkr|djƒp‡|}qq>q>W|jƒ|S(sY Reads the default temp dir from up2date config. if defined uses that else use /tmp. s/etc/sysconfig/rhn/up2dates/tmpstmpDir=t=iiÿÿÿÿ(topentIOErrort readlinest startswithtsplitR tstriptclose(t up2dateCfgR!tftlinetcfgdir((s//usr/lib/python2.7/site-packages/rhn/SmartIO.pyREs   ((RRt cStringIORRtNoneR R(((s//usr/lib/python2.7/site-packages/rhn/SmartIO.pyt s  +