o ckF[ @sbddlmZddlmZGdddeZdddZddd Zdd d Zed Z GdddeZ dS))SDBResponseError)sixc@s0eZdZdZdZd ddZd ddZdd ZdS) SequenceGeneratoraGeneric Sequence Generator object, this takes a single string as the "sequence" and uses that to figure out what the next value in a string is. For example if you give "ABC" and pass in "A" it will give you "B", and if you give it "C" it will give you "AA". If you set "rollover" to True in the above example, passing in "C" would give you "A" again. The Sequence string can be a string or any iterable that has the "index" function and is indexable. FcCs:||_t|d|_||_|d|_d|jj|f|_dS)aCreate a new SequenceGenerator using the sequence_string as how to generate the next item. :param sequence_string: The string or list that explains how to generate the next item in the sequence :type sequence_string: str,iterable :param rollover: Rollover instead of incrementing when we hit the end of the sequence :type rollover: bool rz%s('%s')N)sequence_stringlensequence_lengthrollover last_item __class____name__)selfrr r6/usr/lib/python3/dist-packages/boto/sdb/db/sequence.py__init__(s   zSequenceGenerator.__init__NcCs|dus t||jkr|jdS||j d}|js3||jkr3d||d|j ||f}|Sd|d|j ||f}|S)z"Get the next value in the sequenceNrz%s%s)rrrr r _inc)r vallast last_valuerrr__call__:s "zSequenceGenerator.__call__cCs2t||jks J|j|j|dt|jS)zIncrement a single value)rrrindexr rrrrrHs zSequenceGenerator._inc)FN)r __module__ __qualname____doc__rrrrrrrrs    rNcCs|durdS|dS)Nrrrcvlvrrrincrement_by_oneQr cCs|durdS|dS)NrrrrrrdoubleVr!r#rcCs |durd}|dur d}||S)z@The fibonacci sequence, this incrementer uses the last valueNrrrrrrrfib[s r$ABCDEFGHIJKLMNOPQRSTUVWXYZc@sdeZdZdZddedfddZddZddZeeeZ d d Z d d Z ee Z d dZ ddZdS)SequencezA simple Sequence using the new SDB "Consistent" features Based largly off of the "Counter" example from mitch garnaat: http://bitbucket.org/mitch/stupidbototricks/src/tip/counter.pyNcCsd|_d|_d|_||_||_|dur||}|jdur'ddl}t||_t|d|_ d|_ t |t j rAddlm}||}||_|jsL||_dSdS)anCreate a new Sequence, using an optional function to increment to the next number, by default we just increment by one. Every parameter here is optional, if you don't specify any options then you'll get a new SequenceGenerator with a random ID stored in the default domain that increments by one and uses the default botoweb environment :param id: Optional ID (name) for this counter :type id: str :param domain_name: Optional domain name to use, by default we get this out of the environment configuration :type domain_name:str :param fnc: Optional function to use for the incrementation, by default we just increment by one There are several functions defined in this module. Your function must accept "None" to get the initial value :type fnc: function, str :param init_val: Initial value, by default this is the first element in your sequence, but you can pass in any value, even a string if you pass in a function that uses strings instead of ints to increment Nr) find_class)_db_valuer domain_nameiduuidstruuid4type item_type timestamp isinstancer string_types boto.utilsr'fncr)r r+r*r5init_valr,r'rrrrls&    zSequence.__init__c Csddl}|}g}i}||d<|jdur!|j|d<dt|jg}||d<z|jj|j||d|d|_WdStyM}z |jdkrHt dd}~ww) z Set the valuerNr1r current_value)expected_valueizSequence out of sync) timer)r-dbput_attributesr+r1rstatus ValueError)r rr9nowr8new_valerrrsets$   z Sequence.setcCsj|jj|jdd}|r2d|vr|d|_d|vr ||d|_d|vr2|ddur2||d|_|jS)z Get the valueT)consistent_readr1r7rN)r:get_attributesr+r1r0r)rrrrrgets z Sequence.getcCs&d|jj|j|j|jj|jj|jfS)Nz%s('%s', '%s', '%s.%s', '%s'))r r r+r*r5rrr rrr__repr__s zSequence.__repr__c Cs|jsKddl}|}|js|jdd|jddd|_z ||j|_W|jStyJ}z|jdkr=| |j|_nWYd}~|jSd}~ww|jS)zConnect to our domainrNDB sequence_dbdb_namedefaulti) r(boto connect_sdbr*configrD get_domainrr< create_domain)r rKsdbr@rrr_connects"  zSequence._connectcCs||j|j|_|jSr)r5rrrErrrnextsz Sequence.nextcCs|j|jdS)zRemove this sequenceN)r:delete_attributesr+rErrrdeleteszSequence.delete)r rrrr rrArDpropertyrrFrQr:rRrTrrrrr&gs0   r&)NN)rr) boto.exceptionr boto.compatrobjectrr r#r$increment_stringr&rrrrs   8