{G_Tc@s-ddlmZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl m Z mZmZmZddl mZmZdd lmZdd lmZd ejfd YZd ejfdYZdZedkr)endS(i(tunicode_literalsN(tarray(tproxy(twraps(tUserList(tTESTFNtcheck_warningst run_unittestt make_bad_fd(t py3k_bytest cpython_only(t run_python(tFileIOt AutoFileTestscBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZejejdkddZdZdZedZedZedZedZedZedZedZedZedZedZ dZ!edZ"edZ#ed Z$RS(!cCsttd|_dS(Nuw(t_FileIORtf(tself((s,/usr/local/lib/python2.7/test/test_fileio.pytsetUpscCs*|jr|jjntjtdS(N(RtclosetostremoveR(R((s,/usr/local/lib/python2.7/test/test_fileio.pyttearDowns cCswt|j}|jttd|j|jj|j|jjd|_|j t t |ddS(Ni utell( RRtwritetbytestranget assertEqualttellRtNonet assertRaisestReferenceErrortgetattr(Rtp((s,/usr/local/lib/python2.7/test/test_fileio.pyt testWeakRefss   cCs|jjttd|j|jjd|jjd|j|jjd|jjd|j|jjd|jjdd|j|jjd|jjdd|j|jjd|jjdd|j|jjddS( Niii iiiii(RRRRRRtseek(R((s,/usr/local/lib/python2.7/test/test_fileio.pyt testSeekTell(scCsc|j}|j|jd|j|jtx-dD]%}|jttft||dq6WdS(Nuwbumodeucloseduoops(umodeuclosed( RRtmodetclosedtFalseRtAttributeErrort TypeErrortsetattr(RRtattr((s,/usr/local/lib/python2.7/test/test_fileio.pyttestAttributes6s   cCsw|jjd|jjtdd}ttd|_|jj|}|jtdddg|| dS( Nstbtxi uriit xxxxxxxxxx(RRRRRRtreadintoR(Rtatn((s,/usr/local/lib/python2.7/test/test_fileio.pyt testReadintoBs  cCs^ddg}|jj||jjttd|_|jj}|j|ddS(Nt123t456urbt123456(Rt writelinesRRRtreadR(Rtltbuf((s,/usr/local/lib/python2.7/test/test_fileio.pyttestWritelinesListKs   cCsdtddg}|jj||jjttd|_|jj}|j|ddS(NR2R3urbR4(RRR5RRRR6R(RR7R8((s,/usr/local/lib/python2.7/test/test_fileio.pyttestWritelinesUserListSs  cCs?|jt|jjdddg|jt|jjddS(Niii(RR'RR5R(R((s,/usr/local/lib/python2.7/test/test_fileio.pyttestWritelinesError[s"cCs|jjd|jjttd|_|j|jjdd|jjd|j|jj dd|j|jj dddgdS(Ns hi bye abcurishi sbye tabc( RRRRRRR6RR!treadlinet readlines(R((s,/usr/local/lib/python2.7/test/test_fileio.pyttest_none_args_s cCs|jt|jd|jj|jjf|j`|jt|jd|jj|jjf|jj|jt|jddS(Nu<_io.FileIO name=%r mode='%s'>u<_io.FileIO fd=%r mode='%s'>u<_io.FileIO [closed]>(RtreprRtnameR#tfilenoR(R((s,/usr/local/lib/python2.7/test/test_fileio.pyttestReprhs  cCs|j}|j|j |j|j |jt|jd|j|j|jtt d}|jt |j d|j|j |j|j|jdS(Ni uru( Rt assertTruetisattyR$Rt ValueErrorR6RRRR'R.(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyt testErrorsqs   c Csddddddddd d d g }tjjd rI|jdn|jj|j|jjx0|D](}t|j|}|j t |qpWdS( Nufilenouisattyureadureadintouseekutellutruncateuwriteuseekableureadableuwritableuatheos( tsystplatformt startswithRRRRDR$RRRF(Rtmethodst methodnametmethod((s,/usr/local/lib/python2.7/test/test_fileio.pyt testMethodss    cCs^ytddWn9tk rL}|j|jd|j|jdnX|jddS(Nu.uriuShould have raised IOError(RtIOErrortassertNotEqualterrnoRtfilenametfail(Rte((s,/usr/local/lib/python2.7/test/test_fileio.pyt testOpendirs untu&test only works on a POSIX-like systemcCsdtjdtj}|jt}t|dWdQXtj||j|jj t j dS(Nu.ur( RtopentO_RDONLYRRORRRt exceptionRQtEISDIR(Rtfdtcm((s,/usr/local/lib/python2.7/test/test_fileio.pyt testOpenDirFDs  cstfd}|S(NcsZ|j}tj|jz||Wdy|jjWntk rTnXXdS(N(RRRRBRO(RR(tfunc(s,/usr/local/lib/python2.7/test/test_fileio.pytwrappers  (R(R]R^((R]s,/usr/local/lib/python2.7/test/test_fileio.pytClosedFDs cstfd}|S(Ncs|j}tj|jzNy||Wn)tk r[}|j|jtjnX|jdWdy|jjWntk rnXXdS(NuShould have raised IOError( RRRRBRORRQtEBADFRS(RRRT(R](s,/usr/local/lib/python2.7/test/test_fileio.pyR^s  (R(R]R^((R]s,/usr/local/lib/python2.7/test/test_fileio.pytClosedFDRaisesscCs|jdS(N(R(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestErrnoOnClosescCs|jddS(Nua(R(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestErrnoOnClosedWritescCs|jddS(Ni(R!(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestErrnoOnClosedSeekscCs|jdS(N(R(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestErrnoOnClosedTellscCs|jddS(Ni(ttruncate(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestErrnoOnClosedTruncatescCs|jdS(N(tseekable(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestErrnoOnClosedSeekablescCs|jdS(N(treadable(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestErrnoOnClosedReadablescCs|jdS(N(twritable(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestErrnoOnClosedWritablescCs|jdS(N(RB(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestErrnoOnClosedFilenoscCs|j|jtdS(N(RRER%(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestErrnoOnClosedIsattyscCsTy|jjWntk r$nXttd|_tj|jj|jS(Nur(RRRORRRRB(R((s,/usr/local/lib/python2.7/test/test_fileio.pyt ReopenForReads cCs|j}|jddS(Ni(RpR6(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestErrnoOnClosedReads cCs|j}|jdS(N(Rptreadall(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestErrnoOnClosedReadalls cCs,|j}tdd}|j|dS(NR+R,i R-(RpRR.(RRR/((s,/usr/local/lib/python2.7/test/test_fileio.pyttestErrnoOnClosedReadintos (%t__name__t __module__RRR R"R*R1R9R:R;R?RCRGRNRUtunittesttskipIfRRAR\R_RaRbRcRdReRgRiRkRmRnRoRpRqRsRt(((s,/usr/local/lib/python2.7/test/test_fileio.pyR s>         $   tOtherFileTestscBseZdZejejdkddZdZdZ dZ dZ dZ e d Zd Zd Zd Zd ZdZdZdZdZRS(cCs@z+ttd}|j|jt|j|jt|j|jt|jttd}|j|jt|j|jt|j|jt|jttd}|j|jt|j|jt|j|jt|j|j t|jWdt j tXdS(Nuwurua+( RRRRjR%RltTrueRhRRERtunlink(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyt testAbles s$  uwin32uno ttys on WindowscCsytdd}Wntk r3|jdnX|j|jt|j|jttj dkrdtj krtj j d r|j|j tn|j|j t|j dS(Nu/dev/ttyuau need /dev/ttyudarwinubsdusunos(RtEnvironmentErrortskipTestRRjR%RlRzRHRIRJRhRER(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestAblesOnTTY s cCsWxPdD]H}ytt|}Wntk r3qX|j|jd|qWdS(NuuaUuwU+urwurtu%r is an invalid file mode(uuaUuwU+urwurt(RRRFRRS(RR#R((s,/usr/local/lib/python2.7/test/test_fileio.pyttestInvalidModeStrings4s   c Cszlxeddddddddddddg D]9}tt|d }|j|j|dWdQXq.WWdtjjtrtjtnXdS(Nuwuwbuwb+urb+uw+buauabuab+ua+bururbur+bii(uwuwb(uwbuwb(uwb+urb+(uw+burb+(uauab(uabuab(uab+uab+(ua+buab+(ururb(urburb(urb+urb+(ur+burb+(RRRR#RtpathtexistsR{(RtmodesR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestModeStrings?s   %cCs0tttd}|jtjtdS(Nuw(RtstrRRRR{(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestUnicodeOpenNs cCsytjd}Wn"tk r7|jdtnXt|d}zI|jd|jttd}|j|j dWdQXWdt j tXdS(Nuasciiucould not encode %r to asciiuwR<urb( RtencodetUnicodeEncodeErrorR~RRRRVRR6RR{(RtfnR((s,/usr/local/lib/python2.7/test/test_fileio.pyt testBytesOpenTs    cCsd|jttd|jttttjdkr`ddl}|jt|j tndS(Niuwin32i( RRFRtOSErrorRRHRItmsvcrtROt get_osfhandle(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyt testInvalidFdcs  cCsDddl}|jtt|jd|jtt|jddS(Nii(t _testcapiRR'RtINT_MAXtINT_MIN(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyttestInvalidFd_overflowjs cCsd}ytt|}Wnatk r|}|jddkrt|}t|ksb||kry|jd|qyqnX|j|jd|dS(Nuqwertyiu&bad error message for invalid mode: %suno error for invalid mode: %s(RRRFtargsRRSR(Rtbad_modeRtmsgts((s,/usr/local/lib/python2.7/test/test_fileio.pyttestBadModeArgumentqs  cCsttd}|jtttd|j|jd|jd|j|jd|j|j dt j d|jd|j|jd|j|j dt j d|j dS(Nuwi iii( RRRRt bytearrayRRRRfR!RtSEEK_ENDR(RR((s,/usr/local/lib/python2.7/test/test_fileio.pyt testTruncates  cs/fd}z |WdtjtXdS(Ncsttd}|jttd|jttd}|jd}|ttdkr|jd|n|jdkrjd|jn|j |jdkrjd|jn|jt j j t}|dkrjd|ndS( Nuwi ur+iu(Read on file opened for update failed %ruFile pos after read wrong %du!File pos after ftruncate wrong %du"File size after ftruncate wrong %d( RRRRRRR6RSRRfRRtgetsize(Rtdatatsize(R(s,/usr/local/lib/python2.7/test/test_fileio.pyt bug801631s     (RR{R(RR((Rs,/usr/local/lib/python2.7/test/test_fileio.pyttestTruncateOnWindowss cCszttd}|jd|jttd}|jd|jttd}|j}|j|j|dWdytjtWnnXXdS(Nuwbtspamuabteggsurbtspameggs(RVRRRR6RRR{(RRtd((s,/usr/local/lib/python2.7/test/test_fileio.pyt testAppends      cCs|jttddddS(Nu1i(RR'R(R((s,/usr/local/lib/python2.7/test/test_fileio.pyttestInvalidInitsc Cs~tdti}|j|jg|jttg|j|jg|jttdd|j|jgWdQXdS(Ntquietu/some/invalid/nameurt(RRzRtwarningsRR'RRF(Rtw((s,/usr/local/lib/python2.7/test/test_fileio.pyt testWarningss cCsd}yt|WdQXWnttfk r6nXttj}d|ds"    "