ó FRTc@s½ddlZddlZddlZddlmZddlmZddlmZm Z ddl m Z ddl m Z ddlmZdejfd „ƒYZd efd „ƒYZdS( iÿÿÿÿN(thandler(tAWSQueryConnection(tDomaintDomainMetaData(tItem(t SDBRegionInfo(tSDBResponseErrort ItemThreadcBs eZdZd„Zd„ZRS(sj A threaded :class:`Item ` retriever utility class. Retrieved :class:`Item ` objects are stored in the ``items`` instance variable after :py:meth:`run() ` is called. .. tip:: The item retrieval will not start until the :func:`run() ` method is called. cCsDtt|ƒjd|ƒ||_tƒ|_||_g|_dS(s¾ :param str name: A thread name. Used for identification. :param str domain_name: The name of a SimpleDB :class:`Domain ` :type item_names: string or list of strings :param item_names: The name(s) of the items to retrieve from the specified :class:`Domain `. :ivar list items: A list of items retrieved. Starts as empty list. tnameN(tsuperRt__init__t domain_namet SDBConnectiontconnt item_namestitems(tselfRR R((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pyR (s    cCs@x9|jD].}|jj|j|ƒ}|jj|ƒq WdS(sŽ Start the threaded retrieval of items. Populates the ``items`` list with :class:`Item ` objects. N(RR tget_attributesR Rtappend(Rt item_nametitem((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pytrun9s(t__name__t __module__t__doc__R R(((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pyRs R cBsReZdZdZdZdZeZdde ddddddddddde dd„Z d„Z d„Z e d d „Zd „Ze d „Zd „Zd„Zd„Ze d„Ze d„Zddd„Zd„Zd„Zd„Zd„Ze dd„Ze d„Zde dd„Zddd„Zd„Zdde d„Z RS(sˆ This class serves as a gateway to your SimpleDB region (defaults to us-east-1). Methods within allow access to SimpleDB :class:`Domain ` objects and their associated :class:`Item ` objects. .. tip:: While you may instantiate this class directly, it may be easier to go through :py:func:`boto.connect_sdb`. s us-east-1ssdb.us-east-1.amazonaws.coms 2009-04-15it/cCsÎ| sWtjjdd|jƒ}x3tjjƒD]}|j|kr1|} Pq1q1Wn| |_tt |ƒj |||||||||jj | | | d|d|d|ƒ d|_ | |_ t|_dS(sZ For any keywords that aren't documented, refer to the parent class, :py:class:`boto.connection.AWSAuthConnection`. You can avoid having to worry about these keyword arguments by instantiating these objects via :py:func:`boto.connect_sdb`. :type region: :class:`boto.sdb.regioninfo.SDBRegionInfo` :keyword region: Explicitly specify a region. Defaults to ``us-east-1`` if not specified. You may also specify the region in your ``boto.cfg``: .. code-block:: cfg [SDB] region = eu-west-1 tSDBtregiontsecurity_tokentvalidate_certst profile_namegN(tbototconfigtgettDefaultRegionNametsdbtregionsRRR R R tendpointt box_usaget converterRtitem_cls(Rtaws_access_key_idtaws_secret_access_keyt is_securetporttproxyt proxy_portt proxy_usert proxy_passtdebugthttps_connection_factoryRtpathR'RRRt region_nametreg((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pyR Ts&        cCsdgS(NR#((R((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pyt_required_auth_capabilityscCs ||_dS(s While the default item class is :py:class:`boto.sdb.item.Item`, this default may be overridden. Use this method to change a connection's item class. :param object cls: The new class to set as this connection's item class. See the default item class for inspiration as to what your replacement should/could look like. N(R((Rtcls((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pyt set_item_cls‚s t Attributec Cs4t|jƒƒ}d}x|D] }||}t|tƒr¿xá|D]s} ||d||f<|jr}|jj| ƒ} n| |d||f<|r®d|d||fR'R?( RR@RRBRRDRtjRt attr_namest attr_nameRFRG((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pyt_build_batch_list¯s6          cCs=d}|jƒx&|D]}||d|<|d7}qWdS(NisAttribute.%d.Name(tsort(RR@tattribute_namesRDR((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pyt_build_name_listÍs   cCs|jS(så Returns the BoxUsage (in USD) accumulated on this specific SDBConnection instance. .. tip:: This can be out of date, and should only be treated as a rough estimate. Also note that this estimate only applies to the requests made on this specific connection instance. It is by no means an account-wide estimate. :rtype: float :return: The accumulated BoxUsage of all requests made on the connection. (R&(R((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pyt get_usageÔs cCs&d|jGH|jd}d|GHdS(s Print the BoxUsage and approximate costs of all requests made on this specific SDBConnection instance. .. tip:: This can be out of date, and should only be treated as a rough estimate. Also note that this estimate only applies to the requests made on this specific connection instance. It is by no means an account-wide estimate. sTotal Usage: %f compute secondsgìQ¸…ëÁ?sApproximate Cost: $%fN(R&(Rtcost((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pyt print_usageãs  cCs0t||ƒ}|r,|j|d|ƒn|S(sŽ Retrieves a :py:class:`boto.sdb.domain.Domain` object whose name matches ``domain_name``. :param str domain_name: The name of the domain to retrieve :keyword bool validate: When ``True``, check to see if the domain actually exists. If ``False``, blindly return a :py:class:`Domain ` object with the specified name set. :raises: :py:class:`boto.exception.SDBResponseError` if ``validate`` is ``True`` and no match could be found. :rtype: :py:class:`boto.sdb.domain.Domain` :return: The requested domain sselect * from `%s` limit 1(Rtselect(RR tvalidatetdomain((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pyt get_domainñscCs*y|j||ƒ}Wn d}nX|S(sÕ Lookup an existing SimpleDB domain. This differs from :py:meth:`get_domain` in that ``None`` is returned if ``validate`` is ``True`` and no match was found (instead of raising an exception). :param str domain_name: The name of the domain to retrieve :param bool validate: If ``True``, a ``None`` value will be returned if the specified domain can't be found. If ``False``, a :py:class:`Domain ` object will be dumbly returned, regardless of whether it actually exists. :rtype: :class:`boto.sdb.domain.Domain` object or ``None`` :return: The Domain object or ``None`` if the domain does not exist. N(R\RN(RR RZR[((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pytlookups  cCsHi}|r||d` to the specified number of members. :keyword str next_token: A token string that was returned in an earlier call to this method as the ``next_token`` attribute on the returned :py:class:`ResultSet ` object. This attribute is set if there are more than Domains than the value specified in the ``max_domains`` keyword. Pass the ``next_token`` value from you earlier query in this keyword to get the next 'page' of domains. tMaxNumberOfDomainst NextTokent ListDomainst DomainName(tget_listR(Rt max_domainst next_tokenR@((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pytget_all_domainss   cCs/i|d6}|jd|tƒ}||_|S(sç Create a SimpleDB domain. :type domain_name: string :param domain_name: The name of the new domain :rtype: :class:`boto.sdb.domain.Domain` object :return: The newly created domain Rat CreateDomain(t get_objectRR(RR R@td((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pyt create_domain6s  cCs3t|tƒr||jfS|j|ƒ|fSdS(s’ Given a ``str`` or :class:`boto.sdb.domain.Domain`, return a ``tuple`` with the following members (in order): * In instance of :class:`boto.sdb.domain.Domain` for the requested domain * The domain's name as a ``str`` :type domain_or_name: ``str`` or :class:`boto.sdb.domain.Domain` :param domain_or_name: The domain or domain name to get the domain and name for. :raises: :class:`boto.exception.SDBResponseError` when an invalid domain name is specified. :rtype: tuple :return: A ``tuple`` with contents outlined as per above. N(R=RRR\(Rtdomain_or_name((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pytget_domain_and_nameEs cCs2|j|ƒ\}}i|d6}|jd|ƒS(sX Delete a SimpleDB domain. .. caution:: This will delete the domain and all items within the domain. :type domain_or_name: string or :class:`boto.sdb.domain.Domain` object. :param domain_or_name: Either the name of a domain or a Domain object :rtype: bool :return: True if successful Rat DeleteDomain(Rkt get_status(RRjR[R R@((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pyt delete_domain]s  cCsD|j|ƒ\}}i|d6}|jd|tƒ}||_|S(sR Get the Metadata for a SimpleDB domain. :type domain_or_name: string or :class:`boto.sdb.domain.Domain` object. :param domain_or_name: Either the name of a domain or a Domain object :rtype: :class:`boto.sdb.domain.DomainMetaData` object :return: The newly created domain metadata object RatDomainMetadata(RkRgRR[(RRjR[R R@Rh((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pytdomain_metadatans   c Cse|j|ƒ\}}i|d6|d6}|j|||ƒ|rU|j||ƒn|jd|ƒS(sÀ Store attributes for a given item in a domain. :type domain_or_name: string or :class:`boto.sdb.domain.Domain` object. :param domain_or_name: Either the name of a domain or a Domain object :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 RatItemNamet PutAttributes(RkRHRMRm( RRjRRARBRLR[R R@((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pytput_attributes~s(  cCsK|j|ƒ\}}i|d6}|j|||ƒ|jd|ddƒS(s| Store attributes for multiple items in a domain. :type domain_or_name: string or :class:`boto.sdb.domain.Domain` object. :param domain_or_name: Either the name of a domain or a Domain object :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 RatBatchPutAttributestverbtPOST(RkRRRm(RRjRRBR[R R@((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pytbatch_put_attributes®s c Cs|j|ƒ\}}i|d6|d6}|r<d|dtbuild_list_paramst make_requesttreadtstatusRNR(Rt XmlHandlertxmltsaxt parseStringRtreason( RRjRRTtconsistent_readRR[R R@tresponsetbodyth((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pyRÉs$      cCs±|j|ƒ\}}i|d6|d6}|rˆt|tƒrQ|j||ƒqˆt|tƒsrt||jƒrˆ|j||ƒqˆn|r¡|j||ƒn|jd|ƒS(sŽ Delete attributes from a given item in a domain. :type domain_or_name: string or :class:`boto.sdb.domain.Domain` object. :param domain_or_name: Either the name of a domain or a Domain object :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 RaRqtDeleteAttributes( RkR=R>RUtdictR(RHRMRm(RRjRRPRLR[R R@((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pytdelete_attributesùs)  !cCsK|j|ƒ\}}i|d6}|j||tƒ|jd|ddƒS(s] Delete multiple items in a domain. :type domain_or_name: string or :class:`boto.sdb.domain.Domain` object. :param domain_or_name: Either the name of a domain or a Domain object :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. :return: True if successful RatBatchDeleteAttributesRuRv(RkRRRKRm(RRjRR[R R@((s@/opt/freeware/lib/python2.7/site-packages/boto/sdb/connection.pytbatch_delete_attributes.s tc Cs§|j|ƒ\}}i|d6}|r5d|ds   %