KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17
System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64
User : nobody ( 99)
PHP Version : 5.2.17
Disable Function : NONE
Directory :  /proc/21571/root/usr/lib/python2.4/test/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/21571/root/usr/lib/python2.4/test/test_iterlen.pyc
mς
‚=5Dc@sdZdkZdklZdklZlZdklZdk	l	Z	dZ
deifd„ƒYZd	efd
„ƒYZ
defd„ƒYZd
efd„ƒYZdefd„ƒYZdefd„ƒYZde
fd„ƒYZde
fd„ƒYZde
fd„ƒYZde
fd„ƒYZde
fd„ƒYZde
fd„ƒYZdefd „ƒYZd!efd"„ƒYZd#efd$„ƒYZd%efd&„ƒYZed'joAeeeeeeeeeeeeeegZeieŒndS((s‘ Test Iterator Length Transparency

Some functions or methods which accept general iterable arguments have
optional, more efficient code paths if they know how many items to expect.
For instance, map(func, iterable), will pre-allocate the exact amount of
space required whenever the iterable can report its length.

The desired invariant is:  len(it)==len(list(it)).

A complication is that an iterable and iterator can be the same object. To
maintain the invariant, an iterator needs to dynamically update its length.
For instance, an iterable such as xrange(10) always reports its length as ten,
but it=iter(xrange(10)) starts at ten, and then goes to nine after it.next().
Having this capability means that map() can ignore the distinction between
map(func, iterable) and map(func, iter(iterable)).

When the iterable is immutable, the implementation can straight-forwardly
report the original length minus the cumulative number of calls to next().
This is the case for tuples, xrange objects, and itertools.repeat().

Some containers become temporarily immutable during iteration.  This includes
dicts, sets, and collections.deque.  Their implementation is equally simple
though they need to permantently set their length to zero whenever there is
an attempt to iterate after a length mutation.

The situation slightly more involved whenever an object allows length mutation
during iteration.  Lists and sequence iterators are dynanamically updatable.
So, if a list is extended during iteration, the iterator will continue through
the new items.  If it shrinks to a point before the most recent iteration,
then no further items are available and the length is reported at zero.

Reversed objects can also be wrapped around mutable objects; however, any
appends after the current position are ignored.  Any other approach leads
to confusion and possibly returning the same item more than once.

The iterators not listed above, such as enumerate and the other itertools,
are not length transparent because they have no way to distinguish between
iterables that report static length and iterators whose length changes with
each call (i.e. the difference between enumerate('abc') and
enumerate(iter('abc')).

N(stest_support(srepeatscount(sdeque(sUserListi
tTestInvariantWithoutMutationscBstZd„ZRS(NcCs|i}xAttdtdƒƒD]&}|it|ƒ|ƒ|iƒq#W|it|ƒdƒ|i	t
|iƒ|it|ƒdƒdS(Nii(tselftittreversedtxrangetntitassertEqualtlentnexttassertRaisest
StopIteration(RRR((t'/usr/lib/python2.4/test/test_iterlen.pyttest_invariant6s	(t__name__t
__module__R
(((RR4stTestTemporarilyImmutablecBstZd„ZRS(NcCsz|i}|it|ƒtƒ|iƒ|it|ƒtdƒ|iƒ|it|iƒ|it|ƒdƒdS(Nii(	RRRRRR	tmutateR
tRuntimeError(RR((Rttest_immutable_during_iterationAs	

(RRR(((RR?st
TestRepeatcBstZd„Zd„ZRS(NcCstdtƒ|_dS(N(trepeattNoneRRR(R((RtsetUpQscCs|itttdƒƒdS(N(RR
t	TypeErrorRRR(R((Rttest_no_len_for_infinite_repeatTs(RRRR(((RROs	t
TestXrangecBstZd„ZRS(NcCstttƒƒ|_dS(N(titerRRRR(R((RRZs(RRR(((RRXstTestXrangeCustomReversedcBstZd„ZRS(NcCstttƒƒ|_dS(N(RRRRR(R((RR_s(RRR(((RR]st	TestTuplecBstZd„ZRS(NcCsttttƒƒƒ|_dS(N(RttupleRRRR(R((RRds(RRR(((RRbst	TestDequecBstZd„ZRS(NcCs1tttƒƒ}t|ƒ|_|i|_dS(N(	tdequeRRtdRRRtpopR(RR!((RRks(RRR(((RRistTestDequeReversedcBstZd„ZRS(NcCs1tttƒƒ}t|ƒ|_|i|_dS(N(	R RRR!RRRR"R(RR!((RRrs(RRR(((RR#pstTestDictKeyscBstZd„ZRS(NcCs4tittƒƒ}t|ƒ|_|i|_	dS(N(
tdicttfromkeysRRR!RRRtpopitemR(RR!((RRys(RRR(((RR$wst
TestDictItemscBstZd„ZRS(NcCs4tittƒƒ}|iƒ|_|i|_	dS(N(
R%R&RRR!t	iteritemsRRR'R(RR!((RR€s(RRR(((RR(~stTestDictValuescBstZd„ZRS(NcCs4tittƒƒ}|iƒ|_|i|_	dS(N(
R%R&RRR!t
itervaluesRRR'R(RR!((RR‡s(RRR(((RR*…stTestSetcBstZd„ZRS(NcCs1tttƒƒ}t|ƒ|_|i|_dS(N(	tsetRRR!RRRR"R(RR!((RRŽs(RRR(((RR,ŒstTestListcBstZd„Zd„ZRS(NcCstttƒƒ|_dS(N(RtrangeRRR(R((RR—scCsΠttƒ}t|ƒ}|iƒ|iƒ|it|ƒtdƒ|i	tƒ|it|ƒtdƒg|d)|it|ƒdƒ|it
|ƒgƒ|itdƒƒ|it|ƒdƒdS(Niiii(
R/RR!RRR	RRRtappendtlisttextendR(RR!R((Rt
test_mutationšs



(RRRR3(((RR.•s	tTestListReversedcBstZd„Zd„ZRS(NcCstttƒƒ|_dS(N(RR/RRR(R((RRͺscCsΠttƒ}t|ƒ}|iƒ|iƒ|it|ƒtdƒ|i	tƒ|it|ƒtdƒg|d)|it|ƒdƒ|it
|ƒgƒ|itdƒƒ|it|ƒdƒdS(Niiii(
R/RR!RRR	RRRR0R1R2R(RR!R((RR3­s



(RRRR3(((RR4¨s	tTestSeqItercBstZd„Zd„ZRS(NcCsttttƒƒƒ|_dS(N(RtUserListR/RRR(R((RR½scCsΦtttƒƒ}t|ƒ}|iƒ|iƒ|it	|ƒtdƒ|i
tƒ|it	|ƒtdƒg|d)|it	|ƒdƒ|it|ƒgƒ|it
dƒƒ|it	|ƒdƒdS(Niiii(R6R/RR!RRR	RRRR0R1R2R(RR!R((RR3ΐs



(RRRR3(((RR5»s	tTestSeqIterReversedcBstZd„Zd„ZRS(NcCsttttƒƒƒ|_dS(N(RR6R/RRR(R((RRΠscCsΦtttƒƒ}t|ƒ}|iƒ|iƒ|it	|ƒtdƒ|i
tƒ|it	|ƒtdƒg|d)|it	|ƒdƒ|it|ƒgƒ|it
dƒƒ|it	|ƒdƒdS(Niiii(R6R/RR!RRR	RRRR0R1R2R(RR!R((RR3Σs



(RRRR3(((RR7Ξs	t__main__(t__doc__tunittestttestttest_supportt	itertoolsRtcounttcollectionsR R6RtTestCaseRRRRRRRR#R$R(R*R,R.R4R5R7Rt	unitteststrun_unittest(R<R R:R.R4RRR6RRR5R#R>R,RARR*RRR(R7RRR$((Rt?*s2	


		
0

Anon7 - 2021