
    9 f"                     |   d Z ddlZddlZddlZddlZddlmZmZ 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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dS )z:Additional declarations for "fuzzy" attribute definitions.    N   )declarationsrandomzSetting a specific random seed for {} can still have varying results unless you also set a specific end date. For details and potential solutions see https://github.com/FactoryBoy/factory_boy/issues/331c                       e Zd ZdZd Zd ZdS )BaseFuzzyAttributez^Base class for fuzzy attributes.

    Custom fuzzers should override the `fuzz()` method.
    c                     t                      NNotImplementedErrorselfs    C/var/www/equiseq/venv/lib/python3.11/site-packages/factory/fuzzy.pyfuzzzBaseFuzzyAttribute.fuzz       !###    c                 *    |                                  S r	   )r   )r   instancestepextras       r   evaluatezBaseFuzzyAttribute.evaluate   s    yy{{r   N)__name__
__module____qualname____doc__r   r    r   r   r   r      s<         
$ $ $    r   r   c                   (     e Zd ZdZ fdZd Z xZS )FuzzyAttributezSimilar to LazyAttribute, but yields random values.

    Attributes:
        function (callable): function taking no parameters and returning a
            random value.
    c                 V    t                                                       || _        d S r	   )super__init__fuzzer)r   r!   	__class__s     r   r    zFuzzyAttribute.__init__*   s$    r   c                 *    |                                  S r	   )r!   r   s    r   r   zFuzzyAttribute.fuzz.   s    {{}}r   r   r   r   r   r    r   __classcell__r"   s   @r   r   r   "   sQ                   r   r   c                   <     e Zd ZdZdddej        f fd	Zd Z xZS )	FuzzyTexta4  Random string with a given prefix.

    Generates a random string of the given length from chosen chars.
    If a prefix or a suffix are supplied, they will be prepended / appended
    to the generated string.

    Args:
        prefix (text): An optional prefix to prepend to the random string
        length (int): the length of the random part
        suffix (text): An optional suffix to append to the random string
        chars (str list): the chars to choose from

    Useful for generating unique attributes where the exact value is
    not important.
        c                     t                                                       || _        || _        || _        t          |          | _        d S r	   )r   r    prefixsuffixlengthtuplechars)r   r,   r.   r-   r0   r"   s        r   r    zFuzzyText.__init__C   s?    5\\


r   c                       fdt           j                  D             } j        d                    |          z    j        z   S )Nc                 X    g | ]&}t           j                            j                  'S r   )r   randgenchoicer0   ).0_ir   s     r   
<listcomp>z"FuzzyText.fuzz.<locals>.<listcomp>K   s+    PPPr&&tz22PPPr   r)   )ranger.   r,   joinr-   )r   r0   s   ` r   r   zFuzzyText.fuzzJ   sD    PPPPU4;=O=OPPP{RWWU^^+dk99r   )	r   r   r   r   stringascii_lettersr    r   r%   r&   s   @r   r(   r(   2   sd           !Bf>R " " " " " ": : : : : : :r   r(   c                   *     e Zd ZdZd fd	Zd Z xZS )FuzzyChoicezHandles fuzzy choice of an attribute.

    Args:
        choices (iterable): An iterable yielding options; will only be unrolled
            on the first call.
        getter (callable or None): a function to parse returned values
    Nc                 r    d | _         || _        || _        t                                                       d S r	   )choiceschoices_generatorgetterr   r    )r   r?   rA   r"   s      r   r    zFuzzyChoice.__init__X   s5    !(r   c                     | j         t          | j                  | _         t          j                            | j                   }| j        |S |                     |          S r	   )r?   listr@   r   r3   r4   rA   )r   values     r   r   zFuzzyChoice.fuzz^   sR    < 677DL%%dl33;L{{5!!!r   r	   r$   r&   s   @r   r=   r=   O   sV              " " " " " " "r   r=   c                   *     e Zd ZdZd fd	Zd Z xZS )FuzzyIntegerz$Random integer within a given range.Nr   c                 ~    ||}d}|| _         || _        || _        t                                                       d S Nr   )lowhighr   r   r    )r   rI   rJ   r   r"   s       r   r    zFuzzyInteger.__init__j   sC    <DC		r   c                 h    t           j                            | j        | j        dz   | j                  S Nr   )r   r3   	randrangerI   rJ   r   r   s    r   r   zFuzzyInteger.fuzzu   s&    ~''$)a-KKKr   rL   r$   r&   s   @r   rF   rF   g   sY        ..	 	 	 	 	 	L L L L L L Lr   rF   c                   *     e Zd ZdZd fd	Zd Z xZS )FuzzyDecimalz$Random decimal within a given range.N   c                 ~    ||}d}|| _         || _        || _        t                                                       d S )Ng        rI   rJ   	precisionr   r    r   rI   rJ   rS   r"   s       r   r    zFuzzyDecimal.__init__|   sC    <DC	"r   c                     t          j        t          t          j                            | j        | j                                      }|                    t          j        d          | j	         z            S )N
   )
decimalDecimalstrr   r3   uniformrI   rJ   quantizerS   r   bases     r   r   zFuzzyDecimal.fuzz   sT    s6>#9#9$(DI#N#NOOPP}}W_R00T^OCDDDr   )NrP   r$   r&   s   @r   rO   rO   y   sY        ..	 	 	 	 	 	E E E E E E Er   rO   c                   *     e Zd ZdZd fd	Zd Z xZS )
FuzzyFloatz"Random float within a given range.N   c                 ~    ||}d}|| _         || _        || _        t                                                       d S rH   rR   rT   s       r   r    zFuzzyFloat.__init__   sC    <DC	"r   c                     t           j                            | j        | j                  }t          t          |d| j        z                      S )Nz.%dg)r   r3   rZ   rI   rJ   floatformatrS   r\   s     r   r   zFuzzyFloat.fuzz   s<    ~%%dh	::VD&4>"9::;;;r   )Nr`   r$   r&   s   @r   r_   r_      sR        ,,	 	 	 	 	 	< < < < < < <r   r_   c                   *     e Zd ZdZd fd	Zd Z xZS )	FuzzyDatez&Random date within a given date range.Nc                    t                                                       |it          j        j        r:| j        j        }t          j        t          
                    |          d           t          j                                        }||k    rt          d|d|d          |                                | _        |                                | _        d S )NrP   
stacklevelz3FuzzyDate boundaries should have start <= end; got  > .)r   r    r   r3   	state_setr"   r   warningswarnrandom_seed_warningrd   datetimedatetoday
ValueError	toordinal
start_dateend_date)r   ru   rv   cls_namer"   s       r   r    zFuzzyDate.__init__   s    ~' R>2188BBqQQQQ}**,,H  *::xxx)* * * %..00 **,,r   c                     t           j                            t          j                            | j        | j                            S r	   )rp   rq   fromordinalr   r3   randintru   rv   r   s    r   r   zFuzzyDate.fuzz   s0    }(()?)?QUQ^)_)_```r   r	   r$   r&   s   @r   rf   rf      sY        00- - - - - - a a a a a a ar   rf   c                   >     e Zd ZdZd Zd Z	 	 	 	 d fd	Zd Z xZS )BaseFuzzyDateTimezxBase class for fuzzy datetime-related attributes.

    Provides fuzz() computation, forcing year/month/day/hour/...
    c                 T    ||k    r!t          | j        j        d|d|          d S )Nz* boundaries should have start <= end, got rj   )rs   r"   r   )r   start_dtend_dts      r   _check_boundszBaseFuzzyDateTime._check_bounds   sG    fN+++XXXvv?@ @ @ r   c                     t                      r	   r
   r   s    r   _nowzBaseFuzzyDateTime._now   r   r   Nc
                    t                                                       |_t          j        j        r:| j        j        }
t          j        t          
                    |
          d           |                                 }|                     ||           || _        || _        || _        || _        || _        || _        || _        || _        |	| _        d S )NrP   rh   )r   r    r   r3   rl   r"   r   rm   rn   ro   rd   r   r   r~   r   
force_yearforce_month	force_day
force_hourforce_minuteforce_secondforce_microsecond)r   r~   r   r   r   r   r   r   r   r   rw   r"   s              r   r    zBaseFuzzyDateTime.__init__   s     	>~' R>2188BBqQQQQYY[[F8V,,, $&"$((!2r   c                    | j         | j        z
  }|j        d|j        |j        dz  z   z  z   }t
          j                            d|          }| j        t          j	        |          z   }| j
        |                    | j
                  }| j        |                    | j                  }| j        |                    | j                  }| j        |                    | j                  }| j        |                    | j        	          }| j        |                    | j        
          }| j        |                    | j                  }|S )Ni@B iQ r   )microseconds)year)month)day)hour)minute)second)microsecond)r   r~   r   secondsdaysr   r3   rz   rp   	timedeltar   replacer   r   r   r   r   r   )r   deltar   offsetresults        r   r   zBaseFuzzyDateTime.fuzz   s:   dm+)Gu}
UZHZ7[,\\''<88!3!H!H!HH?&^^^99F'^^$*:^;;F>%^^^77F?&^^^99F(^^4+<^==F(^^4+<^==F!-^^0F^GGFr   )NNNNNNNN)	r   r   r   r   r   r   r    r   r%   r&   s   @r   r|   r|      s         
@ @ @$ $ $ )->BBF#'3 3 3 3 3 30      r   r|   c                   (     e Zd ZdZd Z fdZ xZS )FuzzyNaiveDateTimezzRandom naive datetime within a given range.

    If no upper bound is given, will default to datetime.datetime.now().
    c                 >    t           j                                         S r	   )rp   nowr   s    r   r   zFuzzyNaiveDateTime._now   s     $$&&&r   c                     |j         t          d|z            |j         t          d|z            t                                          ||           d S )Nz=FuzzyNaiveDateTime only handles naive datetimes, got start=%rz;FuzzyNaiveDateTime only handles naive datetimes, got end=%rtzinfors   r   r   r   r~   r   r"   s      r   r   z FuzzyNaiveDateTime._check_bounds   sq    ?&O   =$M   	h/////r   r   r   r   r   r   r   r%   r&   s   @r   r   r      sQ         
' ' '	0 	0 	0 	0 	0 	0 	0 	0 	0r   r   c                   (     e Zd ZdZd Z fdZ xZS )FuzzyDateTimezRandom timezone-aware datetime within a given range.

    If no upper bound is given, will default to datetime.datetime.now()
    If no timezone is given, will default to utc.
    c                 `    t           j                             t           j        j                  S )N)tz)rp   r   timezoneutcr   s    r   r   zFuzzyDateTime._now  s"     $$(9(=$>>>r   c                     |j         t          d|z            |j         t          d|z            t                                          ||           d S )Nz=FuzzyDateTime requires timezone-aware datetimes, got start=%rz;FuzzyDateTime requires timezone-aware datetimes, got end=%rr   r   s      r   r   zFuzzyDateTime._check_bounds  sq    ?"O   = M   	h/////r   r   r&   s   @r   r   r     sQ         ? ? ?	0 	0 	0 	0 	0 	0 	0 	0 	0r   r   )r   rp   rW   r:   rm   r)   r   r   ro   BaseDeclarationr   r   r(   r=   rF   rO   r_   rf   r|   r   r   r   r   r   <module>r      sT   A @     " " " " " " " "? 
 
 
 
 
5 
 
 
    '    : : : : :" : : ::" " " " "$ " " "0L L L L L% L L L$E E E E E% E E E&< < < < <# < < <&a a a a a" a a a.= = = = =* = = =@0 0 0 0 0* 0 0 0*0 0 0 0 0% 0 0 0 0 0r   