Ñò ñG“Ic@s0defd„ƒYZdefd„ƒYZdS(tRangecBs°eZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z e e ƒZ d„Z e e ƒZ d „Z e e ƒZ d d „Ze eƒZd „Ze eƒZRS( sì Represents the Range header. This only represents ``bytes`` ranges, which are the only kind specified in HTTP. This can represent multiple sets of ranges, but no place else is this multi-range facility supported. cCsLx<|D]4\}}|djp|djptd|‚qW||_dS(NisBad ranges: %r(tNonetAssertionErrortranges(tselfRtbegintend((s3/usr/lib/python2.6/site-packages/webob/byterange.pyt__init__ s ,cCs=x6|iD]+\}}|dj o||jotSq WtS(sq Returns true if this range can be satisfied by the resource with the given byte length. N(RRtFalsetTrue(RtlengthRR((s3/usr/lib/python2.6/site-packages/webob/byterange.pyt satisfiables   cCstt|iƒdjodS|id\}}|djo|djo ||fSdS||jodS||fS(sÎ *If* there is only one range, and *if* it is satisfiable by the given length, then return a (begin, end) non-inclusive range of bytes to serve. Otherwise return None If length is None (unknown length), then the resulting range may be (begin, None), meaning it should be served from that point. If it's a range with a fixed endpoint we won't know if it is satisfiable, so this will return None. iiN(tlenRR(RR RR((s3/usr/lib/python2.6/site-packages/webob/byterange.pytrange_for_lengths     cCs9|i|ƒ}|djodSt|d|d|ƒS(s Works like range_for_length; returns None or a ContentRange object You can use it like:: response.content_range = req.range.content_range(response.content_length) Though it's still up to you to actually serve that content range! iiN(R Rt ContentRange(RR trange((s3/usr/lib/python2.6/site-packages/webob/byterange.pyt content_range2s  cCs|id|i|iƒƒS(Ntbytes(tserialize_bytestpython_ranges_to_bytesR(R((s3/usr/lib/python2.6/site-packages/webob/byterange.pyt__str__AscCs)d|iiditt|iƒƒfS(Ns<%s ranges=%s>s, (t __class__t__name__tjointmaptreprR(R((s3/usr/lib/python2.6/site-packages/webob/byterange.pyt__repr__Ds cCsp|i|ƒ}|djodS|\}}|iƒdjodS|i|ƒ}|djodS||ƒS(sH Parse the header; may return None if header is invalid RN(t parse_bytesRtlowertbytes_to_python_ranges(tclstheaderRtunitsR((s3/usr/lib/python2.6/site-packages/webob/byterange.pytparseJs   c Cs³|ptdƒ‚ng}d}yh|iddƒ\}}|iƒiƒ}x7|idƒD]&}d|jo tƒ‚n|idƒo9|djotdƒ‚nt|ƒ}d }d}n«|iddƒ\}}t|ƒ}||jp |djo|G|GHtd ƒ‚n|iƒp d }n t|ƒ}|d j o||jotd ƒ‚n|}|i||fƒq`WWntj o}|GHd SX||fS( sÛ Parse a Range header into (bytes, list_of_ranges). Note that the ranges are *inclusive* (like in HTTP, not like in Python typically). Will return None if the header is invalid sThe header must not be emptyit=it,t-stoo many end rangesiÿÿÿÿsbeginendN( t TypeErrortsplittstripRt ValueErrort startswithtintRtappend( RRtlast_endR RtitemRRte((s3/usr/lib/python2.6/site-packages/webob/byterange.pyRD           cCsßg}x¿|D]·\}}|djo9|djo|id|ƒqÄ|it|ƒƒq |djotd||fƒ‚n|djotd||fƒ‚n|id||fƒq Wd|di|ƒfS( sL Takes the output of parse_bytes and turns it into a header is%s-s/(%r, %r) should have a non-negative first values0(%r, %r) should have a non-negative second values%s-%ss%s=%sR#N(RR+tstrR(R(R RtpartsRR((s3/usr/lib/python2.6/site-packages/webob/byterange.pyRs     cCsþg}xñ|D]é\}}|djo;|djo|i|dfƒq qa||}|}n|djo d}n|djo|dj o |}n|dj o|dj o||jodS|dj o|d8}n|i||fƒq W|S(s- Converts the list-of-ranges from parse_bytes() to a Python-style list of ranges (non-inclusive end points) In the list of ranges, the last item can be None to indicate that it should go to the end of the file, and the first item can be negative to indicate that it should start from an offset from the end. If you give a length then this will not occur (negative numbers and offsets will be resolved). If length is given, and any range is not value, then None is returned. iiN(RR+(RR tresultRR((s3/usr/lib/python2.6/site-packages/webob/byterange.pyR¤s&        ' cCs\g}xO|D]G\}}|djo|i|dfƒq |i||dfƒq W|S(s˜ Converts a Python-style list of ranges to what serialize_bytes expects. This is the inverse of bytes_to_python_ranges iN(RR+(RR1RR((s3/usr/lib/python2.6/site-packages/webob/byterange.pyRÈs  N(Rt __module__t__doc__RR R RRRR!t classmethodRt staticmethodRRRR(((s3/usr/lib/python2.6/site-packages/webob/byterange.pyRs"        /    !  RcBsGeZdZd„Zd„Zd„Zd„Zd„ZeeƒZRS(s¨ Represents the Content-Range header This header is ``start-stop/length``, where stop and length can be ``*`` (represented as None in the attributes). cCso|djptd|‚|djp(|djo ||jptd|‚||_||_||_dS(Nis Bad start: %rs Bad stop: %r(RRtstarttstopR (RR6R7R ((s3/usr/lib/python2.6/site-packages/webob/byterange.pyRás *   cCsd|ii|fS(Ns<%s %s>(RR(R((s3/usr/lib/python2.6/site-packages/webob/byterange.pyRés cCs^|idjo d}n|id}|idjo d}n |i}d|i||fS(Nt*isbytes %s-%s/%s(R7RR R6(RR7R ((s3/usr/lib/python2.6/site-packages/webob/byterange.pyRîs    cCst|i|i|igƒS(sk Mostly so you can unpack this, like: start, stop, length = res.content_range (titerR6R7R (R((s3/usr/lib/python2.6/site-packages/webob/byterange.pyt__iter__ùscCs@|djodS|iƒ}|idƒpdS|tdƒiƒ}d|jodS|iddƒ\}}d|jodS|iddƒ\}}yVt|ƒ}|djo d}n t|ƒ}|djo d}n t|ƒ}Wntj odSX|djo||d|ƒS|||d|ƒSdS(sH Parse the header. May return None if it cannot parse. sbytes t/iR$R8N(RR'R)R R&R*R((RtvalueRR R6R((s3/usr/lib/python2.6/site-packages/webob/byterange.pyR!s2           ( RR2R3RRRR:R!R4(((s3/usr/lib/python2.6/site-packages/webob/byterange.pyRØs   $N(tobjectRR(((s3/usr/lib/python2.6/site-packages/webob/byterange.pyts×