
    9 fh                        d dl Z d dlZd dlZddlmZmZmZ  ej        d          Z	 G d dej
                  Z G d de          Z G d	 d
e          Z G d de          Z G d de          Z G d d          ZefdZ G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d d          Z G d  d!e          Z G d" d#e          Z G d$ d%e          Z G d& d'          Z e            Z G d( d)e          Z G d* d+ej
                  Z G d, d-e          Z  G d. d/e          Z! G d0 d1ej"                  Z# G d2 d3e          Z$ G d4 d5e$          Z% G d6 d7e$          Z& G d8 d9e&          Z' G d: d;          Z( G d< d=e$          Z)dS )>    N   )enumserrorsutilszfactory.generatec                   Z     e Zd ZdZej        j        ZdZdZ	 fdZ
d Zd Zd Zd Z xZS )	BaseDeclarationzA factory declaration.

    Declarations mark an attribute as needing lazy evaluation.
    This allows them to refer to attributes defined by other BaseDeclarations
    in the same factory.
    FTc                 Z    t                                                       |pi | _        d S N)super__init__	_defaults)selfdefaults	__class__s     J/var/www/equiseq/venv/lib/python3.11/site-packages/factory/declarations.pyr   zBaseDeclaration.__init__    s(    !R    c                 B   t                      }|                    | j                   |                    |           | j        s|S t	          d |                                D                       s|S dd l}|j        j        }|	                    |||j
                  S )Nc              3   >   K   | ]}t          j        |          V  d S r
   )r   get_builder_phase).0vs     r   	<genexpr>z1BaseDeclaration.unroll_context.<locals>.<genexpr>+   s-      MM!5*1--MMMMMMr   r   force_sequence)dictupdater    UNROLL_CONTEXT_BEFORE_EVALUATIONanyvaluesfactory.basebaseDictFactoryrecursesequence)r   instancestepcontextfull_contextfactory
subfactorys          r   unroll_contextzBaseDeclaration.unroll_context$   s    vvDN+++G$$$4 	 MM|7J7J7L7LMMMMM 	 \-
||JT]|SSSr   c                `    t          |t                    r|                    |||          S |S )zEvaluate a wrapped pre-declaration.

        This is especially useful for declarations wrapping another one,
        e.g. Maybe or Transformer.
        r%   r&   	overrides)
isinstancer   evaluate_pre)r   wrappedr%   r&   r.   s        r   _unwrap_evaluate_prez$BaseDeclaration._unwrap_evaluate_pre3   sC     g// 	''!# (   
 r   c                 ^    |                      |||          }|                     |||          S r
   )r+   evaluate)r   r%   r&   r.   r'   s        r   r0   zBaseDeclaration.evaluate_preA   s/    %%hi@@}}XtW555r   c                      t          d          )a%  Evaluate this declaration.

        Args:
            instance (builder.Resolver): The object holding currently computed
                attributes
            step: a factory.builder.BuildStep
            extra (dict): additional, call-time added kwargs
                for the step.
        zThis is an abstract methodNotImplementedErrorr   r%   r&   extras       r   r4   zBaseDeclaration.evaluateE   s     "">???r   )__name__
__module____qualname____doc__r   BuilderPhaseATTRIBUTE_RESOLUTIONFACTORY_BUILDER_PHASECAPTURE_OVERRIDESr   r   r+   r2   r0   r4   __classcell__r   s   @r   r   r      s          ".C
  (,$( ( ( ( (T T T  6 6 6
@ 
@ 
@ 
@ 
@ 
@ 
@r   r   c                       e Zd ZdZdS )OrderedDeclarationCompatibilityN)r:   r;   r<   r=    r   r   rE   rE   R   s        r   rE   c                   (     e Zd ZdZ fdZd Z xZS )LazyFunctionzSimplest BaseDeclaration computed by calling the given function.

    Attributes:
        function (function): a function without arguments and
            returning the computed value.
    c                 V    t                                                       || _        d S r
   r   r   functionr   rL   r   s     r   r   zLazyFunction.__init__`   $     r   c                 l    t                               d| j        |           |                                 S )Nz!LazyFunction: Evaluating %r on %rloggerdebugrL   r8   s       r   r4   zLazyFunction.evaluated   s)    8$-NNN}}r   r:   r;   r<   r=   r   r4   rB   rC   s   @r   rI   rI   X   sQ         ! ! ! ! !      r   rI   c                   (     e Zd ZdZ fdZd Z xZS )LazyAttributezSpecific BaseDeclaration computed using a lambda.

    Attributes:
        function (function): a function, expecting the current LazyStub and
            returning the computed value.
    c                 V    t                                                       || _        d S r
   rK   rM   s     r   r   zLazyAttribute.__init__q   rN   r   c                 n    t                               d| j        |           |                     |          S )Nz"LazyAttribute: Evaluating %r on %rrP   r8   s       r   r4   zLazyAttribute.evaluateu   s-    94=(SSS}}X&&&r   rS   rC   s   @r   rU   rU   i   sQ         ! ! ! ! !' ' ' ' ' ' 'r   rU   c                   F     e Zd ZdZdZ G d d          Z fdZd Z xZS )TransformerTFc                       e Zd ZdZd Zd ZdS )Transformer.Forcez
        Bypass a transformer's transformation.

        The forced value can be any declaration, and will be evaluated as if it
        had been passed instead of the Transformer declaration.
        c                     || _         d S r
   )forced_value)r   r]   s     r   r   zTransformer.Force.__init__   s     ,Dr   c                 2    dt          | j                   dS )NzTransformer.Force())reprr]   r   s    r   __repr__zTransformer.Force.__repr__   s    BT->(?(?BBBBr   N)r:   r;   r<   r=   r   rb   rG   r   r   Forcer[   ~   sA        	 		- 	- 	-	C 	C 	C 	C 	Cr   rc   c                d    t                                                       || _        || _        d S r
   )r   r   default	transform)r   re   rf   r   s      r   r   zTransformer.__init__   s+    "r   c                     |                     d| j                  }t          || j                  r
d}|j        }nd}|                     ||||          }|r|S |                     |          S )N TFr-   )popre   r/   rc   r]   r2   rf   )r   r%   r&   r.   value_or_declarationbypass_transformvalues          r   r0   zTransformer.evaluate_pre   s    (}}R>>*DJ77 	%##7#D  $)) 	 * 
 
  	L~~e$$$r   )	r:   r;   r<   rA   r   rc   r   r0   rB   rC   s   @r   rY   rY   z   s        ',$C C C C C C C C# # # # #
% % % % % % %r   rY   c                       e Zd ZdS )_UNSPECIFIEDNr:   r;   r<   rG   r   r   rn   rn              Dr   rn   c                     	 d|v r8|                     dd          \  }}t          t          | |          ||          S t          | |          S # t          $ r |t          u r |cY S w xY w)a  Try to retrieve the given attribute of an object, digging on '.'.

    This is an extended getattr, digging deeper if '.' is found.

    Args:
        obj (object): the object of which an attribute should be read
        name (str): the name of an attribute to look up.
        default (object): the default value to use if the attribute wasn't found

    Returns:
        the attribute pointed to by 'name', splitting on '.'.

    Raises:
        AttributeError: if obj has no 'name' attribute.
    .r   )splitdeepgetattrgetattrAttributeErrorrn   )objnamere   attrsubnames        r   rt   rt      s     
$;; JJsA..MD'wsD117GDDD3%%%   l""NNN	s   ;A A A'&A'c                   2     e Zd ZdZef fd	Zd Zd Z xZS )SelfAttributea  Specific BaseDeclaration copying values from other fields.

    If the field name starts with two dots or more, the lookup will be anchored
    in the related 'parent'.

    Attributes:
        depth (int): the number of steps to go up in the containers chain
        attribute_name (str): the name of the attribute to copy.
        default (object): the default value to use if the attribute doesn't
            exist.
    c                     t                                                       t          |          t          |                    d                    z
  }||d          }|| _        || _        || _        d S )Nrr   )r   r   lenlstripdepthattribute_namere   )r   r   re   r   r   s       r   r   zSelfAttribute.__init__   si    N##c.*?*?*D*D&E&EE'/
,r   c                     | j         dk    r|j        | j         dz
           }n|}t                              d| j        |           t          || j        | j                  S )Nr   z)SelfAttribute: Picking attribute %r on %r)r   chainrQ   rR   r   rt   re   )r   r%   r&   r9   targets        r   r4   zSelfAttribute.evaluate   sX    :>>Z
Q/FFF@$BUW]^^^64#6EEEr   c                 B    d| j         j        d| j        d| j        dS )N<(z
, default=z)>)r   r:   r   re   ra   s    r   rb   zSelfAttribute.__repr__   s1     N###LLL
 	
r   )	r:   r;   r<   r=   rn   r   r4   rb   rB   rC   s   @r   r|   r|      sm        
 
 0<      F F F
 
 
 
 
 
 
r   r|   c                   0     e Zd ZdZd fd	Zd Zd Z xZS )Iteratora  Fill this value using the values returned by an iterator.

    Warning: the iterator should not end !

    Attributes:
        iterator (iterable): the iterator whose value should be used.
        getter (callable or None): a function to parse returned values
    TNc                     t                                                       || _        d | _        |rfd| _        d S fd| _        d S )Nc                  P    t          j        t          j                             S r
   )r   ResetableIterator	itertoolscycleiterators   r   <lambda>z#Iterator.__init__.<locals>.<lambda>   s    E,CIOT\D]D],^,^ r   c                  ,    t          j                   S r
   )r   r   r   s   r   r   z#Iterator.__init__.<locals>.<lambda>   s    E,CH,M,M r   )r   r   getterr   iterator_builder)r   r   r   r   r   s    `  r   r   zIterator.__init__   s_     	N$^$^$^$^D!!!$M$M$M$MD!!!r   c                     | j         |                                 | _         t                              d| j                    t	          t          | j                             }| j        |S |                     |          S )Nz%Iterator: Fetching next value from %r)r   r   rQ   rR   nextiterr   )r   r%   r&   r9   rl   s        r   r4   zIterator.evaluate  sl     =  1133DM<dmLLLT$-(());L{{5!!!r   c                 J    | j         | j                                          dS dS )zReset the internal iterator.N)r   resetra   s    r   r   zIterator.reset  s,    =$M!!!!! %$r   )TN)r:   r;   r<   r=   r   r4   r   rB   rC   s   @r   r   r      sk         N N N N N N
" 
" 
"" " " " " " "r   r   c                   (     e Zd ZdZ fdZd Z xZS )Sequencea  Specific BaseDeclaration to use for 'sequenced' fields.

    These fields are typically used to generate increasing unique values.

    Attributes:
        function (function): A function, expecting the current sequence counter
            and returning the computed value.
    c                 V    t                                                       || _        d S r
   rK   rM   s     r   r   zSequence.__init__  rN   r   c                     t                               d| j        |j                   |                     t	          |j                            S )Nz/Sequence: Computing next value of %r for seq=%srQ   rR   rL   r$   intr8   s       r   r4   zSequence.evaluate!  s;    FW[Wdeee}}S//000r   rS   rC   s   @r   r   r     sQ         ! ! ! ! !1 1 1 1 1 1 1r   r   c                       e Zd ZdZd ZdS )LazyAttributeSequencea>  Composite of a LazyAttribute and a Sequence.

    Attributes:
        function (function): A function, expecting the current LazyStub and the
            current sequence counter.
        type (function): A function converting an integer into the expected kind
            of counter for the 'function' attribute.
    c                     t                               d| j        |j        |           |                     |t	          |j                            S )NzDLazyAttributeSequence: Computing next value of %r for seq=%s, obj=%rr   r8   s       r   r4   zLazyAttributeSequence.evaluate/  sF    RM4=(	4 	4 	4 }}Xs4='9'9:::r   N)r:   r;   r<   r=   r4   rG   r   r   r   r   &  s-         ; ; ; ; ;r   r   c                   *     e Zd ZdZd fd	Zd Z xZS )ContainerAttributea  Variant of LazyAttribute, also receives the containers of the object.

    Attributes:
        function (function): A function, expecting the current LazyStub and the
            (optional) object having a subfactory containing this attribute.
        strict (bool): Whether evaluating should fail when the containers are
            not passed in (i.e used outside a SubFactory).
    Tc                 d    t                                                       || _        || _        d S r
   )r   r   rL   strict)r   rL   r   r   s      r   r   zContainerAttribute.__init__?  s+     r   c                 |    |j         dd         }| j        r|st          d          |                     ||          S )aY  Evaluate the current ContainerAttribute.

        Args:
            obj (LazyStub): a lazy stub of the object being constructed, if
                needed.
            containers (list of LazyStub): a list of lazy stubs of factories
                being evaluated in a chain, each item being a future field of
                next one.
        r   NzKA ContainerAttribute in 'strict' mode can only be used within a SubFactory.)r   r   	TypeErrorrL   )r   r%   r&   r9   r   s        r   r4   zContainerAttribute.evaluateD  sQ     
122; 	(u 	('( ( ( }}Xu---r   )TrS   rC   s   @r   r   r   6  sV              
. . . . . . .r   r   c                       e Zd ZdZd Zd ZdS )ParameteredAttributezBase class for attributes expecting parameters.

    Attributes:
        defaults (dict): Default values for the parameters.
            May be overridden by call-time parameters.
    c                 .    |                      ||          S )a  Evaluate the current definition and fill its attributes.

        Uses attributes definition in the following order:
        - values defined when defining the ParameteredAttribute
        - additional values defined when instantiating the containing factory

        Args:
            instance (builder.Resolver): The object holding currently computed
                attributes
            step: a factory.builder.BuildStep
            extra (dict): additional, call-time added kwargs
                for the step.
        )generater8   s       r   r4   zParameteredAttribute.evaluate`  s     }}T5)))r   c                     t                      )a  Actually generate the related attribute.

        Args:
            sequence (int): the current sequence number
            obj (LazyStub): the object being constructed
            create (bool): whether the calling factory was in 'create' or
                'build' mode
            params (dict): parameters inherited from init and evaluation-time
                overrides.

        Returns:
            Computed value for the current declaration.
        r6   )r   r&   paramss      r   r   zParameteredAttribute.generatep  s     "###r   N)r:   r;   r<   r=   r4   r   rG   r   r   r   r   X  s<         * * * $ $ $ $ $r   r   c                   $    e Zd ZdZd Zd Zd ZdS )_FactoryWrapperzHandle a 'factory' arg.

    Such args can be either a Factory subclass, or a fully qualified import
    path for that subclass (e.g 'myapp.factories.MyFactory').
    c                    d | _         dx| _        | _        t          |t                    r	|| _         d S t          |t
                    rd|v st          d|z            |                    dd          \  | _        | _        d S )Nrh   rr   zrA factory= argument must receive either a class or the fully qualified path to a Factory subclass; got %r instead.r   )r)   modulerx   r/   typestr
ValueErrorrsplit)r   factory_or_paths     r   r   z_FactoryWrapper.__init__  s    "$$diot,, 	D*DLLL44 59O9O "$345 5 5 &5%;%;C%C%C"DKr   c                 f    | j         $t          j        | j        | j                  | _         | j         S r
   )r)   r   import_objectr   rx   ra   s    r   getz_FactoryWrapper.get  s2    < .	 DL |r   c                 V    | j         d| j         d| j         dS d| j         j         dS )Nz<_FactoryImport: rr   >)r)   r   rx   r   ra   s    r   rb   z_FactoryWrapper.__repr__  s=    <At{AATYAAAA@t|'=@@@@r   N)r:   r;   r<   r=   r   r   rb   rG   r   r   r   r     sS         
D D D  A A A A Ar   r   c                   6     e Zd ZdZdZdZ fdZd Zd Z xZ	S )
SubFactoryzBase class for attributes based upon a sub-factory.

    Attributes:
        defaults (dict): Overrides to the defaults defined in the wrapped
            factory
        factory (base.Factory): the wrapped factory
    Fc                 b     t                      j        di | t          |          | _        d S )NrG   )r   r   r   factory_wrapper)r   r)   kwargsr   s      r   r   zSubFactory.__init__  s6    ""6""".w77r   c                 4    | j                                         S z.Retrieve the wrapped factory.Factory subclass.r   r   ra   s    r   get_factoryzSubFactory.get_factory      #'')))r   c                     |                                  }t                              d|j        |j        t          j        |          |           | j        r|j        nd}|	                    |||          S )zEvaluate the current definition and fill its attributes.

        Args:
            step: a factory.builder.BuildStep
            params (dict): additional, call-time added kwargs
                for the step.
        z.SubFactory: Instantiating %s.%s(%s), create=%r)r   Nr   )
r   rQ   rR   r;   r:   r   
log_pprintFORCE_SEQUENCEr$   r#   )r   r%   r&   r9   r*   r   s         r   r4   zSubFactory.evaluate  sz     %%''
<!:#6E***		
 	
 	
 +/*=G4||Jn|MMMr   )
r:   r;   r<   r=   r   r   r   r   r4   rB   rC   s   @r   r   r     st          N',$8 8 8 8 8* * *N N N N N N Nr   r   c                   (     e Zd ZdZdZd fd	Z xZS )Dictz$Fill a dict with usual declarations.Tfactory.DictFactoryc                 V     t                      j        |fi t          |           d S r
   )r   r   r   )r   r   dict_factoryr   s      r   r   zDict.__init__  s.    66f66666r   )r   r:   r;   r<   r=   r   r   rB   rC   s   @r   r   r     sH        ..N7 7 7 7 7 7 7 7 7 7r   r   c                   (     e Zd ZdZdZd fd	Z xZS )Listz'Fill a list with standard declarations.Tfactory.ListFactoryc                 n    d t          |          D             } t                      j        |fi | d S )Nc                 4    i | ]\  }}t          |          |S rG   )r   )r   ir   s      r   
<dictcomp>z!List.__init__.<locals>.<dictcomp>  s$    :::1#a&&!:::r   )	enumerater   r   )r   r   list_factoryr   s      r   r   zList.__init__  sC    ::	&(9(9:::0000000r   )r   r   rC   s   @r   r   r     sH        11N1 1 1 1 1 1 1 1 1 1r   r   c                       e Zd Zd ZdS )Skipc                     dS )NFrG   ra   s    r   __bool__zSkip.__bool__  s    ur   N)r:   r;   r<   r   rG   r   r   r   r     s#            r   r   c                   6     e Zd Zeef fd	Zd Zd Zd Z xZS )Maybec                    t                                                       t          j        |          t	          |d           }|| _        || _        || _        t          j        |          t          j        |          d}d |                                D             }t          |          dk    rt          d| d|          |r|                                nt          j        j        | _        d S )Nre   )yes_declarationno_declarationc                     h | ]}||S r
   rG   )r   phases     r   	<setcomp>z!Maybe.__init__.<locals>.<setcomp>  s    OOOU=Nu=N=N=Nr   r   zInconsistent phases for z: )r   r   r   r   r|   decideryesnor   r~   r   ri   r>   r?   r@   )r   r   r   r   phasesused_phasesr   s         r   r   zMaybe.__init__  s    "7++3#GT:::G"   %6GG#5nEE
 
 PO&--//OOO{aKtKKKKLLL:E%r[__%6%6%65K]Kr"""r   c                    t          j        | j                  }|t           j        j        k    r#| j                            |j        ||          }n4|t           j        j        k    sJ | j                            ||i           }|r| j	        n| j
        }t          j        |          t           j        j        k    r|                    |||          S |S )z#Handle post-generation declarationsr-   )r   r   r   r>   r?   r0   stubPOST_INSTANTIATIONevaluate_postr   r   )r   r%   r&   r.   decider_phasechoicer   s          r   r   zMaybe.evaluate_post  s    /==E.CCC \.. / D DFF !E$6$IIIII\//! 0 < <F $0"6**e.@.SSS''!# (    Mr   c                     | j                             ||i           }|r| j        n| j        }|                     ||||          S )N)r%   r&   r9   r-   )r   r4   r   r   r2   )r   r%   r&   r.   r   r   s         r   r0   zMaybe.evaluate_pre  s[    &&t2&NN#0 ((	 ) 
 
 	
r   c                 8    d| j         d| j        d| j        dS )NzMaybe(z, yes=z, no=r_   )r   r   r   ra   s    r   rb   zMaybe.__repr__&  s)    KKKdhKKtwKKKKr   )	r:   r;   r<   SKIPr   r   r0   rb   rB   rC   s   @r   r   r     s|        04T s s s s s s,  0

 

 

L L L L L L Lr   r   c                       e Zd ZdZd Zd ZdS )	ParameterzA complex parameter, to be used in a Factory.Params section.

    Must implement:
    - A "compute" function, performing the actual declaration override
    - Optionally, a get_revdeps() function (to compute other parameters it may alter)
    c                     t                      )a  Compute the overrides for this parameter.

        Args:
        - field_name (str): the field this parameter is installed at
        - declarations (dict): the global factory declarations

        Returns:
            dict: the declarations to override
        r6   r   
field_namedeclarationss      r   as_declarationszParameter.as_declarations2  s     "###r   c                     g S )z;Retrieve the list of other parameters modified by this one.rG   r   
parameterss     r   get_revdepszParameter.get_revdeps>  s    	r   N)r:   r;   r<   r=   r   r   rG   r   r   r   r   *  s<         
$ 
$ 
$    r   r   c                   :     e Zd Z fdZd Zed             Z xZS )SimpleParameterc                 V    t                                                       || _        d S r
   )r   r   rl   )r   rl   r   s     r   r   zSimpleParameter.__init__D  s$    


r   c                     || j         iS r
   )rl   r   s      r   r   zSimpleParameter.as_declarationsH  s    

 	
r   c                 n    t          |t                    s | |          S |                                 |S r
   )r/   r   touch_creation_counter)clsrl   s     r   wrapzSimpleParameter.wrapM  s9    %++ 	3u::$$&&&r   )r:   r;   r<   r   r   classmethodr  rB   rC   s   @r   r   r   C  sb            
 
 

   [    r   r   c                   4     e Zd ZdZ fdZd Zd Zd Z xZS )Traitz_The simplest complex parameter, it enables a bunch of new declarations based on a boolean flag.c                 V    t                                                       || _        d S r
   )r   r   r.   )r   r.   r   s     r   r   zTrait.__init__W  s$    "r   c           	         i }| j                                         D ]g\  }}t          t          d|                    t
          j                  z  d|d          ||                    |t                              ||<   h|S )Nrr   Fr   )r   r   r   )	r.   itemsr   r|   countr   SPLITTERr   r   )r   r   r   r.   maybe_field	new_values         r   r   zTrait.as_declarations[  s    	&*n&:&:&<&< 	 	"K%*%k//?????"
 "   !*+//TBB
& 
& 
&Ik"" r   c                        fd|D             S )z'This might alter fields it's injecting.c                 &    g | ]}|j         v |S rG   )r.   )r   paramr   s     r   
<listcomp>z%Trait.get_revdeps.<locals>.<listcomp>m  s%    III%$.1H1H1H1H1Hr   rG   r   s   ` r   r   zTrait.get_revdepsk  s    IIII:IIIIr   c                     | j         j        dd                    d | j                                        D                       dS )Nr   z, c              3       K   | ]	}d |z  V  
dS )z%s=%rNrG   )r   ts     r   r   z!Trait.__repr__.<locals>.<genexpr>r  s&      BBagkBBBBBBr   r_   )r   r:   joinr.   r  ra   s    r   rb   zTrait.__repr__o  sL    N###IIBB4>+?+?+A+ABBBBBBB
 	
r   )	r:   r;   r<   r=   r   r   r   rb   rB   rC   s   @r   r	  r	  U  sn        ii# # # # #   J J J
 
 
 
 
 
 
r   r	  c                   \    e Zd ZU eed<   ej        ed<   ej        eej        f         ed<   dS )PostGenerationContextvalue_providedrl   r9   N)	r:   r;   r<   bool__annotations__TAnyr   r   rG   r   r   r  r  z  sB         5LLL6#qu*r   r  c                   6    e Zd ZdZej        j        Zd Zd Z	dS )PostGenerationDeclarationzCDeclarations to be called once the model object has been generated.c                     |                      |||          }t          t          d|v           |                    d          d |                                D                       }|                     |||          S )Nrh   c                 &    i | ]\  }}|d k    ||S rh   rG   )r   kr   s      r   r   z;PostGenerationDeclaration.evaluate_post.<locals>.<dictcomp>  s#    ???DAqqBww1awwwr   )r  rl   r9   )r+   r  r  r   r  call)r   r%   r&   r.   r'   postgen_contexts         r   r   z'PostGenerationDeclaration.evaluate_post  sz    %%hi@@/g..++b//??GMMOO???
 
 

 yy4999r   c                     t                      )aN  Call this hook; no return value is expected.

        Args:
            instance (object): the newly generated object
            step (bool): whether the object was 'built' or 'created'
            context: a builder.PostGenerationContext containing values
                extracted from the containing factory's declaration
        r6   )r   r%   r&   r'   s       r   r&  zPostGenerationDeclaration.call  s     "###r   N)
r:   r;   r<   r=   r   r>   r   r@   r   r&  rG   r   r   r!  r!    sD        MM!.A: : :	$ 	$ 	$ 	$ 	$r   r!  c                   (     e Zd ZdZ fdZd Z xZS )PostGenerationz:Calls a given function once the object has been generated.c                 V    t                                                       || _        d S r
   rK   rM   s     r   r   zPostGeneration.__init__  rN   r   c           
         t                               d| j        j        | j        j        t          j        ||f|                                                     |j        j	        t          j        k    } | j        |||j        fi |j        S )Nz!PostGeneration: Calling %s.%s(%s))rQ   rR   rL   r;   r:   r   r   _asdictbuilderstrategyr   CREATE_STRATEGYrl   r9   )r   r%   r&   r'   creates        r   r&  zPostGeneration.call  s    /M$M"4 !! 		
 	
 	
 &%*??t}fgm> >/6}> > 	>r   r:   r;   r<   r=   r   r&  rB   rC   s   @r   r*  r*    sM        DD! ! ! ! !> > > > > > >r   r*  c                   4     e Zd ZdZdZd fd	Zd Zd Z xZS )RelatedFactorya6  Calls a factory once the object has been generated.

    Attributes:
        factory (Factory): the factory to call
        defaults (dict): extra declarations for calling the related factory
        name (str): the name to use to refer to the generated object when
            calling the related factory
    Frh   c                     t                                                       || _        || _        t	          |          | _        d S r
   )r   r   rx   r   r   r   )r   r)   factory_related_namer   r   s       r   r   zRelatedFactory.__init__  s=    (	 .w77r   c                 4    | j                                         S r   r   ra   s    r   r   zRelatedFactory.get_factory  r   r   c           	         |                                  }|j        r3t                              d|j        |j        |j                   |j        S t          | j                  }|	                    |j
                   | j        r
||| j        <   t                              d|j        |j        t          j        |f|                     |                    ||          S )Nz>RelatedFactory: Using provided %r instead of generating %s.%s.z$RelatedFactory: Generating %s.%s(%s))r   r  rQ   rR   rl   r;   r:   r   r   r   r9   rx   r   r   r#   )r   r%   r&   r'   r)   passed_kwargss         r   r&  zRelatedFactory.call  s    ""$$! 	!LLP"G$4  
 = T]++W]+++9 	0'/M$)$2dWm44		
 	
 	
 ||G]333r   r$  )	r:   r;   r<   r=   r   r   r   r&  rB   rC   s   @r   r4  r4    sm          (-$8 8 8 8 8 8* * *4 4 4 4 4 4 4r   r4  c                   .     e Zd ZdZd fd	Z fdZ xZS )RelatedFactoryLista  Calls a factory 'size' times once the object has been generated.

    Attributes:
        factory (Factory): the factory to call "size-times"
        defaults (dict): extra declarations for calling the related factory
        factory_related_name (str): the name to use to refer to the generated
            object when calling the related factory
        size (int|lambda): the number of times 'factory' is called, ultimately
            returning a list of 'factory' objects w/ size 'size'.
    rh      c                 L    || _          t                      j        ||fi | d S r
   )sizer   r   )r   r)   r6  r>  r   r   s        r   r   zRelatedFactoryList.__init__  s2    	"6CC(CCCCCr   c                     t                      fdt          t          | j        t                    r| j        n|                                           D             S )Nc                 >    g | ]}                               S rG   )r&  )r   r   r'   r%   parentr&   s     r   r  z+RelatedFactoryList.call.<locals>.<listcomp>  s9     
 
 
 KK$00
 
 
r   )r   ranger/   r>  r   )r   r%   r&   r'   rA  r   s    ```@r   r&  zRelatedFactoryList.call  sq    
 
 
 
 
 
 

49c(B(BS499		TT
 
 
 	
r   )rh   r<  r2  rC   s   @r   r;  r;    sf        	 	D D D D D D
 
 
 
 
 
 
 
 
r   r;  c                       e Zd ZdS )NotProvidedNro   rG   r   r   rD  rD    rp   r   rD  c                   (     e Zd ZdZ fdZd Z xZS )PostGenerationMethodCalla  Calls a method of the generated object.

    Attributes:
        method_name (str): the method to call
        method_args (list): arguments to pass to the method
        method_kwargs (dict): keyword arguments to pass to the method

    Example:
        class UserFactory(factory.Factory):
            ...
            password = factory.PostGenerationMethodCall('set_pass', password='')
    c                     t                                                       t          |          dk    rt          j        d          || _        |r|d         nt          | _        || _        d S )Nr   z|A PostGenerationMethodCall can only handle 1 positional argument; please provide other parameters through keyword arguments.r   )	r   r   r~   r   InvalidDeclarationErrormethod_namerD  
method_argmethod_kwargs)r   rI  argsr   r   s       r   r   z!PostGenerationMethodCall.__init__	  so    t99q==0M   '%):$q''{#r   c           	      T   |j         s| j        t          u rd}n| j        f}n|j        f}t	          | j                  }|                    |j                   t          || j	                  }t                              d|| j	        t          j        ||                      ||i |S )NrG   z+PostGenerationMethodCall: Calling %r.%s(%s))r  rJ  rD  rl   r   rK  r   r9   ru   rI  rQ   rR   r   r   )r   r%   r&   r'   rL  r   methods          r   r&  zPostGenerationMethodCall.call  s    % 	$+--)M#Dd())gm$$$4#3449T6**		
 	
 	
 vt&v&&&r   r2  rC   s   @r   rF  rF    sQ         	$ 	$ 	$ 	$ 	$' ' ' ' ' ' 'r   rF  )*r   loggingtypingr  rh   r   r   r   	getLoggerrQ   OrderedBaser   rE   rI   rU   rY   rn   rt   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	  
NamedTupler  r!  r*  r4  r;  rD  rF  rG   r   r   <module>rT     sW            " " " " " " " " " "		-	.	.B@ B@ B@ B@ B@e' B@ B@ B@J           ?   "' ' ' ' 'O ' ' '"(% (% (% (% (%/ (% (% (%V	 	 	 	 	 	 	 	 $0    :%
 %
 %
 %
 %
O %
 %
 %
P#" #" #" #" #" #" #" #"L1 1 1 1 1 1 1 1$; ; ; ; ;H ; ; ; . . . . . . . .D&$ &$ &$ &$ &$? &$ &$ &$RA A A A A A A AD&N &N &N &N &N &N &N &NR7 7 7 7 7: 7 7 71 1 1 1 1: 1 1 1       
 tvv<L <L <L <L <LO <L <L <L~    !   2    i   $
 
 
 
 
I 
 
 
J    AL   $ $ $ $ $ $ $ $4> > > > >. > > >*.4 .4 .4 .4 .4. .4 .4 .4b
 
 
 
 
 
 
 
0	 	 	 	 	 	 	 	*' *' *' *' *'8 *' *' *' *' *'r   