ó T!¶\c@sÍddlZddlZddlmZddlmZddlmZddlm Z ddl m Z dd l m Z ejeƒZd efd „ƒYZd efd „ƒYZdefd„ƒYZdS(iÿÿÿÿN(t xform_name(t merge_dictsi(t BatchAction(tcreate_request_parameters(tResourceHandleri(t docstringtResourceCollectioncBs_eZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z RS( s¸ Represents a collection of resources, which can be iterated through, optionally with filtering. Collections automatically handle pagination for you. See :ref:`guide_collections` for a high-level overview of collections, including when remote service requests are performed. :type model: :py:class:`~boto3.resources.model.Collection` :param model: Collection model :type parent: :py:class:`~boto3.resources.base.ServiceResource` :param parent: The collection's parent resource :type handler: :py:class:`~boto3.resources.response.ResourceHandler` :param handler: The resource response handler used to create resource instances cKsF||_||_t|jjƒ|_||_tj|ƒ|_ dS(N( t_modelt_parentRtrequestt operationt_py_operation_namet_handlertcopytdeepcopyt_params(tselftmodeltparentthandlertkwargs((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyt__init__.s    cCs:dj|jj|jdj|jjj|jjjƒƒS(Ns {0}({1}, {2})s{0}.{1}( tformatt __class__t__name__Rtmetat service_nameRtresourcettype(R((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyt__repr__6s   ccsr|jjddƒ}d}xP|jƒD]B}x9|D]1}|V|d7}|dk r5||kr5dSq5Wq(WdS(sÁ A generator which yields resource instances after doing the appropriate service operation calls and handling any pagination on your behalf. Page size, item limit, and filter parameters are applied if they have previously been set. >>> bucket = s3.Bucket('boto3') >>> for obj in bucket.objects.all(): ... print(obj.key) 'key1' 'key2' tlimitiiN(RtgettNonetpages(RRtcounttpagetitem((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyt__iter__@s  cKsJtj|jƒ}t||dtƒ|j|j|j|j|}|S(sO Create a clone of this collection. This is used by the methods below to provide a chainable interface that returns copies rather than the original. This allows things like: >>> base = collection.filter(Param1=1) >>> query1 = base.filter(Param2=2) >>> query2 = base.filter(Param3=3) >>> query1.params {'Param1': 1, 'Param2': 2} >>> query2.params {'Param1': 1, 'Param3': 3} :rtype: :py:class:`ResourceCollection` :return: A clone of this resource collection t append_lists( R RRRtTrueRRRR (RRtparamstclone((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyt_clone]s c cs®|jjj}|jjƒ}|jdd ƒ}|jdd ƒ}t|j|jj ƒ}t ||dt ƒ|j |j ƒrÙtjd|jjj|j |ƒ|j|j ƒ}|jdi|d6|d6|}n=tjd|jjj|j |ƒt||j ƒ|g}d }x‹|D]ƒ} g} xS|j|j|| ƒD]9} | j| ƒ|d 7}|d k rH||krHPqHqHW| V|d k r#||kr#Pq#q#Wd S( sª A generator which yields pages of resource instances after doing the appropriate service operation calls and handling any pagination on your behalf. Non-paginated calls will return a single page of items. Page size, item limit, and filter parameters are applied if they have previously been set. >>> bucket = s3.Bucket('boto3') >>> for page in bucket.objects.pages(): ... for obj in page: ... print(obj.key) 'key1' 'key2' :rtype: list(:py:class:`~boto3.resources.base.ServiceResource`) :return: List of resource instances Rt page_sizeR&sCalling paginated %s:%s with %rtPaginationConfigtMaxItemstPageSizesCalling %s:%s with %riiN(RRtclientRR tpopR RRR RR't can_paginateR tloggertdebugRt get_paginatortpaginatetgetattrR tappend( RR/tcleaned_paramsRR+R(t paginatorR!R"R#t page_itemsR$((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyR!ts<          cCs |jƒS(s Get all items from the collection, optionally with a custom page size and item count limit. This method returns an iterable generator which yields individual resource instances. Example use:: # Iterate through items >>> for queue in sqs.queues.all(): ... print(queue.url) 'https://url1' 'https://url2' # Convert to list >>> queues = list(sqs.queues.all()) >>> len(queues) 2 (R*(R((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pytall·scKs |j|S(s¬ Get items from the collection, passing keyword arguments along as parameters to the underlying service operation, which are typically used to filter the results. This method returns an iterable generator which yields individual resource instances. Example use:: # Iterate through items >>> for queue in sqs.queues.filter(Param='foo'): ... print(queue.url) 'https://url1' 'https://url2' # Convert to list >>> queues = list(sqs.queues.filter(Param='foo')) >>> len(queues) 2 :rtype: :py:class:`ResourceCollection` (R*(RR((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pytfilterÌscCs|jd|ƒS(s Return at most this many resources. >>> for bucket in s3.buckets.limit(5): ... print(bucket.name) 'bucket1' 'bucket2' 'bucket3' 'bucket4' 'bucket5' :type count: int :param count: Return no more than this many items :rtype: :py:class:`ResourceCollection` R(R*(RR"((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyRäscCs|jd|ƒS(s3 Fetch at most this many resources per service request. >>> for obj in s3.Bucket('boto3').objects.page_size(100): ... print(obj.key) :type count: int :param count: Fetch this many items per request :rtype: :py:class:`ResourceCollection` R+(R*(RR"((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyR+ös ( Rt __module__t__doc__RRR%R*R!R;R<RR+(((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyRs    C   tCollectionManagercBs§eZdZeZd„Zd„Zd„Zd„Zejje_d„Z ej je _d„Z ej je _d„Z ej je _d„Z ej je _RS( s A collection manager provides access to resource collection instances, which can be iterated and filtered. The manager exposes some convenience functions that are also found on resource collections, such as :py:meth:`~ResourceCollection.all` and :py:meth:`~ResourceCollection.filter`. Get all items:: >>> for bucket in s3.buckets.all(): ... print(bucket.name) Get only some items via filtering:: >>> for queue in sqs.queues.filter(QueueNamePrefix='AWS'): ... print(queue.url) Get whole pages of items: >>> for page in s3.Bucket('boto3').objects.pages(): ... for obj in page: ... print(obj.key) A collection manager is not iterable. You **must** call one of the methods that return a :py:class:`ResourceCollection` before trying to iterate, slice, or convert to a list. See the :ref:`guide_collections` guide for a high-level overview of collections, including when remote service requests are performed. :type collection_model: :py:class:`~boto3.resources.model.Collection` :param model: Collection model :type parent: :py:class:`~boto3.resources.base.ServiceResource` :param parent: The collection's parent resource :type factory: :py:class:`~boto3.resources.factory.ResourceFactory` :param factory: The resource factory to create new resources :type service_context: :py:class:`~boto3.utils.ServiceContext` :param service_context: Context about the AWS service c Cs^||_|jjj}||_|jj}td|d|d|jd|d|ƒ|_dS(Nt search_pathtfactorytresource_modeltservice_contexttoperation_name(RR R RRtpathRR (Rtcollection_modelRRARCRDR@((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyR2s     cCs:dj|jj|jdj|jjj|jjjƒƒS(Ns {0}({1}, {2})s{0}.{1}( RRRRRRRRR(R((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyR?s   cKs|j|j|j|j|S(s½ Get a resource collection iterator from this manager. :rtype: :py:class:`ResourceCollection` :return: An iterable representing the collection of resources (t_collection_clsRRR (RR((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pytiteratorIscCs |jƒS(N(RH(R((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyR;TscKs |j|S(N(RH(RR((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyR<XscCs|jd|ƒS(NR(RH(RR"((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyR\scCs|jd|ƒS(NR+(RH(RR"((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyR+`scCs|jƒjƒS(N(RHR!(R((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyR!ds( RR=R>RRGRRRHR;R<RR+R!(((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyR?s*     tCollectionFactorycBs2eZdZd„Zd„Zd„Zd„ZRS(só A factory to create new :py:class:`CollectionManager` and :py:class:`ResourceCollection` subclasses from a :py:class:`~boto3.resources.model.Collection` model. These subclasses include methods to perform batch operations. c Csi}|j}|j||||j|ƒ|jd|d|d|d|jd|dtƒ|j|krƒdj|j|ƒ}ndj|j||ƒ}tt|ƒtf|ƒ}|jd|d|d|d|jd|dt ƒ||d <|d 7}tt|ƒt f|ƒS( s Loads a collection from a model, creating a new :py:class:`CollectionManager` subclass with the correct properties and methods, named based on the service and resource name, e.g. ec2.InstanceCollectionManager. It also creates a new :py:class:`ResourceCollection` subclass which is used by the new manager class. :type resource_name: string :param resource_name: Name of the resource to look up. For services, this should match the ``service_name``. :type service_context: :py:class:`~boto3.utils.ServiceContext` :param service_context: Context about the AWS service :type event_emitter: :py:class:`~botocore.hooks.HierarchialEmitter` :param event_emitter: An event emitter :rtype: Subclass of :py:class:`CollectionManager` :return: The collection class. tattrst resource_nameRFt service_modelt event_emittert base_classs{0}.{1}Collections{0}.{1}.{2}CollectionRGtManager( tnamet_load_batch_actionsRLt#_load_documented_collection_methodsRRRRtstrR?( RRKRFRCRMRJtcollection_nametcls_nametcollection_cls((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pytload_from_definitionps6            cCsIxB|jD]7}t|jƒ}|j||||||ƒ||( t factory_selfRJRKRFRLRMRNR;R<RR+((RNs;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyRR¸sH            c sat|ƒ‰‡fd†}t|ƒ|_tjd|d|d|d|d|dtƒ|_|S(ss Creates a new method which makes a batch operation request to the underlying service API. csˆ|||ŽS(N((RtargsR(taction(s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyt batch_actionsRKRMtbatch_action_modelRLRFR](RRSRRtBatchActionDocstringR_R>(R`RKR[RZRFRLRMRc((Rbs;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyRYùs   (RR=R>RWRQRRRY(((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyRIis  < A(R tloggingtbotocoreRtbotocore.utilsRRbRR(RtresponseRtdocsRt getLoggerRR2tobjectRR?RI(((s;/tmp/pip-install-usGedi/boto3/boto3/resources/collection.pyts  çe