Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/landscape/lib/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pyc


Tc@s]defdYZdefdYZdZdZdZdZdZd	S(
t
SequenceErrorcBseZdZRS(s@Raised when the sequence isn't proper for translation to ranges.(t__name__t
__module__t__doc__(((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pyRstSequenceRangescBskeZdZdZedZedZdZdZdZ	dZ
dZd	ZRS(
sZHigh level interface to ranges.

    A ranges list represent a sequence of ordered and non-repeating
    elements into a more compact format, by representing 3 or more
    consecutive entries by a range.

    This means that a sequence such as

        [1, 2, 4, 5, 6, 8, 10, 11, 12, 14]

    becomes

        [1, 2, (4, 6), 8, (10, 12), 14]
    cCs
g|_dS(N(t_ranges(tself((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pyt__init__scCs|}t||j(|S(N(tsequence_to_rangesR(tclstsequencetobj((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pyt
from_sequences	cCs|}||j(|S(N(R(R	trangesR((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pytfrom_ranges s	
cCstt|jS(N(tlisttranges_to_sequenceR(R((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pytto_sequence&scCs
t|jS(N(RR(R((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pyt	to_ranges)scCs
t|jS(N(RR(R((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pyt__iter__,scCsqt|j|}|t|jkrm|j|}t|trc|d|ko`|dkSS||kStS(Nii(tfind_ranges_indexRtlent
isinstancettupletFalse(Rtitemtindexttest((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pyt__contains__/s
 
cCst|j|dS(N(t
add_to_rangesR(RR((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pytadd8scCst|j|dS(N(tremove_from_rangesR(RR((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pytremove;s(
RRRRtclassmethodRRRRRRRR (((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pyRs							ccs,t|}y|j}}Wntk
r4dSXx|dk	r'y|j}Wntk
rmd}nX||dkr|d7}q8|dk	r||kr||krtd||fqtd|fn||kr|Vn(||dkr|V|Vn||fV|}}q8WdS(s9Iterate over range items that compose the given sequence.NisSequence is unordered (%r < %r)sFound duplicated item (%r)(titertnextt
StopIterationtNoneR(R
titeratortrange_startt
range_stopR((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pyR?s0



ccs|xu|D]m}t|tro|\}}||krItd||nx(t||dD]}|Vq]Wq|VqWdS(s;Iterate over individual items represented in a ranges list.sRange error %d > %diN(RRt
ValueErrortxrange(R
Rtstarttend((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pyR_s
cCsd}t|}xi||kr}||d}||}y|d}Wntk
rZnX||krt|d}q|}qW|S(s'Find the index where an entry *may* be.iii(Rt	TypeError(R
RtlothitmidR((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pyRls



c	Cst||}}}|}}t|}||kr||}t|tr}|d|koq|dknrdSq||krdSnxz|dkr||d}t|tr|d|dkrPn|d}n||dkrPn|d8}|d8}qWxv||kr||}t|trZ|d|dkrMPn|d}n||dkrnPn|d7}|d7}qW||dkr|j||n||ff|||+dS(s.Insert item in ranges, reorganizing as needed.iiNi(RRRRtinsert(	R
Rtindex_startt
index_stopRR'R(t
ranges_lenR((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pyR~sB

$




cCs t||}t|}||kr||}t|tr|\}}||kr||dkrt|d|d|||d+n|d|ff|||d+||dkr||krt|||||+qq||dff|||+qq||kr||=qndS(s0Remove item from ranges, reorganizing as needed.iiN(RRRRtrange(R
RRR4RR'R(((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pyRs 
% N(	t	ExceptionRtobjectRRRRRR(((s@/usr/lib/python2.7/dist-packages/landscape/lib/sequenceranges.pyt<module>s8	 	
		1