
    vKgX                         S SK r S SKJr  SSKJr  SSKJr  SSKJrJ	r	  SSK
JrJr  SS	KJr  SS
KJr  SSKJrJr  \ R(                  " \5      r " S S5      rg)    N)partial   )	docstring)ResourceLoadException   )ServiceActionWaiterAction)ResourceMetaServiceResource)CollectionFactory)ResourceModel)ResourceHandlerbuild_identifiersc                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS r SS jrSrg)ResourceFactory   a?  
A factory to create new :py:class:`~boto3.resources.base.ServiceResource`
classes from a :py:class:`~boto3.resources.model.ResourceModel`. There are
two types of lookups that can be done: one on the service itself (e.g. an
SQS resource) and another on models contained within the service (e.g. an
SQS Queue resource).
c                 .    [        5       U l        Xl        g N)r   _collection_factory_emitter)selfemitters     W/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/boto3/resources/factory.py__init__ResourceFactory.__init__%   s    #4#6     c                    [         R                  SUR                  U5        [        UUUR                  5      nSnUR
                  (       a%  UR                  R                  UR
                  5      nUR                  U5        [        UR                  US9nSU0nU R                  UUUUS9  U R                  UUUUS9  U R                  UUUUUS9  U R                  UUUS9  U R                  UUUUS9  U R                  UUUUS9  UnUR                  U:X  a  S	nUR                  S
-   U-   n[         /n	U R"                  b  U R"                  R%                  SU 3UU	US9  ['        [)        U5      [+        U	5      U5      $ )a  
Loads a resource from a model, creating a new
:py:class:`~boto3.resources.base.ServiceResource` subclass
with the correct properties and methods, named based on the service
and resource name, e.g. EC2.Instance.

:type resource_name: string
:param resource_name: Name of the resource to look up. For services,
                      this should match the ``service_name``.

:type single_resource_json_definition: dict
:param single_resource_json_definition:
    The loaded json of a single service resource or resource
    definition.

:type service_context: :py:class:`~boto3.utils.ServiceContext`
:param service_context: Context about the AWS service

:rtype: Subclass of :py:class:`~boto3.resources.base.ServiceResource`
:return: The service or resource class.
zLoading %s:%sN)resource_modelmeta)attrsr   resource_namer   )r    r!   r   service_context)r    r   r!   r   r"   )r    r   r"   r   .zcreating-resource-class.)class_attributesbase_classesr"   )loggerdebugservice_namer   resource_json_definitionsshapeservice_model	shape_forload_rename_mapr
   _load_identifiers_load_actions_load_attributes_load_collections_load_has_relations_load_waitersr   r   emittypestrtuple)
r   r!   single_resource_json_definitionr"   r   r*   r   r    cls_namer%   s
             r   load_from_definition$ResourceFactory.load_from_definition)   s   0 	_99=	

 '+55
 #11;;$$E 	&&u- ((
 D
 	')	 	 	
 	')+	 	 	
 	')+ 	 	
 	)+ 	 	
 	  ')+	 	! 	
 	')+	 	 	
 !''=8(H"//#5@'(==$MM*8*5!&) /	   CM5#6>>r   c                     UR                    HE  nUR                   R                  UR                  5        U R                  XT5      XR                  '   MG     g)z
Populate required identifiers. These are arguments without which
the resource cannot be used. Identifiers become arguments for
operations on the resource.
N)identifiersappendname_create_identifier)r   r    r   r   r!   
identifiers         r   r.   !ResourceFactory._load_identifiers   sF     )44J##JOO4%)%<%<&E//" 5r   c                     UR                   (       a'  U R                  UR                   UUSS9US'   US   US'   UR                   H   nU R                  UUUS9XR                  '   M"     g)z
Actions on the resource become methods, with the ``load`` method
being a special case which sets internal data for attributes, and
``reload`` is an alias for ``load``.
T)action_modelr!   r"   is_loadloadreload)rD   r!   r"   N)rF   _create_actionactionsr?   )r   r    r!   r   r"   actions         r   r/   ResourceFactory._load_actions   s|      //+00+ /	 0 E&M $FmE(O$,,F!%!4!4#+ / "5 "E++ -r   c           	         UR                   (       d  gUR                  R                  UR                   5      nUR                   Vs0 sH#  nUR                  (       d  M  UR                  U_M%     nnUR                  U5      n	U	R                  5        H9  u  n
u  pX;   a  U R                  UX   UUS9nOU R                  UUU
UUS9nXU
'   M;     gs  snf )z
Load resource attributes based on the resource shape. The shape
name is referenced in the resource JSON, but the shape itself
is defined in the Botocore service JSON, hence the need for
access to the ``service_model``.
N)r!   rA   member_modelr"   )r!   r?   snake_casedrM   r"   )	r*   r+   r,   r=   member_nameget_attributesitems_create_identifier_alias_create_autoload_property)r   r    r   r!   r   r"   r*   ir=   
attributesr?   	orig_namememberprops                 r   r0    ResourceFactory._load_attributes   s     ##--778L8LM $//
/}} AMM1/ 	 

 $2259
)3)9)9);%D%9"44"/*0!'$3	 5  55"/" $!'$3 6  $K! *<
s   CCc                 x    UR                    H*  nU R                  UR                  UUS9XR                  '   M,     g)z
Load resource collections from the model. Each collection becomes
a :py:class:`~boto3.resources.collection.CollectionManager` instance
on the resource instance, which allows you to iterate and filter
through the collection's items.
)r!   collection_modelr"   N)collections_create_collectionr?   )r   r    r   r"   r[   s        r   r1   !ResourceFactory._load_collections   sC     !/ : :+/+B+B,11!1 / ,C ,E''( !;r   c                     UR                    H   nU R                  UUUS9XR                  '   M"     UR                   H   nU R	                  UUUS9XR                  '   M"     U R                  XR                  5        g)a  
Load related resources, which are defined via a ``has``
relationship but conceptually come in two forms:

1. A reference, which is a related resource instance and can be
   ``None``, such as an EC2 instance's ``vpc``.
2. A subresource, which is a resource constructor that will always
   return a resource instance which shares identifiers/data with
   this resource, such as ``s3.Bucket('name').Object('key')``.
)reference_modelr!   r"   )subresource_modelr!   r"   N)
references_create_referencer?   subresources_create_class_partial&_create_available_subresources_command)r   r    r!   r   r"   	referencesubresources          r   r2   #ResourceFactory._load_has_relations   s     (22I %)$:$: )+ / %; %E..!	 3 *66K '+&@&@"-+ / 'A 'E""# 7 	33..	
r   c                 p   ^ U Vs/ sH  o3R                   PM     snm[        T5      mU4S jnXAS'   g s  snf )Nc                    > T$ )z
Returns a list of all the available sub-resources for this
Resource.

:returns: A list containing the name of each sub-resource for this
    resource
:rtype: list of str
 )factory_self_subresourcess    r   get_available_subresourcesZResourceFactory._create_available_subresources_command.<locals>.get_available_subresources   s     ! r   ro   )r?   sorted)r   r    rd   rh   ro   rn   s        @r   rf   6ResourceFactory._create_available_subresources_command  s<    =IJ\k))\J}-		! /I*+ Ks   3c                 d    UR                    H   nU R                  UUUS9XR                  '   M"     g)z
Load resource waiters from the model. Each waiter allows you to
wait until a resource reaches a specific state by polling the state
of the resource.
)resource_waiter_modelr!   r"   N)waiters_create_waiterr?   )r   r    r!   r   r"   waiters         r   r3   ResourceFactory._load_waiters-  s9     %,,F!%!4!4&,+ / "5 "E++ -r   c                    ^ U4S jn[        TR                  5      Ul        [        R                  " UTSS9Ul        [        U5      $ )z9
Creates a read-only property for identifier attributes.
c                 8   > [        U STR                  -   S 5      $ N_getattrr?   r   rA   s    r   get_identifier:ResourceFactory._create_identifier.<locals>.get_identifierA  s     4z!6==r   F)r!   identifier_modelinclude_signature)r6   r?   __name__r   IdentifierDocstring__doc__property)rm   rA   r!   r   s    `  r   r@   "ResourceFactory._create_identifier<  sD    
	> #&joo"6!*!>!>''#"
 ''r   c           	         ^ U4S jn[        TR                  5      Ul        [        R                  " UR
                  UTR                  U R                  USS9Ul        [        U5      $ )z:
Creates a read-only property that aliases an identifier.
c                 8   > [        U STR                  -   S 5      $ r{   r}   r   s    r   r   @ResourceFactory._create_identifier_alias.<locals>.get_identifierZ  s    4z!6==r   Fr(   r!   	attr_nameevent_emitter
attr_modelr   )	r6   rO   r   r   AttributeDocstringr(   r   r   r   )rm   r!   rA   rM   r"   r   s     `   r   rR   (ResourceFactory._create_identifier_aliasS  sa    	> #&j&<&<"=!*!=!=(55' ,,&//##"
 ''r   c           	         ^ U4S jn[        U5      Ul        [        R                  " UR                  UUU R
                  USS9Ul        [        U5      $ )zr
Creates a new property on the resource to lazy-load its value
via the resource's ``load`` method (if it exists).
c                   > U R                   R                  cD  [        U S5      (       a  U R                  5         O"[	        U R
                  R                   S35      eU R                   R                  R                  T5      $ )NrF   z has no load method)r   datahasattrrF   r   	__class__r   get)r   r?   s    r   property_loaderBResourceFactory._create_autoload_property.<locals>.property_loaderz  se    yy~~%4((IIK/>>2233FG  99>>%%d++r   Fr   )r6   r   r   r   r(   r   r   r   )rm   r!   r?   rN   rM   r"   r   s     `    r   rS   )ResourceFactory._create_autoload_propertyi  sU    "		, $'{#3 "+">">(55'!&//###
 ((r   c           	         ^ [        UUR                  S9mU4S jn[        UR                  5      Ul        [        R
                  " UU R                  UR                  UUR                  SS9Ul	        U$ )z`
Creates a new wait method for each resource where both a waiter and
resource model is defined.
)waiter_resource_namec                    > T" U /UQ70 UD6  g r   rl   )r   argskwargsrw   s      r   	do_waiter1ResourceFactory._create_waiter.<locals>.do_waiter  s    4)$)&)r   F)r!   r   r+   rt   service_waiter_modelr   )
r	   r?   r6   r   r   ResourceWaiterDocstringr   r+   r   r   )rm   rt   r!   r"   r   rw   s        @r   rv   ResourceFactory._create_waiter  su     !!6!;!;

	* !!6!;!;<	%=='&//)77"7!0!E!E#
	 r   c                    ^ ^^^ T R                   R                  UTTT R                  S9mUUU U4S jn[        TR                  5      Ul        [        R                  " TSS9Ul        [        U5      $ )zC
Creates a new property on the resource to lazy-load a collection.
)r!   r[   r"   r   c                    > T" TU TTS9$ )N)r[   parentfactoryr"   rl   )r   clsr[   rm   r"   s    r   get_collection:ResourceFactory._create_collection.<locals>.get_collection  s    !1$ /	 r   F)r[   r   )
r   r:   r   r6   r?   r   r   CollectionDocstringr   r   )rm   r!   r[   r"   r   r   s   ` `` @r   r]   "ResourceFactory._create_collection  sx     ..CC'-+&//	 D 
	 	 #&&6&;&;"<!*!>!>-"
 ''r   c                 2  ^^ [        UR                  R                  U UR                  US9m[        S UR                  R                   5       5      mUU4S jn[        UR                  5      Ul        [        R                  " USS9Ul
        [        U5      $ )zB
Creates a new property on the resource to lazy-load a reference.
)search_pathr   r   r"   c              3   <   #    U H  oR                   S :H  v   M     g7f)r   N)source).0rT   s     r   	<genexpr>4ResourceFactory._create_reference.<locals>.<genexpr>  s      
(L1HH(Ls   c                    > T(       a8  U R                   R                  c!  [        U S5      (       a  U R                  5         T" U 0 U R                   R                  5      $ NrF   )r   r   r   rF   )r   handler
needs_datas    r   get_reference8ResourceFactory._create_reference.<locals>.get_reference  sA     diinn4v9N9N		4TYY^^44r   F)r`   r   )r   resourcepathanyr=   r6   r?   r   r   ReferenceDocstringr   r   )rm   r`   r!   r"   r   r   r   s        @@r   rc   !ResourceFactory._create_reference  s     "'0055 *33+	
  
(7(@(@(L(L
 


	5 "%_%9%9!: ) < <+u!
 &&r   c                    ^ ^^^ TR                   R                  mU UUU4S jn[        T5      Ul        [        R
                  " UTTR                  SS9Ul        U$ )z
Creates a new method which acts as a functools.partial, passing
along the instance's low-level `client` to the new resource
class' constructor.
c                 0  > / nTR                   R                  T
0 5      nT	R                  T
UTS9nTR                  R                  nUb%  [        X`5       H  u  pxUR                  U5        M     [        U/UQ7SU R                  R                  06" U0 UD6$ )N)r!   r8   r"   client)
r)   r   r:   r   r=   r   r>   r   r   r   )r   r   r   positional_argsjson_defresource_clsr=   rA   valuerm   r?   r"   ra   s            r   create_resource>ResourceFactory._create_class_partial.<locals>.create_resource  s     !O '@@DDT2NH'<<"08 / = L ,44@@K&):;)M%J#**51 *N .7;yy7G7G r   F)r!   sub_resource_modelr+   r   )r   r5   r6   r   r   SubResourceDocstringr+   r   )rm   ra   r!   r"   r   r?   s   `` ` @r   re   %ResourceFactory._create_class_partial  s[     !))..	 	6 $'t9 "+"@"@'0)77#	#
 r   c           	      J  ^ [        XUS9mU(       a>  U4S jn[        R                  " UR                  UU R                  UUR
                  SS9nO2U4S jn[        R                  " UU R                  UUR
                  SS9n[        UR                  5      Ul        Xel	        U$ )zK
Creates a new method which makes a request to the underlying
AWS service.
)r   r"   c                 >   > T" U /UQ70 UD6nX0R                   l        g r   )r   r   r   r   r   responserJ   s       r   	do_action1ResourceFactory._create_action.<locals>.do_action4  s     !$888!)		r   F)action_namer!   r   
load_modelr+   r   c                 d   > T" U /UQ70 UD6n[        U S5      (       a  S U R                  l        U$ r   )r   r   r   r   s       r   r   r   D  s6    !$8884(( &*DIINr   )r!   r   rD   r+   r   )
r   r   LoadReloadDocstringr?   r   r+   ActionDocstringr6   r   r   )rm   rD   r!   r"   rE   r   lazy_docstringrJ   s          @r   rH   ResourceFactory._create_action  s     
 *
 '::(--+*33'-;;"'N	  '66+*33)-;;"'N !!2!23	*r   )r   r   N)F)r   
__module____qualname____firstlineno__r   r   r:   r.   r/   r0   r1   r2   rf   r3   r@   rR   rS   rv   r]   rc   re   rH   __static_attributes__rl   r   r   r   r      si     u?n
0$L"
HI"(.(,&)P4(6''R,f <r   r   )logging	functoolsr   docsr   
exceptionsr   rJ   r   r	   baser
   r   
collectionr   modelr   r   r   r   	getLoggerr   r&   r   rl   r   r   <module>r      s>       . / / )   8			8	$} }r   