mò %U²Ic@sÔdklZdkZdklZdklZdkZdkZ dk l Z dk Z dk Z dZd„Zdeifd„ƒYZd „Zd fd „ƒYZd fd „ƒYZdfd„ƒYZdfd„ƒYZdfd„ƒYZdfd„ƒYZdfd„ƒYZdklZlZd„Zdeifd„ƒYZdefd„ƒYZdefd„ƒYZ d eifd!„ƒYZ!d"Z"hd#e"(R R!R((Rt test_reprÈs  cCs™ttdƒƒ}|i|ƒzXttidƒ}||I|iƒttidƒ}|i |i ƒt |ƒƒWd|iƒt itiƒXdS(NiÈtwbtrb(RRRR topent test_supporttTESTFNtfotcloseR R treadROtostremove(R RRV((Rt test_printÏs     cCs-|ittddƒ|ittdƒdS(NRii(R R+R,R(R ((Rt test_initÜscCs|itttdƒƒdS(NR(R R+R,thashR(R ((Rt test_hashàscCs³x¬dD]¤}tt|ƒƒ}|i|i}}xSt|tƒD]B}||ƒ|ƒ}|||jo|i |||ƒqBqBW|i t |ƒt t|tƒƒqWdS(Niiiidiè(iiiidiè(tsizeRRRR RRRFRR%R R RR(R RRRR%R R_((Rt#test_long_steadystate_queue_popleftãs  cCsÅx¾dD]¶}ttt|ƒƒƒ}|i|i}}xSt|tƒD]B}||ƒ|ƒ}|||jo|i |||ƒqHqHW|i t tt |ƒƒƒtt|tƒƒqWdS(Niiiidiè(iiiidiè(R_RR RRR RR RFRR%R R RR(R RRRR%R R_((Rt$test_long_steadystate_queue_poprightîs  cCs‚tƒ}|i|i}}xttƒD]}||ƒq)Wx>ttƒD]0}|ƒ}||jo|i ||ƒqJqJWdS(N( RRR RRRRFRR%R R (R RRRR%R ((Rttest_big_queue_popleftùs     cCs‚tƒ}|i|i}}xttƒD]}||ƒq)Wx>ttƒD]0}|ƒ}||jo|i ||ƒqJqJWdS(N( RRR RR RRFRR%R R (R RRRR%R ((Rttest_big_queue_poprights     cCsžtƒ}|i|i}}xttƒD]}||ƒq)WxDtttƒƒD]0}|ƒ}||jo|i ||ƒqPqPW|i t |ƒdƒdS(Ni( RRR RRRFRR R%R R R(R RRRR%R ((Rttest_big_stack_rights    cCsžtƒ}|i|i}}xttƒD]}||ƒq)WxDt ttƒƒD]0}|ƒ}||jo|i ||ƒqPqPW|i t |ƒdƒdS(Ni(RRR RR RRRFRR R%R R R(R RRRR%R ((Rttest_big_stack_lefts    cCsZttdƒƒ}t|ƒ}|it|ƒt|ƒƒ|it|ƒt|ƒƒdS(NiÈ( RRRR!R tassertNotEqualtidR R(R R!R((Rttest_roundtrip_iter_init$s cCs€ttdƒƒ}xgdD]_}ti||ƒ}ti|ƒ}|i t |ƒt |ƒƒ|i t |ƒt |ƒƒqWdS(NiÈiii(iii(RRRRtpickletdumpsR2tloadsR!R RfRgR R(R R!RRR2((Rt test_pickle*scCs…tdƒ}|i|ƒxedD]]}titi||ƒƒ}|i t |ƒt |ƒƒ|i t |ƒt |dƒƒq WdS(NRiiiiÿÿÿÿ(iii( RRR RRiRkRjR!R RfRgR (R R!RR((Rttest_pickle_recursive2s  cCs‰dg}t|gƒ}ti|ƒ}|it|ƒt|ƒƒd|d<|i t |ƒt |ƒƒ|i t|ƒt|ƒƒdS(Ni i i( tmutRRtcopytdeepcopyR!R R RRfRg(R RnR!R((Rt test_deepcopy:s  cCs‰dg}t|gƒ}ti|ƒ}|it|ƒt|ƒƒd|d<|it |ƒt |ƒƒ|it|ƒt|ƒƒdS(Ni i i( RnRRRoR!R R RRfRg(R RnR!R((Rt test_copyCs  cCsOxHdtdƒfD]4}|ittt|ƒƒƒtt|ƒƒƒqWdS(NR*iÐ(RR2R R RR R(R R2((Rt test_reversedLscCsDdk}tƒ}x+tdƒD]}|idƒ|iƒqWdS(Nidi(tgcRRRRR tcollect(R RRRt((Rttest_gc_doesnt_blowupPs     (t__name__t __module__RR(R.R0R9R:R?RHRKRLRMRPR[R\R^R`RaRbRcRdReRhRlRmRqRrRsRv(((RRs8      5         ccsx|D] }|VqWdS(sRegular generatorN(tseqnR(RyR((RtRYstGcBs tZdZd„Zd„ZRS(sSequence using __getitem__cCs ||_dS(N(RyR (R Ry((RR`scCs |i|S(N(R RyR(R R((RR8bs(RwRxt__doc__RR8(((RR{^s  tIcBs)tZdZd„Zd„Zd„ZRS(s Sequence using iterator protocolcCs||_d|_dS(Ni(RyR R(R Ry((RRgs cCs|S(N(R (R ((Rt__iter__jscCsF|it|iƒjo t‚n|i|i}|id7_|S(Ni(R RRRyt StopIterationtv(R R€((Rtnextls  (RwRxR|RR~R(((RR}es   tIgcBs tZdZd„Zd„ZRS(s9Sequence using iterator protocol defined with a generatorcCs||_d|_dS(Ni(RyR R(R Ry((RRts ccsx|iD] }|Vq WdS(N(R RyR=(R R=((RR~ws (RwRxR|RR~(((RR‚rs  tXcBs tZdZd„Zd„ZRS(s Missing __getitem__ and __iter__cCs||_d|_dS(Ni(RyR R(R Ry((RR}s cCsF|it|iƒjo t‚n|i|i}|id7_|S(Ni(R RRRyRR€(R R€((RR€s  (RwRxR|RR(((RRƒ{s  tNcBs tZdZd„Zd„ZRS(sIterator missing next()cCs||_d|_dS(Ni(RyR R(R Ry((RRˆs cCs|S(N(R (R ((RR~‹s(RwRxR|RR~(((RR„†s  tEcBs)tZdZd„Zd„Zd„ZRS(sTest propagation of exceptionscCs||_d|_dS(Ni(RyR R(R Ry((RRs cCs|S(N(R (R ((RR~“scCs dddS(Nii((R ((RR•s(RwRxR|RR~R(((RR…Žs   tScBs)tZdZd„Zd„Zd„ZRS(sTest immediate stopcCsdS(N((R Ry((RRšscCs|S(N(R (R ((RR~œscCs t‚dS(N(R(R ((RRžs(RwRxR|RR~R(((RR†˜s   (schainsimapcCs(ttd„ttt|ƒƒƒƒƒS(s Test multiple tiers of iteratorscCs|S(N(R%(R%((Rt¤sN(tchaintimapRzR‚R{Ry(Ry((RtL¢stTestVariousIteratorArgscBstZd„Zd„ZRS(NcCsÒxËddtdƒd tdddƒfD]¢}xNttttttfD]4}|i t t ||ƒƒƒt ||ƒƒƒqGW|itt t|ƒƒ|itt t|ƒƒ|itt t|ƒƒq(WdS( Nt123Riètdof1.2iÐi˜i(Rf1.2(RRR2R{R}R‚R†RŠRztgR R RRR+R,RƒR„tZeroDivisionErrorR…(R RŽR2((Rttest_constructor©s(2cCs9tdƒ}t|ƒ}|iƒ|it|iƒdS(Ntabcdefg( RRtitertitRR R+t RuntimeErrorR(R RR“((Rttest_iter_with_altered_data±s   (RwRxRR•(((RR‹§s tDequecBstZRS(N(RwRx(((RR–·stDequeWithBadItercBstZd„ZRS(NcCs t‚dS(N(R,(R ((RR~»s(RwRxR~(((RR—ºst TestSubclasscBs5tZd„Zd„Zd„Zd„Zd„ZRS(NcCs©ttdƒƒ}|itddƒƒx$tddƒD]}|i|ƒq8Wx*ttddƒƒD]}|i|ƒqeW|i t |ƒt ddƒƒ|i t |ƒdƒg}tdƒD]}||iƒqÂ~}|i |t ddƒƒ|i t |ƒt ddƒƒg}tdƒD]}||iƒq'~}|iƒ|i |t d dƒƒ|i t |ƒt dd ƒƒ|iƒ|i t |ƒdƒdS( NidiÈii8ÿÿÿiiXiúi2i–(R–RRRRR R R R R RRRRRRRRRRJ(R RRRRR((RRÀs&--  cCs tdƒ}|iƒ}|it|ƒt|ƒƒ|it|ƒt|ƒƒt|ƒ}|it|ƒt|ƒƒ|it|ƒt|ƒƒti |ƒ}ti |ƒ}|i t |ƒt |ƒƒ|it|ƒt|ƒƒ|it|ƒt|ƒƒdS(NR(R–Rt__copy__R!R R R"RRiRjR2RkRfRg(R R!RR2((Rttest_copy_pickleÖs   cCstdƒ}|i|ƒtiti|ƒƒ}|it |ƒt |ƒƒ|i t |ƒt |ƒƒ|i ƒ}|i ƒ}|i t |ƒt |ƒƒ|i ||ƒ||_titi|ƒƒ}|i t |ƒt |iƒƒtdƒ}|itti|ƒdS(NR(R–RR RiRkRjR!R RfRgR R"RtddteeR%R—R+R,(R R!RRœR›((RRlès      cCsQtdƒ}t|ƒ}|it|ƒt|ƒƒd}|it t|ƒdS(Ntgallahad( RRtproxytpR R tstrtNoneR+tReferenceError(R RRŸ((Rt test_weakrefûs   cCsNdtfd„ƒY}|dddgƒ}|dddgƒ}||jdS( NRƒcBstZd„ZRS(NcCs tgƒS(N(R’(R ((RR~s(RwRxR~(((RRƒsiiiiii(RRƒtd1td2(R RƒR¤R¥((Rttest_strange_subclasss(RwRxRRšRlR£R¦(((RR˜¾s     s‘ Example from the Library Reference: Doc/lib/libcollections.tex >>> from collections import deque >>> d = deque('ghi') # make a new deque with three items >>> for elem in d: # iterate over the deque's elements ... print elem.upper() G H I >>> d.append('j') # add a new entry to the right side >>> d.appendleft('f') # add a new entry to the left side >>> d # show the representation of the deque deque(['f', 'g', 'h', 'i', 'j']) >>> d.pop() # return and remove the rightmost item 'j' >>> d.popleft() # return and remove the leftmost item 'f' >>> list(d) # list the contents of the deque ['g', 'h', 'i'] >>> d[0] # peek at leftmost item 'g' >>> d[-1] # peek at rightmost item 'i' >>> list(reversed(d)) # list the contents of a deque in reverse ['i', 'h', 'g'] >>> 'h' in d # search the deque True >>> d.extend('jkl') # add multiple elements at once >>> d deque(['g', 'h', 'i', 'j', 'k', 'l']) >>> d.rotate(1) # right rotation >>> d deque(['l', 'g', 'h', 'i', 'j', 'k']) >>> d.rotate(-1) # left rotation >>> d deque(['g', 'h', 'i', 'j', 'k', 'l']) >>> deque(reversed(d)) # make a new deque in reverse order deque(['l', 'k', 'j', 'i', 'h', 'g']) >>> d.clear() # empty the deque >>> d.pop() # cannot pop from an empty deque Traceback (most recent call last): File "", line 1, in -toplevel- d.pop() IndexError: pop from an empty deque >>> d.extendleft('abc') # extendleft() reverses the input order >>> d deque(['c', 'b', 'a']) >>> def delete_nth(d, n): ... d.rotate(-n) ... d.popleft() ... d.rotate(n) ... >>> d = deque('abcdef') >>> delete_nth(d, 2) # remove the entry at d[2] >>> d deque(['a', 'b', 'd', 'e', 'f']) >>> def roundrobin(*iterables): ... pending = deque(iter(i) for i in iterables) ... while pending: ... task = pending.popleft() ... try: ... yield task.next() ... except StopIteration: ... continue ... pending.append(task) ... >>> for value in roundrobin('abc', 'd', 'efgh'): ... print value ... a d e b f c g h >>> def maketree(iterable): ... d = deque(iterable) ... while len(d) > 1: ... pair = [d.popleft(), d.popleft()] ... d.append(pair) ... return list(d) ... >>> print maketree('abcdefgh') [[[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]]] t libreftestcCsÀdk}tttf}ti|Œ|ost|dƒocdk }dgd}xAt t |ƒƒD]-}ti|Œ|iƒ|iƒ||          ÿI       Og