ó {G_Tc@s°ddlZddlZddlZddlZddlZddlZddlZddlZddlm Z e a dfd„ƒYZ dfd„ƒYZ d„Zd„Zd „Zd fd „ƒYZd fd „ƒYZdejfd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZddlmZdejfd„ƒYZdejfd„ƒYZdZied6Zd„Zedkr¬eƒndS(iÿÿÿÿN(t test_supporttCcBseZd„ZRS(cCsdS(N((tself((s-/usr/local/lib/python2.7/test/test_weakref.pytmethods(t__name__t __module__R(((s-/usr/local/lib/python2.7/test/test_weakref.pyRstCallablecBseZdZd„ZRS(cCs ||_dS(N(tbar(Rtx((s-/usr/local/lib/python2.7/test/test_weakref.pyt__call__sN(RRtNoneRR (((s-/usr/local/lib/python2.7/test/test_weakref.pyRscCs d„}|S(NcSsdS(N((((s-/usr/local/lib/python2.7/test/test_weakref.pytfs((R ((s-/usr/local/lib/python2.7/test/test_weakref.pytcreate_functions cCs tƒjS(N(RR(((s-/usr/local/lib/python2.7/test/test_weakref.pytcreate_bound_methodscCstjS(N(RR(((s-/usr/local/lib/python2.7/test/test_weakref.pytcreate_unbound_method"stObjectcBs5eZd„Zd„Zd„Zd„Zd„ZRS(cCs ||_dS(N(targ(RR((s-/usr/local/lib/python2.7/test/test_weakref.pyt__init__'scCs d|jS(Ns (R(R((s-/usr/local/lib/python2.7/test/test_weakref.pyt__repr__)scCs#t|tƒr|j|jkStS(N(t isinstanceRRtNotImplemented(Rtother((s-/usr/local/lib/python2.7/test/test_weakref.pyt__eq__+scCs#t|tƒr|j|jkStS(N(RRRR(RR((s-/usr/local/lib/python2.7/test/test_weakref.pyt__ne__/scCs t|jƒS(N(thashR(R((s-/usr/local/lib/python2.7/test/test_weakref.pyt__hash__3s(RRRRRRR(((s-/usr/local/lib/python2.7/test/test_weakref.pyR&s     tRefCyclecBseZd„ZRS(cCs ||_dS(N(tcycle(R((s-/usr/local/lib/python2.7/test/test_weakref.pyR7s(RRR(((s-/usr/local/lib/python2.7/test/test_weakref.pyR6stTestBasecBseZd„Zd„ZRS(cCs d|_dS(Ni(tcbcalled(R((s-/usr/local/lib/python2.7/test/test_weakref.pytsetUp=scCs|jd7_dS(Ni(R(Rtref((s-/usr/local/lib/python2.7/test/test_weakref.pytcallback@s(RRRR (((s-/usr/local/lib/python2.7/test/test_weakref.pyR;s tReferencesTestCasecBspeZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z!d „Z"d!„Z#d"„Z$d#„Z%d$„Z&d%„Z'd&„Z(d'„Z)RS((cCsg|jtƒ|jtƒ|jtƒ|jtƒtƒ}tj|ƒ}t|ƒ~t|ƒdS(N(tcheck_basic_refRR R RtweakrefRtrepr(Rtotwr((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_basic_refFs      cCs8|jtƒ|jtƒ|jtƒ|jtƒdS(N(tcheck_basic_callbackRR R R(R((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_basic_callbackUs   cCsvtƒ}tj||jƒ}tj||jƒ}~|j|ƒdƒ|j|ƒdƒ|j|jddƒdS(Ns$expected reference to be invalidatedis-callback not called the right number of times(RR#RR t assertIsNonet assertEqualR(RR%tref1tref2((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_multiple_callbacks[s cCsC|d„}tƒ}tj||ƒ|_tj||ƒ}~dS(NcSs|jƒdS(N(R(tobjectR((s-/usr/local/lib/python2.7/test/test_weakref.pyR ps(RR#R(RR tcR,((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_multiple_selfref_callbackses  cCs­tƒ}d|_tj||jƒ}tj||jƒ}~d„}|jtj||ƒ|jtj||ƒ|jtjttjtƒƒƒ|j|j dƒdS(NicSs |jdS(N(R(tproxy((s-/usr/local/lib/python2.7/test/test_weakref.pytcheck~si( RRR#R2R t assertRaisestReferenceErrortboolR+R(RR%R,R-R3((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_proxy_refws   "cCsK|ƒ}tj|ƒ}|j|ƒdƒ|ƒ}|j||dƒdS(Ns,weak reference to live object should be lives-() should return original object if live(R#RtassertIsNotNonetassertIs(RtfactoryR%Rto2((s-/usr/local/lib/python2.7/test/test_weakref.pyR"†s    cCsWd|_|ƒ}tj||jƒ}~|j|jddƒ|j|ƒdƒdS(Niis(callback did not properly set 'cbcalled's3ref2 should be dead after deleting object reference(RR#RR R+R*(RR:R%R((s-/usr/local/lib/python2.7/test/test_weakref.pyR(s   cCsÑtƒ}tj|ƒ}tj|ƒ}tj|ƒ}|j||dƒtƒ}tj|ƒ}tj|ƒ}tj|ƒ}|j||dƒ|jtj|ƒddƒ~|jtj|ƒddƒdS(Ns1reference object w/out callback should be re-usediswrong weak ref count for objectis4wrong weak ref count for object after deleting proxy(RR#RR2R9R+tgetweakrefcount(RR%R,R2R-((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_ref_reuse™s"    cCsMtƒ}tj|ƒ}tj|ƒ}tj|ƒ}|j||dƒdS(Ns4proxy object w/out callback should have been re-used(RR#R2RR9(RR%tproxy1Rtproxy2((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_proxy_reuse¯s   c CsÚtƒ}|j|tj|ƒƒtjƒ}tj|ƒ}|j|dƒ|jdƒ|jt|ƒdƒ|j |dƒt j ƒddg|(WdQX|jt|ƒdƒ|jt|ƒdƒ|j d|dƒd|d<|j|ddƒ|j|ddƒtj|ƒ}tj|ƒ}|j||ƒtjt d ƒƒ}tj|ƒ}t j ƒe|j||ƒ|j|d|dƒ|j|d |d ƒ|j|dd!|dd!ƒWdQXdS( Ns(proxy for empty UserList should be falsei is+proxy for non-empty UserList should be trueiis,proxy didn't support __contains__() properlyii (Rt check_proxyR#R2tUserListt assertFalsetappendR+tlent assertTrueRtcheck_py3k_warningstassertIntrange(RR%tLtptL2tp2tL3tp3((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_basic_proxy·s4      cCsadtfd„ƒY}|ƒ}|jdttj|ƒƒƒ|jttj|ƒƒdƒdS(NRcBseZd„Zd„ZRS(cSsdS(Ntstring((R((s-/usr/local/lib/python2.7/test/test_weakref.pyt__str__ØscSsdS(Nuunicode((R((s-/usr/local/lib/python2.7/test/test_weakref.pyt __unicode__Ús(RRRRRS(((s-/usr/local/lib/python2.7/test/test_weakref.pyR×s RSuunicode(R/RHtdirR#R2R+tunicode(RRtinstance((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_proxy_unicodeÕs cCsHddd„ƒY}|ƒ}tj|ƒ}|jtj|ƒdƒdS(NRcBseZd„ZRS(cSsdS(Ni ((R((s-/usr/local/lib/python2.7/test/test_weakref.pyt __index__âs(RRRX(((s-/usr/local/lib/python2.7/test/test_weakref.pyRási ((R#R2R+toperatortindex(RRR%RK((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_proxy_indexàs cCs]ddd„ƒY}|ƒ}tj|ƒ}|j|ddƒ|d}|j|dƒdS(NRcBseZd„Zd„ZRS(cSsdS(Ni*((RR((s-/usr/local/lib/python2.7/test/test_weakref.pyt __floordiv__êscSsdS(Ni((RR((s-/usr/local/lib/python2.7/test/test_weakref.pyt __ifloordiv__ìs(RRR\R](((s-/usr/local/lib/python2.7/test/test_weakref.pyRés ii*i((R#R2R+(RRR%RK((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_proxy_divès   cCs|jtjƒdS(N(tcheck_shared_without_callbackR#R(R((s-/usr/local/lib/python2.7/test/test_weakref.pyt test_shared_ref_without_callbacküscCs|jtjƒdS(N(R_R#R2(R((s-/usr/local/lib/python2.7/test/test_weakref.pyt"test_shared_proxy_without_callbackÿscCsÚtdƒ}||dƒ}||dƒ}|j||dƒ~~||ƒ}||dƒ}|j||dƒ~~||ƒ}||ƒ}|j||dƒ~~||dƒ}||ƒ}|j||dƒdS(Nis%both callbacks were None in the C APIs&callbacks were NULL, None in the C APIs%both callbacks were NULL in the C APIs&callbacks were None, NULL in the C API(RR R9(RtmakerefR%tp1RM((s-/usr/local/lib/python2.7/test/test_weakref.pyR_s      cCs´tƒ}tj|ƒ}|j||ƒ|jt|ƒtjdƒ|dƒ|j|jddƒ|ddƒ|j|jddƒ|j t |ƒ|j t |dddƒdS( Nsproxy is not of callable types twinkies!s1call through proxy not passed through to originalRsSplat.iii( RR#R2RAR9ttypetCallableProxyTypeR+RR4t TypeError(RR%R,((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_callable_proxys   cCs¾d|_|j|jddƒd|_|j|jddƒ|`|jt|dƒdƒd|_|j|jddƒd|_|j|jddƒ|`|jt|dƒd ƒdS( Nis)proxy does not reflect attribute additionis-proxy does not reflect attribute modificationtfoos(proxy does not reflect attribute removals4object does not reflect attribute addition via proxys8object does not reflect attribute modification via proxys3object does not reflect attribute removal via proxy(RhR+RCthasattr(RR%R2((s-/usr/local/lib/python2.7/test/test_weakref.pyRA)s$    cCsIddd„ƒY}|ƒ}tj|ƒ}|d=|j|jdƒdS(NtFoocBseZdZd„ZRS(cSs ||_dS(N(tresult(Rtaccessor((s-/usr/local/lib/python2.7/test/test_weakref.pyt __delitem__BsN(RRR RkRm(((s-/usr/local/lib/python2.7/test/test_weakref.pyRj@si((R#R2R+Rk(RRjtgR ((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_proxy_deletion>s  cCsHdtfd„ƒY}|ƒ}|jttj|ƒƒt|ƒƒdS(NtListcBseZRS((RR(((s-/usr/local/lib/python2.7/test/test_weakref.pyRpKs(tlistR+R6R#R2(RRptlyst((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_proxy_boolIs cCsÑtƒ}tj|ƒ}tj||jƒ}|jtj|ƒddƒtj|ƒ}tj||jƒ}|jtj|ƒddƒ~~~~|jtj|ƒddƒ|jtjdƒddƒdS(Nis*got wrong number of weak reference objectsiisAweak reference objects not unlinked from referent when discarded.is2got wrong number of weak reference objects for int(RR#RR R+R<R2(RR%R,R-R>R?((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_getweakrefcountOs  cCsétƒ}tj||jƒ}tj||jƒ}~|jtj|ƒ|gdƒtƒ}tj||jƒ}tj||jƒ}~|jtj|ƒ|gdƒ~|jtj|ƒgdƒ|jtjdƒgdƒdS(Nslist of refs does not matchslist of refs not clearedis#list of refs does not match for int(RR#RR R+t getweakrefs(RR%R,R-((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_getweakrefsds"  cCs]dtfd„ƒY}|dƒ}tj|ƒ}|j|ddƒ|jd|dƒdS(NtFcBseZRS((RR(((s-/usr/local/lib/python2.7/test/test_weakref.pyRw|sg@gð?g@(tfloatR#R2R+(RRwR RK((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_newstyle_number_ops{s  csœdtfd„ƒY‰i‰‡fd†‰‡‡‡fd†}y |ƒWnˆk r^nX|jdƒy |ƒWnˆk rŠnX|jdƒdS(Nt BogusErrorcBseZRS((RR(((s-/usr/local/lib/python2.7/test/test_weakref.pyRz†scs ˆ|=dS(N((tk(tdata(s-/usr/local/lib/python2.7/test/test_weakref.pytremove‰scs)d„}dˆtj|ˆƒ<ˆ‚dS(NcSsdS(N(((((s-/usr/local/lib/python2.7/test/test_weakref.pytŒs(R R#R(R (RzR|R}(s-/usr/local/lib/python2.7/test/test_weakref.pyt encapsulate‹s sexception not properly restored(t Exceptiontfail(RR((RzR|R}s-/usr/local/lib/python2.7/test/test_weakref.pyttest_callbacks_protectedƒs     cs›ddl‰dtfd„ƒY}|ƒ}tj|‡fd†ƒ}~~|ƒ}|ƒ|_tj|j‡fd†ƒ}|ƒ}||_~~dS(NiÿÿÿÿRcBseZRS((RR(((s-/usr/local/lib/python2.7/test/test_weakref.pyR©scs ˆjƒS(N(tcollect(tignore(tgc(s-/usr/local/lib/python2.7/test/test_weakref.pyR~­scs ˆjƒS(N(Rƒ(R„(R…(s-/usr/local/lib/python2.7/test/test_weakref.pyR~µs(R…R/R#Rtitc1(RRR0R&R‡tc2((R…s-/usr/local/lib/python2.7/test/test_weakref.pyttest_sf_bug_840829œs       cCsyddl}dtfd„ƒY}dtfd„ƒY}|ƒ}||_tj||jƒ|_~~~|jƒdS(NiÿÿÿÿtJcBseZRS((RR(((s-/usr/local/lib/python2.7/test/test_weakref.pyRŠÇstIIcBseZd„ZRS(cSs |jdS(N(RŠ(RR„((s-/usr/local/lib/python2.7/test/test_weakref.pyt acallbackËs(RRRŒ(((s-/usr/local/lib/python2.7/test/test_weakref.pyR‹Ês(R…R/RŠR#RRŒR&Rƒ(RR…RŠR‹tI((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_callback_in_cycle_1Äs    cCsvddl}dtfd„ƒY}ddd„ƒY}|ƒ}||_tj||jƒ|_~~~|jƒdS(NiÿÿÿÿRŠcBseZRS((RR(((s-/usr/local/lib/python2.7/test/test_weakref.pyRŠûsR‹cBseZd„ZRS(cSs |jdS(N(RŠ(RR„((s-/usr/local/lib/python2.7/test/test_weakref.pyRŒÿs(RRRŒ(((s-/usr/local/lib/python2.7/test/test_weakref.pyR‹þs((R…R/RŠR#RRŒR&Rƒ(RR…RŠR‹R((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_callback_in_cycle_2ìs    cCspddl}ddd„ƒY}|ƒ|ƒ}}||_||_tj||jƒ|_~~|jƒdS(NiÿÿÿÿRcBseZd„ZRS(cSs|j|j|jdS(N(tmeR‡R&(RR„((s-/usr/local/lib/python2.7/test/test_weakref.pytcbs(RRR‘(((s-/usr/local/lib/python2.7/test/test_weakref.pyRs((R…RR‡R#RR‘R&Rƒ(RR…RR‡Rˆ((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_callback_in_cycle_3 s   cCsŒddl}dtfd„ƒY}ddd„ƒY}|ƒ|ƒ}}||_||_tj||jƒ|_~~~~|jƒdS(NiÿÿÿÿRcBseZd„ZRS(cSs|j|j|jdS(N(RR‡R&(RR„((s-/usr/local/lib/python2.7/test/test_weakref.pyR‘,s(RRR‘(((s-/usr/local/lib/python2.7/test/test_weakref.pyR+stDcBseZRS((RR(((s-/usr/local/lib/python2.7/test/test_weakref.pyR“1s(( R…R/RR‡R#RR‘R&Rƒ(RR…RR“R‡Rˆ((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_callback_in_cycle_4!s    csddl}g‰dtf‡fd†ƒY}|dƒ|dƒ}}||_||_tj||jƒ|_tj||jƒ|_‡fd†}tj||ƒ}~~~|jˆgƒ|jƒ|jˆdgƒ|j|ƒdƒˆ2|jƒ|jˆgƒdS(NiÿÿÿÿRcs eZd„Z‡fd†ZRS(cSs ||_dS(N(t attribute(Rtvalue((s-/usr/local/lib/python2.7/test/test_weakref.pyRKscsˆj|jƒdS(N(RDR0(RR„(talist(s-/usr/local/lib/python2.7/test/test_weakref.pyRŒNs(RRRRŒ((R—(s-/usr/local/lib/python2.7/test/test_weakref.pyRJs iicsˆjdƒdS(Ns C went away(RD(R„(R—(s-/usr/local/lib/python2.7/test/test_weakref.pyt C_went_awayWss C went away( R…R/R0R#RRŒR&R+RƒR (RR…RR‡RˆR˜R&((R—s-/usr/local/lib/python2.7/test/test_weakref.pyt#test_callback_in_cycle_resurrection=s$      cs+ddl}g‰‡fd†}dtf‡fd†ƒY}|ƒ|ƒ}}||_||_|j}tj||ƒ|_tj||jƒ|_tj||ƒ}|j|ƒ|ƒ~~~~|jˆgƒ|j ƒ|jˆdgƒ|j|ƒdƒˆ2|j ƒ|jˆgƒdS(NiÿÿÿÿcsˆjdƒdS(Nssafe_callback called(RD(R„(R—(s-/usr/local/lib/python2.7/test/test_weakref.pyt safe_callbackpsRcseZ‡fd†ZRS(csˆjdƒdS(Ns cb called(RD(RR„(R—(s-/usr/local/lib/python2.7/test/test_weakref.pyR‘ts(RRR‘((R—(s-/usr/local/lib/python2.7/test/test_weakref.pyRssssafe_callback called( R…R/RR‘R#RR&R9R+RƒR (RR…RšRR0tdR t external_wr((R—s-/usr/local/lib/python2.7/test/test_weakref.pyttest_callbacks_on_callbackks(       cCs|jtjƒdS(N(tcheck_gc_during_creationR#R(R((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_gc_during_ref_creation‘scCs|jtjƒdS(N(RžR#R2(R((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_gc_during_proxy_creation”scCs¡tjƒ}tjdddƒtjƒddd„ƒY}d„}|ƒ}|ƒ}||_||ƒ|_z|ƒ}tj||ƒWdtj|ŒXdS(NitAcBseZRS((RR(((s-/usr/local/lib/python2.7/test/test_weakref.pyR¡›scWsdS(N((targs((s-/usr/local/lib/python2.7/test/test_weakref.pyR žs((R…t get_thresholdt set_thresholdRƒtaR&R#R(RRbt thresholdsR¡R t referencedR¥((s-/usr/local/lib/python2.7/test/test_weakref.pyRž—s       cCs#dtfd„ƒY}|ƒ}dS(NtTargetcBseZd„ZRS(cSstj|ƒadS(N(R#Rt ref_from_del(R((s-/usr/local/lib/python2.7/test/test_weakref.pyt__del__¶s(RRRª(((s-/usr/local/lib/python2.7/test/test_weakref.pyR¨µs(R/(RR¨tw((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_ref_created_during_del°scCs?tjtƒ}|jt|jdddddƒtjƒdS(Ni(R#RR€R4RfRR…Rƒ(Rtr((s-/usr/local/lib/python2.7/test/test_weakref.pyt test_init¼s"cCsÙdtfd„ƒY}ddd„ƒY}g}tjtƒtj||jƒ}d}tjƒ|j|ƒdƒ|j||gƒtj||jƒ}d}tjƒ|j|ƒdƒ|j|||gƒdS(NR¡cBseZRS((RR(((s-/usr/local/lib/python2.7/test/test_weakref.pyR¡ÇstBcBseZRS((RR(((s-/usr/local/lib/python2.7/test/test_weakref.pyR¯És(( R/R#RtintRDR R…RƒR+(RR¡R¯tlR¥tb((s-/usr/local/lib/python2.7/test/test_weakref.pyt test_classesÄs   c Csštdƒ}tdƒ}tdƒ}tj|ƒ}tj|ƒ}tj|ƒ}tj|ƒ}|j||kƒ|j||kƒ|j||kƒ|j||kƒ|j||kƒ|j||kƒ~~~tjƒx*|||fD]}|j|ƒdƒqõW|j||kƒ|j||kƒ|j||kƒ|j||kƒ|j ||k||kƒ|j ||k||k ƒdS(Nii( RR#RRFRCR…RƒR9R R+( RRtytzR¥R²R0R›R­((s-/usr/local/lib/python2.7/test/test_weakref.pyt test_equalityØs.     cCs•tdƒ}tdƒ}tj|ƒ}tj|ƒ}|jt|ƒtdƒƒ~~tjƒ|jt|ƒtdƒƒ|jtt|ƒdS(Ni*( RR#RR+RR…RƒR4Rf(RRR´R¥R²((s-/usr/local/lib/python2.7/test/test_weakref.pyt test_hashingùs   cCsndtfd„ƒY}tjƒ}|dƒ}}x(tdƒD]}||ƒ||<}q?W~tjƒdS(NRcBseZd„ZRS(csA|s dStj|ƒ‰‡fd†}tj||ƒ|_dS(Ncs ˆƒ}dS(N((twparentR%(twself(s-/usr/local/lib/python2.7/test/test_weakref.pyR‘s(R#RR¸(RtparentR‘((R¹s-/usr/local/lib/python2.7/test/test_weakref.pyRs (RRR(((s-/usr/local/lib/python2.7/test/test_weakref.pyR sid(R/R#tWeakKeyDictionaryR RIR…Rƒ(RRR›trootR0tn((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_trashcan_16602s (*RRR'R)R.R1R7R"R(R=R@RPRWR[R^R`RaR_RgRARoRsRtRvRyR‚R‰RŽRR’R”R™RRŸR RžR¬R®R³R¶R·R¾(((s-/usr/local/lib/python2.7/test/test_weakref.pyR!DsP                    ( (    . &      ! tSubclassableWeakrefTestCasecBs5eZd„Zd„Zd„Zd„Zd„ZRS(csšdtjf‡fd†ƒY‰tdƒ}ˆ|ddƒ}|j|ƒ|ƒ|j|jƒ|j|jdƒ~|j|ƒƒ|j|jƒdS(NtMyRefcs,eZdd‡fd†Z‡fd†ZRS(i*cs&||_tˆ|ƒj||ƒdS(N(R–tsuperR(RtobR R–(RÀ(s-/usr/local/lib/python2.7/test/test_weakref.pyR"s cst|_tˆ|ƒjƒS(N(tTruetcalledRÁR (R(RÀ(s-/usr/local/lib/python2.7/test/test_weakref.pyR %s N(RRR RR ((RÀ(s-/usr/local/lib/python2.7/test/test_weakref.pyRÀ!sRhR–i( R#RRR9RFRÄR+R–R*(RR%tmr((RÀs-/usr/local/lib/python2.7/test/test_weakref.pyttest_subclass_refs s cCsdtjfd„ƒY}tdƒ}||ƒ}tj|ƒ}|j||ƒ|jtj|ƒ||gƒ|jtj|ƒdƒ||ƒ}|jtj|ƒdƒtj|ƒ}|jt|ƒdƒ|j||dƒ|j ||dƒ|j ||dƒdS(NRÀcBseZRS((RR(((s-/usr/local/lib/python2.7/test/test_weakref.pyRÀ2si*iiii( R#RRt assertIsNotR+RuR<RER9RH(RRÀR%tr1tr2tr3trefs((s-/usr/local/lib/python2.7/test/test_weakref.pyt-test_subclass_refs_dont_replace_standard_refs1s   cCs†dtjfd„ƒY}tdƒ}||tƒ}||tƒ}|j||ƒtj|ƒ}|j||ƒ|j||ƒdS(NRÀcBseZRS((RR(((s-/usr/local/lib/python2.7/test/test_weakref.pyRÀCsi*(R#RRtidtstrRÇRuRH(RRÀR%RÈRÉRË((s-/usr/local/lib/python2.7/test/test_weakref.pyt*test_subclass_refs_dont_conflate_callbacksBs cCsdtjfd„ƒY}tdƒ}||dddƒ}|j|jdƒ|j|jdƒ|j|jƒdƒ|jt |dƒƒdS(NRÀcBs)eZdZd„Zd„Zd„ZRS(tslot1tslot2cSstjj|||ƒS(N(R#Rt__new__(RdRÂR RÐRÑ((s-/usr/local/lib/python2.7/test/test_weakref.pyRÒPscSs||_||_dS(N(RÐRÑ(RRÂR RÐRÑ((s-/usr/local/lib/python2.7/test/test_weakref.pyRRs cSs|j|jS(N(RÐRÑ(R((s-/usr/local/lib/python2.7/test/test_weakref.pytmethUs(sslot1sslot2(RRt __slots__RÒRRÓ(((s-/usr/local/lib/python2.7/test/test_weakref.pyRÀNs  i*tabctdeftabcdeft__dict__( R#RRR R+RÐRÑRÓRCRi(RRÀR%R­((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_subclass_refs_with_slotsMs cs»dtjfd„ƒY}‡fd†}tƒ}|||ƒ}||_~~ˆjˆjdƒtƒ}|||ƒ}|||ƒ}||_||_~~~ˆjˆjdƒdS(NRÀcBseZRS((RR(((s-/usr/local/lib/python2.7/test/test_weakref.pyRÀescsˆjd7_dS(Ni(R(R«(R(s-/usr/local/lib/python2.7/test/test_weakref.pyR jsi(R#RRR%R+RR­(RRÀR R%RÈRÉ((Rs-/usr/local/lib/python2.7/test/test_weakref.pyttest_subclass_refs_with_cycle^s"     (RRRÆRÌRÏRÙRÚ(((s-/usr/local/lib/python2.7/test/test_weakref.pyR¿s    tMappingTestCasecBs.eZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z!d „Z"RS(!i c sØd}gt|ƒD]}tƒ^q}|‡fd†t|ƒDƒƒ}|jƒ}yt|ƒWntk rwnX~tjƒt|ƒ}t |ƒ~tjƒt|ƒ} |j |dƒ|j | dƒdS(Nic3s$|]\}}ˆ||ƒVqdS(N((t.0R†R%(tcons(s-/usr/local/lib/python2.7/test/test_weakref.pys Œsi( RIRt enumeratet iteritemstnextt StopIterationR…RƒRERqR+( Rt dict_typeRÝtNR†titemstdcttittn1tn2((RÝs-/usr/local/lib/python2.7/test/test_weakref.pytcheck_len_cycles‰s"""       cCs|jtjd„ƒdS(NcSs ||fS(N((R½R{((s-/usr/local/lib/python2.7/test/test_weakref.pyR~£s(RéR#R»(R((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_weak_keyed_len_cycles¢scCs|jtjd„ƒdS(NcSs ||fS(N((R½R{((s-/usr/local/lib/python2.7/test/test_weakref.pyR~¦s(RéR#tWeakValueDictionary(R((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_weak_valued_len_cycles¥sc s'|jtjtjƒŒxtddƒD]ö}d}tjdƒtj|||ƒgt|ƒD]}tƒ^qb}|‡fd†|Dƒƒ}~|jƒ}yt|ƒWnt k rÃnXt |ƒ} ~t |ƒ} |j | dƒ|j | |ƒ|j | dƒ|j | | ƒq)WdS(Niidiic3s|]}ˆ|ƒVqdS(N((RÜR%(RÝ(s-/usr/local/lib/python2.7/test/test_weakref.pys °s( t addCleanupR…R¤R£RIRƒRRßRàRáREtassertGreaterEqualtassertLessEqual( RRâRÝtthRãR†RäRåRæRçRè((RÝs-/usr/local/lib/python2.7/test/test_weakref.pytcheck_len_race¨s( "    cCs|jtjd„ƒdS(NcSs |dfS(Ni((R{((s-/usr/local/lib/python2.7/test/test_weakref.pyR~Ás(RñR#R»(R((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_weak_keyed_len_raceÀscCs|jtjd„ƒdS(NcSs d|fS(Ni((R{((s-/usr/local/lib/python2.7/test/test_weakref.pyR~Äs(RñR#Rë(R((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_weak_valued_len_raceÃscCsP|jƒ\}}xH|D]@}|jtj|ƒdd|ƒ|j|||jdƒqW|jƒ}|jƒjƒ}|jƒ|jƒ|j||dƒ~~|jt |ƒ|j ƒ|d=|jt |ƒ|j ddƒ~~|jt |ƒddƒtj ƒ}|j t |jdƒtƒ|d<|j t |jdƒdS( Nis&wrong number of weak references to %r!s#wrong object returned by weak dict!s/cloning of weak-valued dictionary did not work!is/deleting object did not cause dictionary updates0deleting the values did not clear the dictionaryi(tmake_weak_valued_dictR+R#R<R9RRätcopytsortREtCOUNTRëR4tKeyErrort __getitem__R(RtdicttobjectsR%titems1titems2((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_weak_valuesÆs0         cCs9|jƒ\}}xH|D]@}|jtj|ƒdd|ƒ|j|j||dƒqW|jƒ}|jƒjƒ}|jt|ƒt|ƒdƒ~~|jt |ƒ|j ƒ|d=|jt |ƒ|j ddƒ~~|jt |ƒddƒt dƒ}d ||<|j ||ƒ|j d |ƒdS( Nis&wrong number of weak references to %r!s#wrong object returned by weak dict!s.cloning of weak-keyed dictionary did not work!is/deleting object did not cause dictionary updates.deleting the keys did not clear the dictionaryi*s$What is the meaning of the universe?i"(tmake_weak_keyed_dictR+R#R<R9RRäRõtsetRER÷RRHt assertNotIn(RRúRûR%RüRý((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_weak_keysäs,      cCsY|jƒ\}}|j|ƒ|jƒ}|jt|ƒt|ƒƒt|ƒ}xK|D]C}|ƒ}|j||ƒ|j|j||ƒ|j|ƒqZW|jt|ƒdƒt|ƒ}|jtt|j ƒƒƒt|ƒƒxQ|j ƒD]C}|ƒ}|j||ƒ|j|j||ƒ|j|ƒqøW|jt|ƒdƒdS(Ni( Rÿt check_iterstkeyrefsR+RERqRHRR}t iterkeyrefs(RRúRûRËtobjects2R&RÂ((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_weak_keyed_iterss&      ( cCss|jƒ\}}|j|ƒ|jƒ}|jt|ƒt|ƒƒt|ƒ}xX|D]P}|ƒ}|j|||jƒ|j|j||jjƒ|j|ƒqZW|jt|ƒdƒt|ƒ}|jtt|jƒƒƒt|ƒƒx^|jƒD]P}|ƒ}|j|||jƒ|j|j||jjƒ|j|ƒqW|jt|ƒdƒdS(Ni( RôRt valuerefsR+RERqRR}t itervaluerefs(RRúRûRËRR&RÂ((s-/usr/local/lib/python2.7/test/test_weakref.pyttest_weak_valued_iterss&      ( cCs"|jƒ}x!|jƒD]}|j|ƒqW|jt|ƒddƒ|jƒ}x|D]}|j|ƒq\W|jt|ƒddƒ|jƒ}x!|jƒD]}|j|ƒq¥W|jt|ƒddƒ|jƒ}x!|jƒD]}|j|ƒqîW|jt|ƒddƒdS(Nis#iteritems() did not touch all itemss!__iter__() did not touch all keyss!iterkeys() did not touch all keyss%itervalues() did not touch all values( RäRßR}R+REtkeystiterkeystvaluest itervalues(RRúRätitemR R{R tv((s-/usr/local/lib/python2.7/test/test_weakref.pyR2s"     cCs’t|ƒ}tt||ƒƒƒ}t|ƒ|d=tjƒ|jtt|ƒƒt|ƒt|ƒdgƒ~|jt|ƒ|dƒdS(Niÿÿÿÿi( REtitertgetattrRàR…RƒRHRqR+(RRúRût iter_nameR½Ræ((s-/usr/local/lib/python2.7/test/test_weakref.pyt"check_weak_destroy_while_iteratingLs   2c Csc|ƒ \}}|j||kƒWdQX|ƒ#\}}|jt|j|ƒWdQX|j||kƒ|ƒ#\}}|jt|j|ƒWdQX|j||kƒ|ƒ\}}|||‰xˆD]}|j||R?(s-/usr/local/lib/python2.7/test/test_weakref.pyR1s  iiii( R#R»tFalseR/RIR–R treverseRÃR+RE(RR›RR†R%tcount((R>R?s-/usr/local/lib/python2.7/test/test_weakref.pyt!test_weak_keyed_cascading_deletes)s   %      (#RRR÷RéRêRìRñRòRóRþRRR RRRRRRR!RÿRôR*R+R,R0R1R2R3R4R5R:R;R=RC(((s-/usr/local/lib/python2.7/test/test_weakref.pyRÛ…sB                            (t mapping_teststWeakValueDictionaryTestCasecBsMeZdZiedƒd6edƒd6edƒd6ZejZd„ZRS(s?Check that WeakValueDictionary conforms to the mapping protocoliR%iR'itkey3cCs |jjƒS(N(t!_WeakValueDictionaryTestCase__refRõ(R((s-/usr/local/lib/python2.7/test/test_weakref.pyt _reference\s( RRt__doc__RRGR#Rët type2testRH(((s-/usr/local/lib/python2.7/test/test_weakref.pyREXs- tWeakKeyDictionaryTestCasecBsMeZdZidedƒ6dedƒ6dedƒ6ZejZd„ZRS(s=Check that WeakKeyDictionary conforms to the mapping protocoliR%iR'iRFcCs |jjƒS(N(t_WeakKeyDictionaryTestCase__refRõ(R((s-/usr/local/lib/python2.7/test/test_weakref.pyRHcs( RRRIRRLR#R»RJRH(((s-/usr/local/lib/python2.7/test/test_weakref.pyRK_s- sÀ Doctest for examples in the library reference: weakref.rst >>> import weakref >>> class Dict(dict): ... pass ... >>> obj = Dict(red=1, green=2, blue=3) # this object is weak referencable >>> r = weakref.ref(obj) >>> print r() is obj True >>> import weakref >>> class Object: ... pass ... >>> o = Object() >>> r = weakref.ref(o) >>> o2 = r() >>> o is o2 True >>> del o, o2 >>> print r() None >>> import weakref >>> class ExtendedRef(weakref.ref): ... def __init__(self, ob, callback=None, **annotations): ... super(ExtendedRef, self).__init__(ob, callback) ... self.__counter = 0 ... for k, v in annotations.iteritems(): ... setattr(self, k, v) ... def __call__(self): ... '''Return a pair containing the referent and the number of ... times the reference has been called. ... ''' ... ob = super(ExtendedRef, self).__call__() ... if ob is not None: ... self.__counter += 1 ... ob = (ob, self.__counter) ... return ob ... >>> class A: # not in docs from here, just testing the ExtendedRef ... pass ... >>> a = A() >>> r = ExtendedRef(a, foo=1, bar="baz") >>> r.foo 1 >>> r.bar 'baz' >>> r()[1] 1 >>> r()[1] 2 >>> r()[0] is a True >>> import weakref >>> _id2obj_dict = weakref.WeakValueDictionary() >>> def remember(obj): ... oid = id(obj) ... _id2obj_dict[oid] = obj ... return oid ... >>> def id2obj(oid): ... return _id2obj_dict[oid] ... >>> a = A() # from here, just testing >>> a_id = remember(a) >>> id2obj(a_id) is a True >>> del a >>> try: ... id2obj(a_id) ... except KeyError: ... print 'OK' ... else: ... print 'WeakValueDictionary error' OK t libreftestcCs1tjtttttƒtjtj t ƒdS(N( Rt run_unittestR!RÛRERKR¿t run_doctesttsystmodulesR(((s-/usr/local/lib/python2.7/test/test_weakref.pyt test_main»st__main__( R…RPtunittestRBR#RYRRõttestRR R©RRR R RRRtTestCaseRR!R¿RÛRDtBasicTestMappingProtocolRERKRMt__test__RRR(((s-/usr/local/lib/python2.7/test/test_weakref.pyts>            ÿÿÜgÿÒX