ó {G_Tc@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 PosixTestercBsaeZd„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'ƒoGejjd*ƒ d(ƒd+„ƒZejeed,ƒd-ƒd.„ƒZejeed/ƒd0ƒd1„ƒZejeed2ƒd3ƒd4„ƒZejeed5ƒd6ƒd7„ƒZd8„Z ejeed9ƒd:ƒd;„ƒZ!ejeed<ƒd=ƒd>„ƒZ"ejeed?ƒd@ƒdA„ƒZ#ejeedBƒdCƒdD„ƒZ$ejeedEƒdFƒdG„ƒZ%ejeedHƒdIƒdJ„ƒZ&ejeedKƒdLƒdM„ƒZ'ejeedNƒdOƒdP„ƒZ(ejeedQƒdRƒdS„ƒZ)ejeedTƒdUƒdV„ƒZ*ejeedWƒdXƒdY„ƒZ+ejeedZƒd[ƒd\„ƒZ,d]„Z-ejeed^ƒd_ƒd`„ƒZ.ejeedaƒdbƒdc„ƒZ/ejeedaƒdbƒdd„ƒZ0ejeedeƒdfƒdg„ƒZ1ejee2dhƒdiƒdj„ƒZ3RS(kcCs/ttjdƒ}|jƒtjg|_dS(Nsw+(topenRtTESTFNtclosetteardown_files(tselftfp((s+/usr/local/lib/python2.7/test/test_posix.pytsetUps cCs%x|jD]}tj|ƒq WdS(N(Rtostunlink(Rt teardown_file((s+/usr/local/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/local/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/local/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/local/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/local/lib/python2.7/test/test_posix.pyttest_setresuidHs cCsLtjƒ}d|krH|ddddf}|jttj|ŒndS(Niiiÿÿÿÿ(RR+R%tOSErrorR5(RR7t new_user_ids((s+/usr/local/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/local/lib/python2.7/test/test_posix.pyttest_setresgidYs cCsLtjƒ}d|krH|ddddf}|jttj|ŒndS(Niiiÿÿÿÿ(RR2R%R9R<(RR=t new_group_ids((s+/usr/local/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/local/lib/python2.7/test/test_posix.pyttest_initgroupsjs tstatvfsstest needs posix.statvfs()cCs|jtjtjƒƒdS(N(t assertTrueRROR tcurdir(R((s+/usr/local/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/local/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/local/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/local/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/local/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/local/lib/python2.7/test/test_posix.pyt test_dup2®s   cGs8tjtjtjƒ}tj||Œ}|jƒdS(N(R RRRtO_RDONLYRtfdopenR(RtargsR^Rh((s+/usr/local/lib/python2.7/test/test_posix.pyt fdopen_helper¹sRkstest needs posix.fdopen()cCs+|jƒ|jdƒ|jddƒdS(Ntrid(Rm(R((s+/usr/local/lib/python2.7/test/test_posix.pyt test_fdopen¾s  tsunoscCsBtjtjtjƒ}|jttj|dƒtj |ƒdS(Ntw( R RRRRjR%R9RRkR(RR^((s+/usr/local/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_WRONLYRstO_CREATR%R9t O_NONBLOCKRthasattrRRt(RR^((s+/usr/local/lib/python2.7/test/test_posix.pyt test_osexlockÍs   Rtstest needs posix.O_SHLOCKcCsÜtjtjtjtjBtjBƒ}tjtjtjtjBtjBƒ}tj|ƒtj|ƒtt dƒrØtjtjtjtjBtjBƒ}|j t tjtjtj tj BtjBƒtj|ƒndS(NRs(R RRRRuRtRvRRxRR%R9RjRsRw(Rtfd1tfd2R^((s+/usr/local/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/local/lib/python2.7/test/test_posix.pyt test_fstatîs tstatstest needs posix.stat()cCs|jtjtjƒƒdS(N(RPRRRR(R((s+/usr/local/lib/python2.7/test/test_posix.pyt test_stat÷sc 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/local/lib/python2.7/test/test_posix.pyt check_statþs  iÿÿÿÿiiisHP-UXtSunOSs1Skipping because of non-standard chown() behaviorNI€(sHP-UXRˆ( R RRtplatformtsystemRHRIR%R9RtstrtfloatR&( Rt chown_funcR…R†R‡RƒR„t big_valuett((R…RR†s+/usr/local/lib/python2.7/test/test_posix.pyt_test_all_chown_commonüs>           tchownstest needs os.chown()cCsntjtjƒ|jttjtjddƒttjdƒj ƒ|j tjtjt tddƒƒdS(NiÿÿÿÿRqR( R R RRR%R9RR‘RRRR#R$(R((s+/usr/local/lib/python2.7/test/test_posix.pyt test_chown7s tfchownstest needs os.fchown()cCsftjtjƒttjdƒ}z2|jƒ}|jtj|t tddƒƒWd|j ƒXdS(NRqR}( R R RRRRTRRR“R#R$R(Rt test_fileR^((s+/usr/local/lib/python2.7/test/test_posix.pyt test_fchownBs tlchownstest needs os.lchown()cCsLtjtjƒtjttjƒ|jtjtjt tddƒƒdS(Ntlstat( R R RRtsymlinkt_DUMMY_SYMLINKRRR–R#R$(R((s+/usr/local/lib/python2.7/test/test_posix.pyt test_lchownOstchdirstest needs posix.chdir()cCs-tjtjƒ|jttjtjƒdS(N(RR›R RQR%R9RR(R((s+/usr/local/lib/python2.7/test/test_posix.pyt test_chdirWstlsdirstest needs posix.lsdir()cCs#|jtjtjtjƒƒdS(N(tassertInRRRRR RQ(R((s+/usr/local/lib/python2.7/test/test_posix.pyt test_lsdir\staccessstest needs posix.access()cCs#|jtjtjtjƒƒdS(N(RPRR RRR tR_OK(R((s+/usr/local/lib/python2.7/test/test_posix.pyt test_access`stumaskstest needs posix.umask()cCs0tjdƒ}|j|tƒtj|ƒdS(Ni(RR£R\R](Rtold_mask((s+/usr/local/lib/python2.7/test/test_posix.pyt test_umaskdststrerrorstest needs posix.strerror()cCs|jtjdƒƒdS(Ni(RPRR¦(R((s+/usr/local/lib/python2.7/test/test_posix.pyt test_strerrorjstpipestest needs posix.pipe()cCs0tjƒ\}}tj|ƒtj|ƒdS(N(RR¨R R(Rtreadertwriter((s+/usr/local/lib/python2.7/test/test_posix.pyt test_pipeos ttempnamstest needs posix.tempnam()cCsrtjƒ`tjddtƒ|jtjƒƒ|jtjtjƒƒ|jtjtjdƒƒWdQXdS(NRR¬tblah( RR R!R"RPRR¬R RQ(R((s+/usr/local/lib/python2.7/test/test_posix.pyt test_tempnamus  ttmpfilestest needs posix.tmpfile()cCs@tjƒ.tjddtƒtjƒ}|jƒWdQXdS(NRR¯(RR R!R"RR¯R(RR ((s+/usr/local/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/local/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 RRPRxRµt UF_IMMUTABLER9RJt EOPNOTSUPPtskipTestR,RtIOErrorRKRtchflags( Rt chflags_funct target_filetstterrtmsgtnew_stR^RM((s+/usr/local/lib/python2.7/test/test_posix.pyt_test_chflags_regular_files"Rºstest needs os.chflags()cCs|jtjtjƒdS(N(RÁRRºRR(R((s+/usr/local/lib/python2.7/test/test_posix.pyt test_chflags§stlchflagsstest needs os.lchflags()cCs|jtjtjƒdS(N(RÁRRÃRR(R((s+/usr/local/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 RRRRPRxR˜R™RtappendR—RRÃRµR¶R9RJR·R¸R,(Rt testfn_sttdummy_symlink_stR¾R¿t new_testfn_sttnew_dummy_symlink_st((s+/usr/local/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 testiiRptnetbsdtopenbsds..(R tmkdirR¸R›RR-R9RJt ENAMETOOLONGtsysR‰tERANGER,trmdir(tdirnametcurrent_path_lengthRMtexpected_errnotquirky_platform(t_create_and_do_getcwdR(s+/usr/local/lib/python2.7/test/test_posix.pyRÖÛs(   "   ( R RtpathtabspathRRRÍR›R¸tshutiltrmtree(RRÒRQt base_path((RÖRs+/usr/local/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/local/lib/python2.7/test/test_posix.pys st.iii 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/local/lib/python2.7/test/test_posix.pyttest_getgroupsþs ,((4t__name__t __module__R RR*RHt skipUnlessRxRR1R4R8R;R>R@RNRRRURZR_ReRiRmRoRÏR‰t startswithRrRyR|R~R€RR’R•RšRœRŸR¢R¥R§R«R®R°R´RÁRÂRÄRÊRÜR Rï(((s+/usr/local/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( RRRHRIRxRÏR‰Rt saved_groups(R((s+/usr/local/lib/python2.7/test/test_posix.pyR scCsgttdƒr"tj|jƒnAttdƒrctjtjƒƒj}tj||jdƒndS(Nt setgroupsRAi( RxRRöRõRDRERRFRA(RR(((s+/usr/local/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/local/lib/python2.7/test/test_posix.pyRN(sRöstest needs posix.setgroups()cCsGx@dgtdƒgD])}tj|ƒ|j|tjƒƒqWdS(Nii(trangeRRötassertListEqualR(RRë((s+/usr/local/lib/python2.7/test/test_posix.pyttest_setgroups2s ( RðRñR RRHRòRxRRNRû(((s+/usr/local/lib/python2.7/test/test_posix.pyRôs   cCstjttƒdS(N(Rt run_unittestRRô(((s+/usr/local/lib/python2.7/test/test_posix.pyt test_main:st__main__(t__doc__RWRt import_moduleRRJRÏR²R R‰RDRÙRttempfileRHRR×tjoint gettempdirRR™R!tRuntimeWarningtTestCaseRRôRýRð(((s+/usr/local/lib/python2.7/test/test_posix.pyts0             ÿü$