Ë
   ~ztQ¡²ã            	       óv  — U d dl Zd dlmc mZ d dlZd dlZd dlZd dl	Z	d dl
Z
d dlmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZmZ d dlmZ d dlZd dlmZmZ d d	lmZm Z m!Z! erd d
lm"Z"  G d„ de"«      Z#nej&                  Z# e«       Z$ e%e$«      Z& ee&ei«      Z'ee(e#f   e)d<    G d„ d«      Z*da+e#dz  e)d<   e!se sdede(fd„Z, e, e-«       «      Z.ndZ.de#ddfd„Z/ e0«       Z1e0e   e)d<    ed¬«      de(de2ee(f   fd„«       Z3	 ddede2eg df   eg df   f   fd„Z4ejj                  dde(ded   fd„«       Z6y)é    N)ÚCallableÚ	GeneratorÚHashable)Ú	lru_cache)Úcount)ÚRandom)ÚTYPE_CHECKINGÚAny)ÚWeakValueDictionary)ÚHypothesisWarningÚInvalidArgument)ÚFREE_THREADED_CPYTHONÚGRAALPYÚPYPY)ÚProtocolc                   óH   — e Zd Zdededefd„Zdededefd„Zdededefd„Zy)Ú
RandomLikeÚargsÚkwargsÚreturnc                  ó   — y ©N© ©Úselfr   r   s      ú`/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/hypothesis/internal/entropy.pyÚseedzRandomLike.seed!   ó   � ó    c                  ó   — y r   r   r   s      r   ÚgetstatezRandomLike.getstate"   r   r   c                  ó   — y r   r   r   s      r   ÚsetstatezRandomLike.setstate#   r   r   N)Ú__name__Ú
__module__Ú__qualname__r
   r   r!   r#   r   r   r   r   r       s8   „ Ø=˜cÐ=¨SÐ=°SÓ=ØA #ÐA°ÐA¸ÓAØA #ÐA°ÐA¸ÔAr   r   ÚRANDOMS_TO_MANAGEc                   ó   — e Zd Zdd„Zy)ÚNumpyRandomWrapperNc                 óT  — d}t         j                  }||v }|sµt        j                  d|fd||f«      t        j                  |«      dt        j                  «       v st        j                  t         «      rt        j                  t         «      ndt        j                  |«      dœz  }dd|iz  }t        t        j                  |«      «      ‚d x}x}}dd l
}|j                  j                  | _        |j                  j                  | _        |j                  j                  | _        y )	NÚnumpy)Úin)z/%(py1)s in %(py5)s
{%(py5)s = %(py3)s.modules
}Úsys)Úpy1Úpy3Úpy5zassert %(py7)sÚpy7r   )r-   ÚmodulesÚ
@pytest_arÚ_call_reprcompareÚ	_safereprÚ@py_builtinsÚlocalsÚ_should_repr_global_nameÚAssertionErrorÚ_format_explanationÚnumpy.randomÚrandomr   Ú	get_stater!   Ú	set_stater#   )r   Ú@py_assert0Ú@py_assert4Ú@py_assert2Ú@py_format6Ú@py_format8r+   s          r   Ú__init__zNumpyRandomWrapper.__init__3   s§   € ØÐ%œ#Ÿ+™+Ð%ˆw˜+Ð%×%×%Õ%ˆw˜+×%×%Ó%ˆw×%×%×%×%×%Ð%œ#×%×%Ó%œ#×%×%Ô%˜+×%×%×%×%×%×%Ó%ó 	à—L‘L×%Ñ%ˆŒ	ØŸ™×.Ñ.ˆŒØŸ™×.Ñ.ˆ�r   ©r   N)r$   r%   r&   rD   r   r   r   r)   r)   2   s   „ ô/r   r)   Ú	NP_RANDOMÚrr   c                 ó,   — t        j                  | «      S r   )r-   Úgetrefcount)rG   s    r   Ú_get_platform_base_refcountrJ   C   s   € Ü�‰˜qÓ!Ð!r   éÿÿÿÿc                 ó0  — t        | d«      rt        | d«      rt        | d«      st        d| ›d�«      ‚| t        j                  j	                  «       j                  «       D �cg c]  } |«       x}�|‘Œ c}v ryt        s|t        svt        j                  «        t        j                  | «      sMt        j                  | «      t        k  rt        d| › d�«      ‚t        st!        j"                  d	t$        d
¬«       | t        t'        t(        «      <   yc c}w )aa  Register (a weakref to) the given Random-like instance for management by
    Hypothesis.

    You can pass instances of structural subtypes of ``random.Random``
    (i.e., objects with seed, getstate, and setstate methods) to
    ``register_random(r)`` to have their states seeded and restored in the same
    way as the global PRNGs from the ``random`` and ``numpy.random`` modules.

    All global PRNGs, from e.g. simulation or scheduling frameworks, should
    be registered to prevent flaky tests. Hypothesis will ensure that the
    PRNG state is consistent for all test runs, always seeding them to zero and
    restoring the previous state after the test, or, reproducibly varied if you
    choose to use the :func:`~hypothesis.strategies.random_module` strategy.

    ``register_random`` only makes `weakrefs
    <https://docs.python.org/3/library/weakref.html#module-weakref>`_ to ``r``,
    thus ``r`` will only be managed by Hypothesis as long as it has active
    references elsewhere at runtime. The pattern ``register_random(MyRandom())``
    will raise a ``ReferenceError`` to help protect users from this issue.
    This check does not occur for the PyPy interpreter. See the following example for
    an illustration of this issue

    .. code-block:: python


       def my_BROKEN_hook():
           r = MyRandomLike()

           # `r` will be garbage collected after the hook resolved
           # and Hypothesis will 'forget' that it was registered
           register_random(r)  # Hypothesis will emit a warning


       rng = MyRandomLike()


       def my_WORKING_hook():
           register_random(rng)
    r   r!   r#   zr=z' does not have all the required methodsNz `register_random` was passed `r=zÉ` which will be garbage collected immediately after `register_random` creates a weakref to it. This will prevent Hypothesis from managing this PRNG. See the docs for `register_random` for more details.züIt looks like `register_random` was passed an object that could be garbage collected immediately after `register_random` creates a weakref to it. This will prevent Hypothesis from managing this PRNG. See the docs for `register_random` for more details.é   )Ú
stacklevel)Úhasattrr   r'   ÚdataÚcopyÚvaluesr   r   ÚgcÚcollectÚget_referrersr-   rI   Ú_PLATFORM_REF_COUNTÚReferenceErrorr   ÚwarningsÚwarnr   ÚnextÚ_RKEY)rG   Úrefr<   s      r   Úregister_randomr]   N   s  € ôP �A�vÔ¤7¨1¨jÔ#9¼gÀaÈÔ>TÜ   Ð$KÐLÓMÐMàä$×)Ñ)×.Ñ.Ó0×7Ñ7Ó9öàÙ“eˆOˆFÐ(ò 	òñ ð
 	å•Gä
�
‰
ŒÜ×Ñ Ô"Ü�‰˜qÓ!Ô%8Ò8Ü$Ø6°q°cð :ð óð õ +ô —‘ðQô &Ø õð &'Ô”dœ5“kÒ"ùòEs   Á#DÚ_known_random_state_hashesé@   )Úmaxsizer   c                 óN   — t        | «      j                  «       }|t        |«      fS r   )r   r!   Úhash)r   Ústates     r   Ú_seeded_staterd   ¦   s#   € ä�4‹L×!Ñ!Ó#€EØ”$�u“+ÐÐr   c                 óÐ  ‡ ‡‡‡— t        ‰ t        «      }|�sddt        j                  «       v st	        j
                  t         «      rt	        j                  t         «      nddt        j                  «       v st	        j
                  ‰ «      rt	        j                  ‰ «      nddt        j                  «       v st	        j
                  t        «      rt	        j                  t        «      ndt	        j                  |«      dœz  }t        t	        j                  |«      «      ‚d}d}|‰ k  }d}d	}||z  }‰ |k  }|r|sÃt	        j                  d
||fd|‰ |f«      t	        j                  |«      dt        j                  «       v st	        j
                  ‰ «      rt	        j                  ‰ «      ndt	        j                  |«      t	        j                  |«      dœz  }dd|iz  }	t        t	        j                  |	«      «      ‚dx}x}x}x}x}}i Št        ‰ «      \  ŠŠdt        j                  v r&t        € t        «       xat        t!        t"        «      <   dˆ ˆˆˆfd„}
dˆfd„}|
|fS )aÕ  Return a pair of functions which respectively seed all and restore
    the state of all registered PRNGs.

    This is used by the core engine via `deterministic_PRNG`, and by users
    via `register_random`.  We support registration of additional random.Random
    instances (or other objects with seed, getstate, and setstate methods)
    to force determinism on simulation or scheduling frameworks which avoid
    using the global random state.  See e.g. #1709.
    z5assert %(py4)s
{%(py4)s = %(py0)s(%(py1)s, %(py2)s)
}Ú
isinstancer   Úint)Úpy0r.   Úpy2Úpy4Nr   rM   é    )ú<=ú<)z%(py1)s <= %(py4)sz%(py4)s < (%(py6)s ** %(py8)s))r.   rj   Úpy6Úpy8zassert %(py11)sÚpy11r+   c                  ó$  •— ‰ } | sedddt        j                  «       v st        j                  ‰«      rt        j                  ‰«      ndiz  }t        t        j                  |«      «      ‚d } t        j                  j                  «       j                  «       D ]t  \  }} |«       }|€Œ|j                  «       ‰|<   |t        k(  rt        j                  ‰«       t        |«      t         u r|j#                  ‰«       Œd|j%                  ‰«       Œv y )Nzassert not %(py0)srh   Ústates)r6   r7   r3   r8   r5   r9   r:   r'   rP   rQ   Úitemsr!   Ú_global_random_rkeyr^   ÚaddÚtyper   r#   r   )	Ú@py_assert1Ú@py_format2Úkr\   rG   r   Úseeded_hashÚseeded_staterr   s	        €€€€r   Úseed_allz)get_seeder_and_restorer.<locals>.seed_allÃ   sÂ   ø€ ØˆzÐ‰z××××Ö�6××Ó�6×××××Ñô  (×,Ñ,×1Ñ1Ó3×9Ñ9Ó;ò 	‰FˆAˆsÙ“ˆAØˆyàØŸ
™
›ˆF�1‰IØÔ'Ò'ô +×.Ñ.¨{Ô;ä�A‹wœ&Ñ Ø—
‘
˜<Õ(à—‘�t•ñ	r   c                  óö   •— ‰j                  «       D ]U  \  } }t        j                  | «      }|€Œ| t        k(  rt        j                  t        |«      «       |j                  |«       ŒW ‰j                  «        y r   )	rs   r'   Úgetrt   r^   ru   rb   r#   Úclear)ry   rc   rG   rr   s      €r   Úrestore_allz,get_seeder_and_restorer.<locals>.restore_allå   sf   ø€ ØŸ™›ò 	‰HˆAˆuÜ!×%Ñ% aÓ(ˆAØˆyØàÔ'Ò'Ü*×.Ñ.¬t°E«{Ô;Ø�J‰J�uÕð	ð 	�‰�r   rE   )rf   rg   r6   r7   r3   r8   r5   r9   r:   r4   rd   r-   r2   rF   r)   r'   rZ   r[   )r   Ú@py_assert3Ú@py_format5r?   rA   Ú@py_assert5Ú@py_assert7Ú@py_assert9Ú@py_format10Ú@py_format12r|   r€   rz   r{   rr   s   `           @@@r   Úget_seeder_and_restorerrˆ   ¬   s{  û€ ô �dœCÓ Ð Ò × × × × Õ Œ:× × Ó Œ:× × × × × Ò �d× × Ó �d× × × × × Ò œC× × Ó œC× × Ô Ð × × × × × Ð ØÐˆ1�ÑÐ�qÐ˜"Ð�q˜"‘uÐ��uÑ×××Ðˆ1��u××Óˆ1×××××Ð�××Ó�××Ô�q××Ò˜"×××××××ÑØ "€FÜ -¨dÓ 3Ñ€L�+à”#—+‘+ÑäÐä9KÓ9MÐMˆIÔ)¬$¬u«+Ñ6÷ ð  õD
ð �[Ð Ð r   )NNNc              #   óV  K  — t         j                  j                  j                  €Tt	        «       t         j                  j                  _        t        t         j                  j                  j                  «       t        | «      \  }} |«        	 d–—  |«        y#  |«        w xY w­w)aA  Context manager that handles random.seed without polluting global state.

    See issue #1266 and PR #1295 for details and motivation - in short,
    leaving the global pseudo-random number generator (PRNG) seeded is a very
    bad idea in principle, and breaks all kinds of independence assumptions
    in practice.
    N)Ú
hypothesisÚcoreÚthreadlocalÚ_hypothesis_global_randomr   r]   rˆ   )r   r|   r€   s      r   Údeterministic_PRNGrŽ   ô   sp   è ø€ ô ‡�×"Ñ"×<Ñ<ÐDÜ@FÃŒ
�‰×#Ñ#Ô=Üœ
Ÿ™×3Ñ3×MÑMÔNä3°DÓ9Ñ€HˆkÙ„JðÛá�ø‰�üs   ‚BB)ÂB ÂB)Â	B&Â&B))r   )7Úbuiltinsr6   Ú_pytest.assertion.rewriteÚ	assertionÚrewriter3   Ú
contextlibrS   r<   r-   rX   Úcollections.abcr   r   r   Ú	functoolsr   Ú	itertoolsr   r   Útypingr	   r
   Úweakrefr   Úhypothesis.corerŠ   Úhypothesis.errorsr   r   Úhypothesis.internal.compatr   r   r   r   r   r[   rZ   rt   r'   rg   Ú__annotations__r)   rF   rJ   ÚobjectrV   r]   Úsetr^   Útuplerd   rˆ   ÚcontextmanagerrŽ   r   r   r   ú<module>r¡      s   ð÷ … Ó Û 	Û Û 
Û ß 9Ñ 9Ý Ý Ý ß %Ý 'ã ß @ß KÑ KáÝôB�Xõ Bð —‘€Já‹€Ù˜5“kÐ ñ ;NØ˜&Ð!ó;Ð Ð& s¨J Ñ7ó ÷
	/ñ 	/ð  $€	ˆ:˜ÑÓ #ñ 	‘ð" sð "¨só "ñ
 6±f³hÓ?Ñð ÐðM'�zð M' dó M'ñj (+£uÐ ˜C ™HÓ ,ñ �2Ôð˜ð   c¨3 h¡ò ó ðð ñE!Ø
ðE!à
ˆ8�B˜�HÑ˜x¨¨D¨Ñ1Ð1Ñ2óE!ðP ×Ññ˜Sð ¨Ð3CÑ)Dò ó ñr   