ó
è?F[c           @   sl   d  d l  m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 S(   iÿÿÿÿ(   t   sixt   Batchc           B   s&   e  Z d  Z d e d „ Z d „  Z RS(   s	  
    Used to construct a BatchGet request.

    :ivar table: The Table object from which the item is retrieved.

    :ivar keys: A list of scalar or tuple values.  Each element in the
        list represents one Item to retrieve.  If the schema for the
        table has both a HashKey and a RangeKey, each element in the
        list should be a tuple consisting of (hash_key, range_key).  If
        the schema for the table contains only a HashKey, each element
        in the list should be a scalar value of the appropriate type
        for the table schema. NOTE: The maximum number of items that
        can be retrieved for a single operation is 100. Also, the
        number of items retrieved is constrained by a 1 MB size limit.

    :ivar attributes_to_get: A list of attribute names.
        If supplied, only the specified attribute names will
        be returned.  Otherwise, all attributes will be returned.

    :ivar consistent_read: Specify whether or not to use a
        consistent read. Defaults to False.

    c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   t   tablet   keyst   attributes_to_gett   consistent_read(   t   selfR   R   R   R   (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyt   __init__3   s    			c         C   s¿   i  } g  } xi |  j  D]^ } t | t ƒ r: | \ } } n | } d } |  j j j |  j j | | ƒ } | j | ƒ q W| | d <|  j	 r› |  j	 | d <n  |  j
 r± t | d <n
 t | d <| S(   sO   
        Convert the Batch object into the format required for Layer1.
        t   Keyst   AttributesToGett   ConsistentReadN(   R   t
   isinstancet   tuplet   NoneR   t   layer2t   build_key_from_valuest   schemat   appendR   R   t   Truet   False(   R   t
   batch_dictt   key_listt   keyt   hash_keyt	   range_keyt   k(    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyt   to_dict:   s"    
		
N(   t   __name__t
   __module__t   __doc__R   R   R   R   (    (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyR      s   t
   BatchWritec           B   s&   e  Z d  Z d d d „ Z d „  Z RS(   s  
    Used to construct a BatchWrite request.  Each BatchWrite object
    represents a collection of PutItem and DeleteItem requests for
    a single Table.

    :ivar table: The Table object from which the item is retrieved.

    :ivar puts: A list of :class:`boto.dynamodb.item.Item` objects
        that you want to write to DynamoDB.

    :ivar deletes: A list of scalar or tuple values.  Each element in the
        list represents one Item to delete.  If the schema for the
        table has both a HashKey and a RangeKey, each element in the
        list should be a tuple consisting of (hash_key, range_key).  If
        the schema for the table contains only a HashKey, each element
        in the list should be a scalar value of the appropriate type
        for the table schema.
    c         C   s+   | |  _  | p g  |  _ | p! g  |  _ d  S(   N(   R   t   putst   deletes(   R   R   R   R    (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyR   g   s    	c         C   sà   g  } xG |  j  D]< } i |  j j j | ƒ d 6} i | d 6} | j | ƒ q Wx} |  j D]r } t | t ƒ r~ | \ } } n | } d } |  j j j	 |  j j
 | | ƒ } i | d 6} | j i | d 6ƒ qZ W|  j j | f S(   sO   
        Convert the Batch object into the format required for Layer1.
        t   Itemt
   PutRequestt   Keyt   DeleteRequestN(   R   R   R   t   dynamize_itemR   R    R   R   R   R   R   t   name(   R   t   op_listt   itemt   dR   R   R   R   (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyR   l   s    N(   R   R   R   R   R   R   (    (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyR   S   s   t	   BatchListc           B   sA   e  Z d  Z d „  Z d e d „ Z d „  Z d „  Z d „  Z	 RS(   ss   
    A subclass of a list object that contains a collection of
    :class:`boto.dynamodb.batch.Batch` objects.
    c         C   s#   t  j |  ƒ d  |  _ | |  _ d  S(   N(   t   listR   R   t   unprocessedR   (   R   R   (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyR   ˆ   s    	c         C   s    |  j  t | | | | ƒ ƒ d S(   sO  
        Add a Batch to this BatchList.

        :type table: :class:`boto.dynamodb.table.Table`
        :param table: The Table object in which the items are contained.

        :type keys: list
        :param keys: A list of scalar or tuple values.  Each element in the
            list represents one Item to retrieve.  If the schema for the
            table has both a HashKey and a RangeKey, each element in the
            list should be a tuple consisting of (hash_key, range_key).  If
            the schema for the table contains only a HashKey, each element
            in the list should be a scalar value of the appropriate type
            for the table schema. NOTE: The maximum number of items that
            can be retrieved for a single operation is 100. Also, the
            number of items retrieved is constrained by a 1 MB size limit.

        :type attributes_to_get: list
        :param attributes_to_get: A list of attribute names.
            If supplied, only the specified attribute names will
            be returned.  Otherwise, all attributes will be returned.
        N(   R   R   (   R   R   R   R   R   (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyt	   add_batch   s    c   
      C   sâ   |  2|  j  s d SxÄ t j |  j  ƒ D]° \ } } | d } |  j j | ƒ } g  } xJ | D]B } | d } d } d | k rˆ | d } n  | j | | f ƒ qY Wd }	 d | k r¾ | d }	 n  |  j | | d |	 ƒq$ W|  j ƒ  S(   s  
        Resubmit the batch to get the next result set. The request object is
        rebuild from scratch meaning that all batch added between ``submit``
        and ``resubmit`` will be lost.

        Note: This method is experimental and subject to changes in future releases
        R   t   HashKeyElementt   RangeKeyElementR	   R   N(	   R,   R   R    t	   iteritemsR   t	   get_tableR   R-   t   submit(
   R   t
   table_namet	   table_reqt
   table_keysR   R   R   t   ht   rR   (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyt   resubmit§   s$    	

c         C   s2   |  j  j |  ƒ } d | k r. | d |  _ n  | S(   Nt   UnprocessedKeys(   R   t   batch_get_itemR,   (   R   t   res(    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyR2   È   s    c         C   sD   i  } x7 |  D]/ } | j  ƒ  } | d r | | | j j <q q W| S(   sM   
        Convert a BatchList object into format required for Layer1.
        R   (   R   R   R&   (   R   R)   t   batcht   b(    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyR   Î   s    
N(
   R   R   R   R   R   R   R-   R8   R2   R   (    (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyR*   ‚   s   		!	t   BatchWriteListc           B   s8   e  Z d  Z d „  Z d d d „ Z d „  Z d „  Z RS(   sx   
    A subclass of a list object that contains a collection of
    :class:`boto.dynamodb.batch.BatchWrite` objects.
    c         C   s   t  j |  ƒ | |  _ d  S(   N(   R+   R   R   (   R   R   (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyR   à   s    c         C   s   |  j  t | | | ƒ ƒ d S(   sW  
        Add a BatchWrite to this BatchWriteList.

        :type table: :class:`boto.dynamodb.table.Table`
        :param table: The Table object in which the items are contained.

        :type puts: list of :class:`boto.dynamodb.item.Item` objects
        :param puts: A list of items that you want to write to DynamoDB.

        :type deletes: A list
        :param deletes: A list of scalar or tuple values.  Each element
            in the list represents one Item to delete.  If the schema
            for the table has both a HashKey and a RangeKey, each
            element in the list should be a tuple consisting of
            (hash_key, range_key).  If the schema for the table
            contains only a HashKey, each element in the list should
            be a scalar value of the appropriate type for the table
            schema.
        N(   R   R   (   R   R   R   R    (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyR-   ä   s    c         C   s   |  j  j |  ƒ S(   N(   R   t   batch_write_item(   R   (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyR2   ú   s    c         C   s7   i  } x* |  D]" } | j  ƒ  \ } } | | | <q W| S(   sR   
        Convert a BatchWriteList object into format required for Layer1.
        (   R   (   R   R)   R<   R3   R   (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyR   ý   s
    N(   R   R   R   R   R   R-   R2   R   (    (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyR>   Ú   s
   		N(   t   boto.compatR    t   objectR   R   R+   R*   R>   (    (    (    s2   lib/python2.7/site-packages/boto/dynamodb/batch.pyt   <module>   s   9/X