ó
è?F[c           @  s¸   d  d l  m Z d  d l m Z d  d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d  d l	 Z	 d  d	 l
 m Z d
 e f d „  ƒ  YZ d  d l m Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   print_function(   t   SelectResultSet(   t   sixt   Domainc           B  sÚ   e  Z d d d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z e	 d d „ Z
 e	 d „ Z d e d d „ Z d d d	 „ Z d
 „  Z d d e d d „ Z e d „ Z d „  Z d „  Z d d „ Z d „  Z d „  Z RS(   c         C  s   | |  _  | |  _ d  |  _ d  S(   N(   t
   connectiont   namet   Nonet	   _metadata(   t   selfR   R   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt   __init__    s    		c         C  s   d |  j  S(   Ns	   Domain:%s(   R   (   R   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt   __repr__%   s    c         C  s   t  |  j d |  j ƒ ƒ S(   Ns   SELECT * FROM `%s`(   t   itert   selectR   (   R   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt   __iter__(   s    c         C  s   d  S(   N(   R   (   R   R   t   attrsR   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt   startElement+   s    c         C  s,   | d k r | |  _  n t |  | | ƒ d  S(   Nt
   DomainName(   R   t   setattr(   R   R   t   valueR   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt
   endElement.   s    c         C  s(   |  j  s! |  j j |  ƒ |  _  n  |  j  S(   N(   R   R   t   domain_metadata(   R   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt   get_metadata4   s    	c         C  s   |  j  j |  | | | | ƒ S(   sõ  
        Store attributes for a given item.

        :type item_name: string
        :param item_name: The name of the item whose attributes are being stored.

        :type attribute_names: dict or dict-like object
        :param attribute_names: The name/value pairs to store as attributes

        :type expected_value: list
        :param expected_value: If supplied, this is a list or tuple consisting
            of a single attribute name and expected value. The list can be
            of the form:

             * ['name', 'value']

            In which case the call will first verify that the attribute
            "name" of this item has a value of "value".  If it does, the delete
            will proceed, otherwise a ConditionalCheckFailed error will be
            returned. The list can also be of the form:

             * ['name', True|False]

            which will simply check for the existence (True) or non-existence
            (False) of the attribute.

        :type replace: bool
        :param replace: Whether the attribute values passed in will replace
                        existing values or will be added as addition values.
                        Defaults to True.

        :rtype: bool
        :return: True if successful
        (   R   t   put_attributes(   R   t	   item_namet
   attributest   replacet   expected_value(    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR   9   s    $c         C  s   |  j  j |  | | ƒ S(   sÑ  
        Store attributes for multiple items.

        :type items: dict or dict-like object
        :param items: A dictionary-like object.  The keys of the dictionary are
                      the item names and the values are themselves dictionaries
                      of attribute names/values, exactly the same as the
                      attribute_names parameter of the scalar put_attributes
                      call.

        :type replace: bool
        :param replace: Whether the attribute values passed in will replace
                        existing values or will be added as addition values.
                        Defaults to True.

        :rtype: bool
        :return: True if successful
        (   R   t   batch_put_attributes(   R   t   itemsR   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR   `   s    c         C  s   |  j  j |  | | | | ƒ S(   sU  
        Retrieve attributes for a given item.

        :type item_name: string
        :param item_name: The name of the item whose attributes are being retrieved.

        :type attribute_names: string or list of strings
        :param attribute_names: An attribute name or list of attribute names.  This
                                parameter is optional.  If not supplied, all attributes
                                will be retrieved for the item.

        :rtype: :class:`boto.sdb.item.Item`
        :return: An Item mapping type containing the requested attribute name/values
        (   R   t   get_attributes(   R   R   t   attribute_namet   consistent_readt   item(    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR   u   s    c         C  s   |  j  j |  | | | ƒ S(   s  
        Delete attributes from a given item.

        :type item_name: string
        :param item_name: The name of the item whose attributes are being deleted.

        :type attributes: dict, list or :class:`boto.sdb.item.Item`
        :param attributes: Either a list containing attribute names which will cause
                           all values associated with that attribute name to be deleted or
                           a dict or Item containing the attribute names and keys and list
                           of values to delete as the value.  If no value is supplied,
                           all attribute name/values for the item will be deleted.

        :type expected_value: list
        :param expected_value: If supplied, this is a list or tuple consisting
            of a single attribute name and expected value. The list can be of
            the form:

             * ['name', 'value']

            In which case the call will first verify that the attribute "name"
            of this item has a value of "value".  If it does, the delete
            will proceed, otherwise a ConditionalCheckFailed error will be
            returned. The list can also be of the form:

             * ['name', True|False]

            which will simply check for the existence (True) or
            non-existence (False) of the attribute.

        :rtype: bool
        :return: True if successful
        (   R   t   delete_attributes(   R   R   R   t   expected_values(    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR!   ˆ   s    #c         C  s   |  j  j |  | ƒ S(   sÖ  
        Delete multiple items in this domain.

        :type items: dict or dict-like object
        :param items: A dictionary-like object.  The keys of the dictionary are
            the item names and the values are either:

                * dictionaries of attribute names/values, exactly the
                  same as the attribute_names parameter of the scalar
                  put_attributes call.  The attribute name/value pairs
                  will only be deleted if they match the name/value
                  pairs passed in.
                * None which means that all attributes associated
                  with the item should be deleted.

        :rtype: bool
        :return: True if successful
        (   R   t   batch_delete_attributes(   R   R   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR#   ®   s    t    c      	   C  s   t  |  | d | d | d | ƒS(   s  
        Returns a set of Attributes for item names within domain_name that match the query.
        The query must be expressed in using the SELECT style syntax rather than the
        original SimpleDB query language.

        :type query: string
        :param query: The SimpleDB query to be performed.

        :rtype: iter
        :return: An iterator containing the results.  This is actually a generator
                 function that will iterate across all search results, not just the
                 first page.
        t	   max_itemst
   next_tokenR   (   R   (   R   t   queryR&   R   R%   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR   Ã   s    c         C  s0   |  j  | d | ƒ} | r( |  | _ | Sd Sd S(   s®  
        Retrieves an item from the domain, along with all of its attributes.

        :param string item_name: The name of the item to retrieve.
        :rtype: :class:`boto.sdb.item.Item` or ``None``
        :keyword bool consistent_read: When set to true, ensures that the most
                                       recent data is returned.
        :return: The requested item, or ``None`` if there was no match found
        R   N(   R   t   domainR   (   R   R   R   R    (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt   get_itemÔ   s
    
	c         C  s   |  j  j |  | ƒ S(   N(   R   t   item_cls(   R   R   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt   new_itemå   s    c         C  s   |  j  | j ƒ d  S(   N(   R!   R   (   R   R    (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt   delete_itemè   s    c      	   C  s’  | s" d d l  m } | ƒ  } n  t d d | ƒt d |  j d | ƒx|  D]} t d | j d | ƒxã | D]Û } t d | d | ƒ| | } t | t ƒ s³ | g } n  x‰ | D] } t d d	 d
 d | ƒt | t j ƒ rý | j d d ƒ } n! t j | d d ƒj d d ƒ } | j	 | ƒ t d d | ƒqº Wt d d | ƒqt Wt d d | ƒqP Wt d d | ƒ| j
 ƒ  | j d ƒ | S(   s×   Get this domain as an XML DOM Document
        :param f: Optional File to dump directly to
        :type f: File or Stream

        :return: File object where the XML has been dumped to
        :rtype: file
        iÿÿÿÿ(   t   TemporaryFiles&   <?xml version="1.0" encoding="UTF-8"?>t   files   <Domain id="%s">s   	<Item id="%s">s   		<attribute id="%s">s   			<value><![CDATA[t   endt    s   utf-8R   t   errorss   ]]></value>s   		</attribute>s   	</Item>s	   </Domain>i    (   t   tempfileR-   t   printR   t
   isinstancet   listR   t	   text_typet   encodet   writet   flusht   seek(   R   t   fR-   R    t   kt   valuesR   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt   to_xmlë   s2    
!
c         C  s/   d d l  } t |  ƒ } | j j | | ƒ | S(   s)   Load this domain based on an XML documentiÿÿÿÿN(   t   xml.saxt   DomainDumpParsert   saxt   parse(   R   t   doct   xmlt   handler(    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt   from_xml  s    c         C  s   |  j  j |  ƒ S(   s<   
        Delete this domain, and all items under it
        (   R   t   delete_domain(   R   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt   delete  s    N(   t   __name__t
   __module__R   R	   R
   R   R   R   R   t   TrueR   R   t   FalseR   R!   R#   R   R)   R+   R,   R>   RF   RH   (    (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR      s(   					&%			$	t   DomainMetaDatac           B  s&   e  Z d d  „ Z d „  Z d „  Z RS(   c         C  sC   | |  _  d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   R(   R   t
   item_countt   item_names_sizet   attr_name_countt   attr_names_sizet   attr_value_countt   attr_values_size(   R   R(   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR	     s    						c         C  s   d  S(   N(   R   (   R   R   R   R   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR   (  s    c         C  sà   | d k r t  | ƒ |  _ n¾ | d k r< t  | ƒ |  _ n  | d k rZ t  | ƒ |  _ n‚ | d k rx t  | ƒ |  _ nd | d k r– t  | ƒ |  _ nF | d k r´ t  | ƒ |  _ n( | d k rÌ | |  _ n t |  | | ƒ d  S(   Nt	   ItemCountt   ItemNamesSizeBytest   AttributeNameCountt   AttributeNamesSizeBytest   AttributeValueCountt   AttributeValuesSizeBytest	   Timestamp(	   t   intRN   RO   RP   RQ   RR   RS   t	   timestampR   (   R   R   R   R   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR   +  s    N(   RI   RJ   R   R	   R   R   (    (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyRM     s   		N(   t   ContentHandlerR@   c           B  s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s6   
    SAX parser for a domain that has been dumped
    c         C  s@   t  | ƒ |  _ d  |  _ i  |  _ d  |  _ d |  _ | |  _ d  S(   NR$   (   t   UploaderThreadt   uploaderR   t   item_idR   t	   attributeR   R(   (   R   R(   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR	   D  s    				c         C  s]   | d k r% | d |  _  i  |  _ n4 | d k rA | d |  _ n | d k rY d |  _ n  d  S(   Nt   Itemt   idRa   R   R$   (   R`   R   Ra   R   (   R   R   R   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR   L  s    c         C  s   |  j  | 7_  d  S(   N(   R   (   R   t   ch(    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt
   charactersU  s    c         C  s÷   | d k rx |  j  ró |  j ró |  j  j ƒ  } |  j j ƒ  } | |  j k rb |  j | j | ƒ qu | g |  j | <qó n{ | d k r× |  j |  j j |  j <t |  j j ƒ d k ró |  j j	 ƒ  t
 |  j ƒ |  _ qó n | d k ró |  j j	 ƒ  n  d  S(   NR   Rb   i   R   (   R   Ra   t   stripR   t   appendR_   R   R`   t   lent   startR^   R(   (   R   R   R   t	   attr_name(    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR   X  s    (   RI   RJ   t   __doc__R	   R   Re   R   (    (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR@   ?  s
   				(   t   ThreadR^   c           B  s    e  Z d  Z d „  Z d „  Z RS(   s   Uploader Threadc         C  s)   | |  _  i  |  _ t t |  ƒ j ƒ  d  S(   N(   t   dbR   t   superR^   R	   (   R   R(   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR	   o  s    		c         C  sz   y |  j  j |  j ƒ Wn? t d ƒ x/ |  j D]  } |  j  j | |  j | ƒ q1 Wn Xt d d d ƒt j j ƒ  d  S(   Ns5   Exception using batch put, trying regular put insteadt   .R/   R0   (   Rm   R   R   R3   R   t   syst   stdoutR9   (   R   R   (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt   runt  s    
"(   RI   RJ   Rk   R	   Rr   (    (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyR^   l  s   	(   t
   __future__R    t   boto.sdb.queryresultsetR   t   boto.compatR   t   objectR   RM   Rp   t   xml.sax.handlerR]   R@   t	   threadingRl   R^   (    (    (    s.   lib/python2.7/site-packages/boto/sdb/domain.pyt   <module>   s   ÿ ,