o ckF[e@sddlZddlZddlZddlmZddlmZddlmZm Z ddl m Z ddl m Z ddlmZGdd d ejZGd d d eZdS) N)handler)AWSQueryConnection)DomainDomainMetaData)Item) SDBRegionInfo)SDBResponseErrorcs(eZdZdZfddZddZZS) ItemThreadaj 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. cs0tt|j|d||_t|_||_g|_dS)a :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. )nameN)superr __init__ domain_name SDBConnectionconn item_namesitems)selfr r r __class__5/usr/lib/python3/dist-packages/boto/sdb/connection.pyr (s   zItemThread.__init__cCs,|jD]}|j|j|}|j|qdS)z Start the threaded retrieval of items. Populates the ``items`` list with :class:`Item ` objects. N)rrget_attributesr rappend)r item_nameitemrrrrun9s zItemThread.run)__name__ __module__ __qualname____doc__r r __classcell__rrrrr s r cs eZdZdZdZdZdZeZ      d8fd d Z d d Z d dZ  d9ddZ ddZ d:ddZddZddZddZd;ddZd;dd Zdd/d0Z  d` 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`. z us-east-1zsdb.us-east-1.amazonaws.comz 2009-04-15NTr/cs| stjdd|j}tjD] }|j|kr|} nq| |_tt |j |||||||||jj | | | |||dd|_ | |_ t|_dS)aZ 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 SDBregion)security_tokenvalidate_certs profile_namegN)botoconfiggetDefaultRegionNamesdbregionsr r#r rr endpoint box_usage converterritem_cls)raws_access_key_idaws_secret_access_key is_secureportproxy proxy_port proxy_user proxy_passdebughttps_connection_factoryr#pathr/r$r%r& region_nameregrrrr Ts*    zSDBConnection.__init__cCsdgS)Nr+rrrrr_required_auth_capabilitysz'SDBConnection._required_auth_capabilitycCs ||_dS)a 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)r0)rclsrrr set_item_clss zSDBConnection.set_item_clsF Attributec Cst|}d}|D]_}||}t|trB|D])} ||d||f<|jr*|j| } | |d||f<|rrrr get_usages zSDBConnection.get_usagecCs(td|j|jd}td|dS)a 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. zTotal Usage: %f compute secondsgQ?zApproximate Cost: $%fN)printr.)rcostrrr print_usages zSDBConnection.print_usagecCs"t||}|r||d||S)a 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 zselect * from `%s` limit 1)rselectrr validatedomainrrr get_domains zSDBConnection.get_domaincCs$z |||}W|Sd}Y|S)a 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)rerbrrrlookups zSDBConnection.lookupcCs0i}|r||d<|r||d<|d|dtfgS)aI Returns a :py:class:`boto.resultset.ResultSet` containing all :py:class:`boto.sdb.domain.Domain` objects associated with this connection's Access Key ID. :keyword int max_domains: Limit the returned :py:class:`ResultSet ` 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. MaxNumberOfDomains NextToken ListDomains DomainName)get_listr)r max_domains next_tokenrJrrrget_all_domainss zSDBConnection.get_all_domainscCs d|i}|d|t}||_|S)z 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 rj CreateDomain) get_objectrr )rr rJdrrr create_domain6s zSDBConnection.create_domaincCs"t|tr ||jfS|||fS)a 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. )rGrr re)rdomain_or_namerrrget_domain_and_nameEs  z!SDBConnection.get_domain_and_namecCs"||\}}d|i}|d|S)aX 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 rj DeleteDomain)rt get_status)rrsrdr rJrrr delete_domain]s  zSDBConnection.delete_domaincCs.||\}}d|i}|d|t}||_|S)aR 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 rjDomainMetadata)rtrprrd)rrsrdr rJrqrrrdomain_metadatans  zSDBConnection.domain_metadatac CsB||\}}||d}|||||r||||d|S)a 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 rjItemName PutAttributes)rtrRrUrv) rrsrrKrLrTrdr rJrrrput_attributes~s(  zSDBConnection.put_attributescCs4||\}}d|i}|||||jd|ddS)a| 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 rjBatchPutAttributesPOSTverbrtrYrv)rrsrrLrdr rJrrrbatch_put_attributessz"SDBConnection.batch_put_attributesc Cs||\}}||d}|rd|d<|r#t|ts|g}|||d|d|} | } | jdkrK|dur<|||}t ||} t j | | |St | j| j| )a  Retrieve 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 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. :type consistent_read: bool :param consistent_read: When set to true, ensures that the most recent data is returned. :type item: :class:`boto.sdb.item.Item` :keyword item: Instead of instantiating a new Item object, you may specify one to update. :rtype: :class:`boto.sdb.item.Item` :return: An Item with the requested attribute name/values set on it rzrDConsistentRead AttributeName GetAttributesN)rtrGrHbuild_list_params make_requestreadstatusr0r XmlHandlerxmlsax parseStringrreason) rrsrr[consistent_readrrdr rJresponsebodyhrrrrs&     zSDBConnection.get_attributescCsr||\}}||d}|r+t|tr|||nt|ts%t||jr+||||r3||||d|S)a 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 rzDeleteAttributes) rtrGrHr\dictr0rRrUrv)rrsrrWrTrdr rJrrrdelete_attributess)    zSDBConnection.delete_attributescCs4||\}}d|i}|||d|jd|ddS)a] 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 rjFBatchDeleteAttributesrrr)rrsrrdr rJrrrbatch_delete_attributes.sz%SDBConnection.batch_delete_attributesc Csx||\}}d|i}|rd|d<|r||d<z|jd|d|jfg|dWSty;}z d||jf|_|d }~ww) a 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. Even though the select request does not require a domain object, a domain object must be passed into this method so the Item objects returned can point to the appropriate 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 query: string :param query: The SimpleDB query to be performed. :type consistent_read: bool :param consistent_read: When set to true, ensures that the most recent data is returned. :rtype: ResultSet :return: An iterator containing the results. SelectExpressionrDrrhSelectr)parentz Query: %s %sN)rtrkr0rr) rrsqueryrmrrdr rJerrrraHszSDBConnection.select)NNTNNNNNrNNr!NNTN)FrB)F)T)NN)TN)NFN)rNF) rrrrr*DefaultRegionEndpoint APIVersionr ResponseErrorr r?rArRrUrYr\r]r`rerfrnrrrtrwryr}rrrrrar rrrrrDsV +       0 0 5r)xml.saxr threadingr'rboto.connectionrboto.sdb.domainrr boto.sdb.itemrboto.sdb.regioninforboto.exceptionrThreadr rrrrrs     %