ó ükWc@s?dZddlmZejdƒZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddlZddl Z ddlZddlZejje jƒejdƒZejddeƒdejfd „ƒYZd ejfd „ƒYZd „Zed kr;eƒndS(sTest posix functionsiÿÿÿÿ(t test_supporttposixNs-dummy-symlinktignores.* potential security risk .*t PosixTestercBs…eZd„Zd„Zd„Zejeedƒdƒd„ƒZ ejeedƒdƒd„ƒZ ejeed ƒd ƒd „ƒZ ejeed ƒd ƒd „ƒZ ejeed ƒdƒd„ƒZ ejeed ƒdƒd„ƒZejeedƒdƒd„ƒZejeedƒdƒd„ƒZejeedƒdƒd„ƒZejeedƒdƒd„ƒZejeedƒdƒd„ƒZejeed ƒd!ƒd"„ƒZejeed#ƒd$ƒd%„ƒZd&„Zejeed'ƒd(ƒd)„ƒZejeed'ƒd(ƒd*„ƒZejeed'ƒokejjd+ƒ d(ƒd,„ƒZejeed-ƒd.ƒd/„ƒZejeed0ƒd1ƒd2„ƒZejeed3ƒd4ƒd5„ƒZejeed6ƒd7ƒd8„ƒZ d9„Z!ejeed:ƒd;ƒd<„ƒZ"ejeed=ƒd>ƒd?„ƒZ#ejeed@ƒdAƒdB„ƒZ$ejeedCƒdDƒdE„ƒZ%ejeedFƒdGƒdH„ƒZ&ejeedIƒdJƒdK„ƒZ'ejeedLƒdMƒdN„ƒZ(ejeedOƒdPƒdQ„ƒZ)ejeedRƒdSƒdT„ƒZ*ejeedUƒdVƒdW„ƒZ+ejeedXƒdYƒdZ„ƒZ,ejeed[ƒd\ƒd]„ƒZ-d^„Z.ejeed_ƒd`ƒda„ƒZ/ejeedbƒdcƒdd„ƒZ0ejeedbƒdcƒde„ƒZ1ejeedfƒdgƒdh„ƒZ2ejee3diƒdjƒdk„ƒZ4RS(lcCs/ttjdƒ}|jƒtjg|_dS(Nsw+(topenRtTESTFNtclosetteardown_files(tselftfp((s%/usr/lib/python2.7/test/test_posix.pytsetUps cCs%x|jD]}tj|ƒq WdS(N(Rtostunlink(Rt teardown_file((s%/usr/lib/python2.7/test/test_posix.pyttearDown#scCs©ddddddddd d d d d ddg}tjƒdtjddtƒxI|D]A}tt|dƒ}|dk rZ|ƒ|jt|dƒqZqZWWdQXdS(Ntctermidtgetcwdtgetcwdutunamettimest getloadavgttmpnamtgetegidtgeteuidtgetgidt getgroupstgetpidtgetpgrptgetppidtgetuidRti( twarningstcatch_warningstfilterwarningstDeprecationWarningtgetattrRtNonet assertRaisest TypeError(RtNO_ARG_FUNCTIONStnamet posix_func((s%/usr/lib/python2.7/test/test_posix.pyttestNoArgFunctions's      t getresuidstest needs posix.getresuid()cCsGtjƒ}|jt|ƒdƒx|D]}|j|dƒq)WdS(Nii(RR+t assertEqualtlentassertGreaterEqual(Rtuser_idstval((s%/usr/lib/python2.7/test/test_posix.pyttest_getresuid8s  t getresgidstest needs posix.getresgid()cCsGtjƒ}|jt|ƒdƒx|D]}|j|dƒq)WdS(Nii(RR2R,R-R.(Rt group_idsR0((s%/usr/lib/python2.7/test/test_posix.pyttest_getresgid@s  t setresuidstest needs posix.setresuid()cCsBtjƒ}|jtj|Œƒ|jtjdddƒƒdS(Niÿÿÿÿ(RR+t assertIsNoneR5(Rtcurrent_user_ids((s%/usr/lib/python2.7/test/test_posix.pyttest_setresuidHs cCsLtjƒ}d|krH|ddddf}|jttj|ŒndS(Niiiÿÿÿÿ(RR+R%tOSErrorR5(RR7t new_user_ids((s%/usr/lib/python2.7/test/test_posix.pyttest_setresuid_exceptionPs  t setresgidstest needs posix.setresgid()cCsBtjƒ}|jtj|Œƒ|jtjdddƒƒdS(Niÿÿÿÿ(RR2R6R<(Rtcurrent_group_ids((s%/usr/lib/python2.7/test/test_posix.pyttest_setresgidYs cCsLtjƒ}d|krH|ddddf}|jttj|ŒndS(Niiiÿÿÿÿ(RR2R%R9R<(RR=t new_group_ids((s%/usr/lib/python2.7/test/test_posix.pyttest_setresgid_exceptionas  t initgroupsstest needs os.initgroups()cCs|jttjƒ|jttjdƒ|jttjddƒ|jttjddtƒƒtjƒdkrytj tjƒƒj }Wn t k r±t j dƒ‚nXytj|dƒWn)tk rñ}|j|jtjƒqX|jdƒndS(Nitfooisneed a pwd entryi s+Expected OSError to be raised by initgroups(R%R&RRAR$tobjectR Rtpwdtgetpwuidtpw_nametKeyErrortunittesttSkipTestR9R,terrnotEPERMtfail(RR(te((s%/usr/lib/python2.7/test/test_posix.pyttest_initgroupsjs tstatvfsstest needs posix.statvfs()cCs|jtjtjƒƒdS(N(t assertTrueRROR tcurdir(R((s%/usr/lib/python2.7/test/test_posix.pyt test_statvfsƒstfstatvfsstest needs posix.fstatvfs()cCsAttjƒ}z |jtj|jƒƒƒWd|jƒXdS(N(RRRRPRRStfilenoR(RR ((s%/usr/lib/python2.7/test/test_posix.pyt test_fstatvfsˆs t ftruncatestest needs posix.ftruncate()cCsUttjdƒ}z1|jdƒ|jƒtj|jƒdƒWd|jƒXdS(Nsw+ttesti( RRRtwritetflushRRVRTR(RR ((s%/usr/lib/python2.7/test/test_posix.pyttest_ftruncate‘s   tdupstest needs posix.dup()cCsWttjƒ}z6tj|jƒƒ}|j|tƒtj |ƒWd|j ƒXdS(N( RRRRR[RTtassertIsInstancetintR R(RR tfd((s%/usr/lib/python2.7/test/test_posix.pyttest_dups tconfstrstest needs posix.confstr()cCs?|jttjdƒ|jttjdƒƒdktƒdS(Nt CS_garbagetCS_PATHi(R%t ValueErrorRR`R,R-tTrue(R((s%/usr/lib/python2.7/test/test_posix.pyt test_confstr¨stdup2stest needs posix.dup2()cCsZttjƒ}ttjƒ}z tj|jƒ|jƒƒWd|jƒ|jƒXdS(N(RRRRRfRTR(Rtfp1tfp2((s%/usr/lib/python2.7/test/test_posix.pyt test_dup2®s   cGs8tjtjtjƒ}tj||Œ}|jƒdS(N(R RRRtO_RDONLYRtfdopenR(RtargsR^Rh((s%/usr/lib/python2.7/test/test_posix.pyt fdopen_helper¹sRkstest needs posix.fdopen()cCs+|jƒ|jdƒ|jddƒdS(Ntrid(Rm(R((s%/usr/lib/python2.7/test/test_posix.pyt test_fdopen¾s  cCs—ytjdtjƒ}Wn6tk rQ}|j|jtjƒ|jdƒnX|jt ƒ}tj |dƒWdQX|j|j jtj ƒdS(Nt.ssystem cannot open directoriesRn( R RRjR9R,RJtEACCEStskipTestR%tIOErrorRkt exceptiontEISDIR(RR^RMtcm((s%/usr/lib/python2.7/test/test_posix.pyttest_fdopen_directoryÅstsunoscCsBtjtjtjƒ}|jttj|dƒtj |ƒdS(Ntw( R RRRRjR%R9RRkR(RR^((s%/usr/lib/python2.7/test/test_posix.pyt#test_fdopen_keeps_fd_open_on_errorsÑstO_EXLOCKstest needs posix.O_EXLOCKcCsÖtjtjtjtjBtjBƒ}|jttjtjtjtjBtj Bƒtj |ƒt t dƒrÒtjtjtjtj BtjBƒ}|jttjtjtjtjBtj Bƒtj |ƒndS(NtO_SHLOCK(R RRRtO_WRONLYR{tO_CREATR%R9t O_NONBLOCKRthasattrRR|(RR^((s%/usr/lib/python2.7/test/test_posix.pyt test_osexlockÙs   R|stest needs posix.O_SHLOCKcCsÜtjtjtjtjBtjBƒ}tjtjtjtjBtjBƒ}tj|ƒtj|ƒtt dƒrØtjtjtjtjBtjBƒ}|j t tjtjtj tj BtjBƒtj|ƒndS(NR{(R RRRR}R|R~RR€RR%R9RjR{R(Rtfd1tfd2R^((s%/usr/lib/python2.7/test/test_posix.pyt test_osshlockés     tfstatstest needs posix.fstat()cCsAttjƒ}z |jtj|jƒƒƒWd|jƒXdS(N(RRRRPRR…RTR(RR ((s%/usr/lib/python2.7/test/test_posix.pyt test_fstatús tstatstest needs posix.stat()cCs|jtjtjƒƒdS(N(RPRR‡RR(R((s%/usr/lib/python2.7/test/test_posix.pyt test_statsc s‡‡‡fd†}tjƒ}tjƒ}|ˆ||ƒ|||ƒ|ˆd|ƒ|||ƒ|ˆ|dƒ|||ƒ|dkrðd }|ˆ||ƒ|||ƒ|ˆddƒ|||ƒ|ˆ||ƒ|||ƒn«tjƒd krtjdƒ‚n‡ˆjt|ˆddƒ|||ƒˆjt|ˆddƒ|||ƒdtj ƒkr›ˆjt|ˆddƒ|||ƒnxlt t fD]^}ˆjt |ˆ||ƒ|ƒ|||ƒˆjt |ˆ|||ƒƒ|||ƒq¨Wd S( s/Common code for chown, fchown and lchown tests.csEˆdk rAˆˆƒ}ˆj|j|ƒˆj|j|ƒndS(N(R$R,tst_uidtst_gid(tuidtgidR‡(t first_paramRt stat_func(s%/usr/lib/python2.7/test/test_posix.pyt check_stat s  iÿÿÿÿiiisHP-UXtSunOSs1Skipping because of non-standard chown() behaviorNl(sHP-UXR( R RRtplatformtsystemRHRIR%R9RtstrtfloatR&( Rt chown_funcRRŽRR‹RŒt big_valuett((RRRŽs%/usr/lib/python2.7/test/test_posix.pyt_test_all_chown_commons>           tchownstest needs os.chown()cCsntjtjƒ|jttjtjddƒttjdƒj ƒ|j tjtjt tddƒƒdS(NiÿÿÿÿRyR‡( R R RRR%R9RR™RRR˜R#R$(R((s%/usr/lib/python2.7/test/test_posix.pyt test_chownCs tfchownstest needs os.fchown()cCsftjtjƒttjdƒ}z2|jƒ}|jtj|t tddƒƒWd|j ƒXdS(NRyR…( R R RRRRTR˜RR›R#R$R(Rt test_fileR^((s%/usr/lib/python2.7/test/test_posix.pyt test_fchownNs tlchownstest needs os.lchown()cCsLtjtjƒtjttjƒ|jtjtjt tddƒƒdS(Ntlstat( R R RRtsymlinkt_DUMMY_SYMLINKR˜RRžR#R$(R((s%/usr/lib/python2.7/test/test_posix.pyt test_lchown[stchdirstest needs posix.chdir()cCs-tjtjƒ|jttjtjƒdS(N(RR£R RQR%R9RR(R((s%/usr/lib/python2.7/test/test_posix.pyt test_chdircstlsdirstest needs posix.lsdir()cCs#|jtjtjtjƒƒdS(N(tassertInRRRR¥R RQ(R((s%/usr/lib/python2.7/test/test_posix.pyt test_lsdirhstaccessstest needs posix.access()cCs#|jtjtjtjƒƒdS(N(RPRR¨RRR tR_OK(R((s%/usr/lib/python2.7/test/test_posix.pyt test_accesslstumaskstest needs posix.umask()cCs0tjdƒ}|j|tƒtj|ƒdS(Ni(RR«R\R](Rtold_mask((s%/usr/lib/python2.7/test/test_posix.pyt test_umaskpststrerrorstest needs posix.strerror()cCs|jtjdƒƒdS(Ni(RPRR®(R((s%/usr/lib/python2.7/test/test_posix.pyt test_strerrorvstpipestest needs posix.pipe()cCs0tjƒ\}}tj|ƒtj|ƒdS(N(RR°R R(Rtreadertwriter((s%/usr/lib/python2.7/test/test_posix.pyt test_pipe{s ttempnamstest needs posix.tempnam()cCsrtjƒ`tjddtƒ|jtjƒƒ|jtjtjƒƒ|jtjtjdƒƒWdQXdS(NRR´tblah( RR R!R"RPRR´R RQ(R((s%/usr/lib/python2.7/test/test_posix.pyt test_tempnams  ttmpfilestest needs posix.tmpfile()cCs@tjƒ.tjddtƒtjƒ}|jƒWdQXdS(NRR·(RR R!R"RR·R(RR ((s%/usr/lib/python2.7/test/test_posix.pyt test_tmpfileŠs  tutimestest needs posix.utime()cCsÁtjƒ}tjtjdƒ|jttjtjdƒ|jttjtj|dfƒ|jttjtjd|fƒtjtjt|ƒt|ƒfƒtjtj||fƒdS(N(NN( ttimeRR¹RRR$R%R&R](Rtnow((s%/usr/lib/python2.7/test/test_posix.pyt test_utime’s ""%c Cs tj|ƒ}|jt|dƒƒy|||jtjBƒWn>tk r€}|jtjkrj‚nd}|j |ƒnXzotj|ƒ}|j |jtjB|jƒyt |dƒ}Wn)t k rî}|j |jtj ƒnXWdtj||jƒXdS(Ntst_flagss2chflag UF_IMMUTABLE not supported by underlying fssw+(R R‡RPR€R½t UF_IMMUTABLER9RJt EOPNOTSUPPRrR,RRsRKRtchflags( Rt chflags_funct target_filetstterrtmsgtnew_stR^RM((s%/usr/lib/python2.7/test/test_posix.pyt_test_chflags_regular_fileœs"RÀstest needs os.chflags()cCs|jtjtjƒdS(N(RÇRRÀRR(R((s%/usr/lib/python2.7/test/test_posix.pyt test_chflags³stlchflagsstest needs os.lchflags()cCs|jtjtjƒdS(N(RÇRRÉRR(R((s%/usr/lib/python2.7/test/test_posix.pyttest_lchflags_regular_file·scCs,tjtjƒ}|jt|dƒƒtjtjtƒ|jj tƒtj tƒ}yt j t|j tjBƒWn>tk r¸}|jtjkr¢‚nd}|j|ƒnXzXtjtjƒ}tj tƒ}|j|j |j ƒ|j|j tjB|j ƒWdt j t|j ƒXdS(NR½s2chflag UF_IMMUTABLE not supported by underlying fs(R R‡RRRPR€R R¡RtappendRŸRRÉR½R¾R9RJR¿RrR,(Rt testfn_sttdummy_symlink_stRÄRÅt new_testfn_sttnew_dummy_symlink_st((s%/usr/lib/python2.7/test/test_posix.pyttest_lchflags_symlink»s( Rstest needs posix.getcwd()cs¥d}tjƒ}tjjtjƒd}ytj|ƒtj|ƒWnˆjdƒnXz#d‡‡fd†‰ˆ|ƒWdtj|ƒt j |ƒXdS(Ns8getcwd-test-directory-0123456789abcdef-01234567890abcdefs.getcwds#cannot create directory for testingicsytj|ƒWnˆjdƒnXtj|ƒz­y8tjƒ|dkroˆ||t|ƒdƒnWnntk rà}tj}dt j kpµdt j kpµdt j k}|rÊtj }nˆj |j|ƒnXWdtjdƒtj |ƒXdS(Ns?mkdir cannot create directory sufficiently deep for getcwd testiiRxtnetbsdtopenbsds..(R tmkdirRrR£RR-R9RJt ENAMETOOLONGtsysR‘tERANGER,trmdir(tdirnametcurrent_path_lengthRMtexpected_errnotquirky_platform(t_create_and_do_getcwdR(s%/usr/lib/python2.7/test/test_posix.pyRÜçs(   "   ( R RtpathtabspathRRRÓR£Rrtshutiltrmtree(RRØRQt base_path((RÜRs%/usr/lib/python2.7/test/test_posix.pyttest_getcwd_long_pathnamesÙs   Rstest needs os.getegid()cCstjdƒ%}|jƒjƒ}|jƒ}WdQX|dksI| r[tjdƒ‚ntj dkrÌddl }|j dƒpˆd}t d„|j dƒd d !DƒƒdkrÌtjd ƒ‚qÌn|jtg|j ƒD]}t|ƒ^qâƒttjƒtjƒgƒƒdS(Nsid -G 2>/dev/nullsneed working 'id -G'tdarwiniÿÿÿÿtMACOSX_DEPLOYMENT_TARGETs10.0css|]}t|ƒVqdS(N(R](t.0tn((s%/usr/lib/python2.7/test/test_posix.pys sRpiii is$getgroups(2) is broken prior to 10.6(i i(R tpopentreadtstripRR$RHRIRÕR‘t sysconfigtget_config_varttupletsplitR,tsetR]RRR(RtidgtgroupstretRêtdttx((s%/usr/lib/python2.7/test/test_posix.pyttest_getgroups s ,((5t__name__t __module__R RR*RHt skipUnlessR€RR1R4R8R;R>R@RNRRRURZR_ReRiRmRoRwRÕR‘t startswithRzRR„R†RˆR˜RšRR¢R¤R§RªR­R¯R³R¶R¸R¼RÇRÈRÊRÐRâR Rô(((s%/usr/lib/python2.7/test/test_posix.pyRsˆ        ;$ $ $$$$$$$ $$$0tPosixGroupsTestercBsbeZd„Zd„Zejeedƒdƒd„ƒZejeedƒdƒd„ƒZ RS(cCsytjƒdkr$tjdƒ‚nttdƒsEtjdƒ‚ntjdkrftjdƒ‚ntjƒ|_dS(Nisnot enough privilegesRsneed posix.getgroupsRãsgetgroups(2) is broken on OSX( RRRHRIR€RÕR‘Rt saved_groups(R((s%/usr/lib/python2.7/test/test_posix.pyR $scCsgttdƒr"tj|jƒnAttdƒrctjtjƒƒj}tj||jdƒndS(Nt setgroupsRAi( R€RRûRúRDRERRFRA(RR(((s%/usr/lib/python2.7/test/test_posix.pyR-s RAstest needs posix.initgroups()cCs^t|jpdgƒd}tjtjƒƒj}tj||ƒ|j|tj ƒƒdS(Nii( tmaxRúRDRERRRFRAR¦R(RtgR(((s%/usr/lib/python2.7/test/test_posix.pyRN4sRûstest needs posix.setgroups()cCsGx@dgtdƒgD])}tj|ƒ|j|tjƒƒqWdS(Nii(trangeRRûtassertListEqualR(RRð((s%/usr/lib/python2.7/test/test_posix.pyttest_setgroups>s ( RõRöR RRHR÷R€RRNR(((s%/usr/lib/python2.7/test/test_posix.pyRù"s   cCstjttƒdS(N(Rt run_unittestRRù(((s%/usr/lib/python2.7/test/test_posix.pyt test_mainFst__main__(t__doc__RWRt import_moduleRRJRÕRºR R‘RDRßR‡ttempfileRHRRÝtjoint gettempdirRR¡R!tRuntimeWarningtTestCaseRRùRRõ(((s%/usr/lib/python2.7/test/test_posix.pyts2             ÿÿ $