B +4 @sddlZddlZdddddddd d d d d g Zdad ddZddZddZddZddZddZ ddZ dd Z dd Z Gdd d Z dd Zd!dd ZddZedkredS)"Ninputclosenextfilefilenamelineno filelinenofileno isfirstlineisstdin FileInputhook_compressed hook_encodedFrcCs(trtjrtdt||||||atS)Nzinput() already active)_state_file RuntimeErrorr )filesinplacebackupbufsizemodeopenhookr,/opt/alt/python37/lib/python3.7/fileinput.pyrSs cCst}da|r|dS)N)rr)staterrrrascCsts tdtS)Nzno active input())rrrrrrrris cCsts tdtS)Nzno active input())rrrrrrrrwscCsts tdtS)Nzno active input())rrrrrrrrscCsts tdtS)Nzno active input())rrrrrrrrscCsts tdtS)Nzno active input())rrrrrrrrscCsts tdtS)Nzno active input())rrr rrrrr scCsts tdtS)Nzno active input())rrr rrrrr sc@seZdZd(ddZdd Zd d Zd d ZddZddZddZ ddZ ddZ ddZ ddZ ddZddZd d!Zd"d#Zd$d%Zd&d'ZdS))r NFrrrcCst|tr|f}nBt|tjr,t|f}n(|dkrBtjdd}|sLd}nt|}||_||_ ||_ |rddl }|j dt ddd|_d|_d|_d|_d|_d|_d|_d|_|dkrtd d |krddl }| d t d||_|r |rtd t|s td ||_dS)N)-rz!bufsize is deprecated and ignored) stacklevelF)rZrUUrbz=FileInput opening mode must be one of 'r', 'rU', 'U' and 'rb'r z'U' mode is deprecatedz4FileInput cannot use an opening hook in inplace modez#FileInput openhook must be callable) isinstancestrosPathLikefspathsysargvtuple_files_inplace_backupwarningswarnDeprecationWarning _savestdout_output _filename _startlineno _filelinenor_isstdin_backupfilename ValueError_modecallable _openhook)selfrrrrrrr-rrr__init__sJ    zFileInput.__init__cCs |dS)N)r)r;rrr__del__szFileInput.__del__cCsz |Wdd|_XdS)Nr)rr*)r;rrrrs zFileInput.closecCs|S)Nr)r;rrr __enter__szFileInput.__enter__cCs |dS)N)r)r;typevalue tracebackrrr__exit__szFileInput.__exit__cCs|S)Nr)r;rrr__iter__szFileInput.__iter__cCs:x4|}|r |jd7_|S|js*t|qWdS)Nr) _readliner4r StopIterationr)r;linerrr__next__szFileInput.__next__cCs>||krtdy|Stk r8tdYnXdS)Nzaccessing lines out of orderzend of input reached)rrrGrE IndexError)r;irrr __getitem__s  zFileInput.__getitem__cCs|j}d|_|r|t_|j}d|_z|r0|Wd|j}d|_y|`Wntk r\YnXz|rr|jsr|Wd|j }d|_ |r|j syt |Wnt k rYnXd|_XXdS)NF)r0r'stdoutr1rrrDAttributeErrorr5r6r,r$unlinkOSError)r;Z savestdoutoutputfileZbackupfilenamerrrr s4    zFileInput.nextfilecCs:x4|}|r |jd7_|S|js*|S|qWdS)Nr)rDr4rr)r;rFrrrreadline+szFileInput.readlinecCs|jsd|jkrdSdS|jd|_|jdd|_||_d|_d|_d|_d|_|jdkrd|_d|jkrt t j d t j |_nt j |_d |_n\|j rt |j|jpd |_yt |jWntk rYnXt |j|jt|j|j|_yt |jj}Wn$tk r6t|jd |_Yn~Xt jt jBt jB}tt d r`|t jO}t |j||}t |d |_ytt drt |j|Wntk rYnXt j|_ |jt _n,|j!r|!|j|j|_nt|j|j|_|jj"|_#|#S)NbrrrFrzbufferTz.bakwO_BINARYchmod)$r*r8r2rr3r4rr5r6getattrr'stdinr+r$r&r,rMrNrenameopenfstatrst_moder1O_CREATO_WRONLYO_TRUNChasattrrVfdopenrWrKr0r:rQrD)r;ZpermrfdrrrrD6s\           zFileInput._readlinecCs|jS)N)r2)r;rrrrpszFileInput.filenamecCs |j|jS)N)r3r4)r;rrrrsszFileInput.linenocCs|jS)N)r4)r;rrrrvszFileInput.filelinenocCs0|jr(y |jStk r$dSXndSdS)N)rrr7)r;rrrrys  zFileInput.filenocCs |jdkS)Nr)r4)r;rrrr szFileInput.isfirstlinecCs|jS)N)r5)r;rrrr szFileInput.isstdin)NFrrrN)__name__ __module__ __qualname__r<r=rr>rBrCrGrJrrQrDrrrrr r rrrrr s$  +  : cCsVtj|d}|dkr,ddl}|||S|dkrHddl}|||St||SdS)Nrz.gzrz.bz2)r$pathsplitextgzipr[bz2ZBZ2File)rrZextrjrkrrrr s  csfdd}|S)Ncst||dS)N)encodingerrors)r[)rr)rlrmrrrszhook_encoded..openhookr)rlrmrr)rlrmrr scCsddl}d}d}|tjddd\}}x(|D] \}}|dkrDd}|dkr0|}q0Wxtt|||dD]b}|d dd kr|dd }|d dd kr|dd }td ttttrd pd|fqdWtdtttfdS)NrFrzib:z-iTz-b)rrrd  z%d: %s[%d]%s %s*rz %d: %s[%d]) getoptr'r(rprintrrrr )rqrrZoptsargsoarFrrr_tests"  rv__main__)NFrrrN)N)r'r$__all__rrrrrrrrr r r r r rvrerrrrKs*         [