
    i                        % S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	J
r
Jr  S SKJrJr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JrJ r J!r!J"r"  S SK#J$r$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/J0r0  S SK1J2r2  S SK3J4r4J5r5  S SK6J7r7  / SQr8\(       a  S SK9J:r:  \;\\;   -  r<\!\=S'   \>\?\?4   r@\!\=S'   \>\?\?S-  4   rA\!\=S'   \>\ S   \@4   \>\ S   \A4   -  rB\!\=S'   \
\B/\4   rC\!\=S'   S\<S\D4S jrE S?S\<\4-  \ S   -  S-  SS 4S! jjrF " S" S#\ R                  5      rHS$\R                  ;   ah  \(       da   S SKJrKS%rL S SKMJNs  JOs  JPs  JQrR  \T" \RR                  \V5      (       a  \RR                  \L1-  \RlU        O\RR                  R                  \L5          " S& S \HS'9rY " S( S)\Y5      rZS*\?S\;4S+ jr[ " S, S-\Y5      r\ " S. S/\Y5      r] " S0 S1\Y5      r^ " S2 S3\Y5      r_ " S4 S5\Y5      r`S6\aS\?4S7 jrbS8\?S\>\a\a4   4S9 jrcS:\\2   S\?4S; jrdS8\?S\>\2S<4   4S= jreS8\?S\>\2S<4   S-  4S> jrfg! \S a    \KR                  R                  rR GN f = f! \X a     Nf = f)@    N)CallableIterable)datetime	timedeltatimezone)	lru_cache)sha384)PathLikegetenv)PathPurePath)Queue)Thread)TYPE_CHECKINGAnyClassVarLiteral	TypeAliascast)	HTTPErrorURLError)Requesturlopen)
BadZipFileZipFile)storage_directory)HypothesisExceptionHypothesisWarning)ChoiceT)UniqueIdentifiernot_set)note_deprecation)DirectoryBasedExampleDatabaseExampleDatabaseGitHubArtifactDatabaseInMemoryExampleDatabaseMultiplexedDatabaseReadOnlyDatabase)BaseObserverStrPathT	SaveDataTDeleteDataTsavedeleteListenerEventT	ListenerTpathreturnc                 f   [        U 5      n  U R                  5       (       d#  U R                  n U R                  5       (       d  M#  U R                  5       =(       aG    [        R
                  " U [        R                  [        R                  -  [        R                  -  5      $ ! [         a     gf = f)z
Returns True if the desired path can be used as database path because
either the directory exists and can be used, or its root directory can
be used and we can make the directory as needed.
F)
r   existsparentis_dirosaccessR_OKW_OKX_OKPermissionErrorr1   s    R/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/hypothesis/database.py_usable_dirr?   C   s{     :D++--;;D ++-- {{}M42771BRWW1L!MM  s   6B# AB# #
B0/B0:memory:r$   c                 2   U [         L ad  [        R                  " S5      b  [        S5      e[	        SSS9n [        U 5      (       d(  [        R                  " SU < 3[        SS9  [        5       $ U S	;   a
  [        5       $ [        [        U 5      n [        U 5      $ )
NHYPOTHESIS_DATABASE_FILEzThe $HYPOTHESIS_DATABASE_FILE environment variable no longer has any effect.  Configure your database location via a settings profile instead.
https://hypothesis.readthedocs.io/en/latest/settings.html#settings-profilesexamplesF)intent_to_writezThe database setting is not configured, and the default location is unusable - falling back to an in-memory database for this session.  path=   
stacklevel)Nr@   )r!   r7   r   r   r   r?   warningswarnr   r&   r   r*   r#   r=   s    r>   _db_for_pathrJ   U   s     w99/0<%^  !UC4  MM5/3g7 " +,,!!&(($D(..    c                   8   ^  \ rS rSrS\S\SS4U 4S jjrSrU =r$ )_EDMetap   argskwargsr2   r$   c                 b   > U [         L a  [        SSSS9  [        U0 UD6$ [        TU ]  " U0 UD6$ )Na%  Creating a database using the abstract ExampleDatabase() class is deprecated. Prefer using a concrete subclass, like InMemoryExampleDatabase() or DirectoryBasedExampleDatabase(path). In particular, the special string ExampleDatabase(":memory:") should be replaced by InMemoryExampleDatabase().z
2025-04-07F)sincehas_codemod)r$   r"   rJ   super__call__)selfrO   rP   	__class__s      r>   rU   _EDMeta.__call__q   sH    ?"C
 #!  000w000rK    )__name__
__module____qualname____firstlineno__r   rU   __static_attributes____classcell__rW   s   @r>   rM   rM   p   s#    1c 1S 15F 1 1rK   rM   sphinxz$hypothesis.database._EDMeta.__call__c                   .   \ rS rSrSrSS jr\R                  S\S\SS4S j5       r	\R                  S\S\
\   4S	 j5       r\R                  S\S\SS4S
 j5       rS\S\S\SS4S jrS\SS4S jrS\SS4S jrSS jrS\SS4S jrSS jrSS jrSrg)r$      a  
A Hypothesis database, for use in |settings.database|.

Hypothesis automatically saves failures to the database set in
|settings.database|. The next time the test is run, Hypothesis will replay
any failures from the database in |settings.database| for that test (in
|Phase.reuse|).

The database is best thought of as a cache that you never need to invalidate.
Entries may be transparently dropped when upgrading your Hypothesis version
or changing your test. Do not rely on the database for correctness; to ensure
Hypothesis always tries an input, use |@example|.

A Hypothesis database is a simple mapping of bytes to sets of bytes. Hypothesis
provides several concrete database subclasses. To write your own database class,
see :doc:`/how-to/custom-database`.

Change listening
----------------

An optional extension to |ExampleDatabase| is change listening. On databases
which support change listening, calling |ExampleDatabase.add_listener| adds
a function as a change listener, which will be called whenever a value is
added, deleted, or moved inside the database. See |ExampleDatabase.add_listener|
for details.

All databases in Hypothesis support change listening. Custom database classes
are not required to support change listening, though they will not be compatible
with features that require change listening until they do so.

.. note::

    While no Hypothesis features currently require change listening, change
    listening is required by `HypoFuzz <https://hypofuzz.com/>`_.

Database methods
----------------

Required methods:

* |ExampleDatabase.save|
* |ExampleDatabase.fetch|
* |ExampleDatabase.delete|

Optional methods:

* |ExampleDatabase.move|

Change listening methods:

* |ExampleDatabase.add_listener|
* |ExampleDatabase.remove_listener|
* |ExampleDatabase.clear_listeners|
* |ExampleDatabase._start_listening|
* |ExampleDatabase._stop_listening|
* |ExampleDatabase._broadcast_change|
r2   Nc                     / U l         g N
_listenersrV   s    r>   __init__ExampleDatabase.__init__   s	    +-rK   keyvaluec                 D    [        [        U 5      R                   S35      e)z`Save ``value`` under ``key``.

If ``value`` is already present in ``key``, silently do nothing.
z.saveNotImplementedErrortyperZ   rV   rk   rl   s      r>   r-   ExampleDatabase.save   s!     "T$Z%8%8$9"?@@rK   c                 D    [        [        U 5      R                   S35      e)z5Return an iterable over all values matching this key.z.fetchrn   rV   rk   s     r>   fetchExampleDatabase.fetch   s!     "T$Z%8%8$9"@AArK   c                 D    [        [        U 5      R                   S35      e)z]Remove ``value`` from ``key``.

If ``value`` is not present in ``key``, silently do nothing.
z.deletern   rq   s      r>   r.   ExampleDatabase.delete   s!     "T$Z%8%8$9"ABBrK   srcdestc                 v    X:X  a  U R                  X5        gU R                  X5        U R                  X#5        g)a  
Move ``value`` from key ``src`` to key ``dest``.

Equivalent to ``delete(src, value)`` followed by ``save(src, value)``,
but may have a more efficient implementation.

Note that ``value`` will be inserted at ``dest`` regardless of whether
it is currently present at ``src``.
N)r-   r.   rV   ry   rz   rl   s       r>   moveExampleDatabase.move   s0     ;IIc!C		$rK   fc                    [        U R                  5      nU R                  R                  U5        U(       d  U R                  5         gg)a/  
Add a change listener. ``f`` will be called whenever a value is saved,
deleted, or moved in the database.

``f`` can be called with two different event values:

* ``("save", (key, value))``
* ``("delete", (key, value))``

where ``key`` and ``value`` are both ``bytes``.

There is no ``move`` event. Instead, a move is broadcasted as a
``delete`` event followed by a ``save`` event.

For the ``delete`` event, ``value`` may be ``None``. This might occur if
the database knows that a deletion has occurred in ``key``, but does not
know what value was deleted.
N)boolrg   append_start_listening)rV   r   had_listenerss      r>   add_listenerExampleDatabase.add_listener  s8    & T__-q!!!# rK   c                    XR                   ;  a  gU R                   R                  U5        U R                   (       d  U R                  5         gg)zy
Removes ``f`` from the list of change listeners.

If ``f`` is not in the list of change listeners, silently do nothing.
N)rg   remove_stop_listening)rV   r   s     r>   remove_listenerExampleDatabase.remove_listener&  s;     OO#q!  " rK   c                     [        U R                  5      nU R                  R                  5         U(       a  U R                  5         gg)zRemove all change listeners.N)r   rg   clearr   )rV   r   s     r>   clear_listenersExampleDatabase.clear_listeners2  s4    T__-  " rK   eventc                 :    U R                    H  nU" U5        M     g)a  
Called when a value has been either added to or deleted from a key in
the underlying database store. The possible values for ``event`` are:

* ``("save", (key, value))``
* ``("delete", (key, value))``

``value`` may be ``None`` for the ``delete`` event, indicating we know
that some value was deleted under this key, but not its exact value.

Note that you should not assume your instance is the only reference to
the underlying database store. For example, if two instances of
|DirectoryBasedExampleDatabase| reference the same directory,
_broadcast_change should be called whenever a file is added or removed
from the directory, even if that database was not responsible for
changing the file.
Nrf   )rV   r   listeners      r>   _broadcast_change!ExampleDatabase._broadcast_change9  s    $ HUO (rK   c                 R    [         R                  " U R                   S3[        SS9  g)a  
Called when the database adds a change listener, and did not previously
have any change listeners. Intended to allow databases to wait to start
expensive listening operations until necessary.

``_start_listening`` and ``_stop_listening`` are guaranteed to alternate,
so you do not need to handle the case of multiple consecutive
``_start_listening`` calls without an intermediate ``_stop_listening``
call.
z' does not support listening for changes   rF   NrH   rI   rW   r   rh   s    r>   r    ExampleDatabase._start_listeningN  s&     	~~EF	
rK   c                 R    [         R                  " U R                   S3[        SS9  g)a  
Called whenever no change listeners remain on the database.

``_stop_listening`` and ``_start_listening`` are guaranteed to alternate,
so you do not need to handle the case of multiple consecutive
``_stop_listening`` calls without an intermediate ``_start_listening``
call.
z0 does not support stopping listening for changesr   rF   Nr   rh   s    r>   r   ExampleDatabase._stop_listening_  s&     	~~NO	
rK   rf   r2   N)rZ   r[   r\   r]   __doc__ri   abcabstractmethodbytesr-   r   ru   r.   r}   r0   r   r   r   r/   r   r   r   r^   rY   rK   r>   r$   r$      s   8t. 	A Ae A A A 	B B8E? B B 	C% C C$ C C U 5 T  $i $t $0
# 
#$ 
##~ $ *
"
rK   )	metaclassc                      ^  \ rS rSrSrSU 4S jjrS\4S jrS\S\	4S jr
S	\S\\   4S
 jrS	\S\SS4S jrS	\S\SS4S jrSS jrSS jrSrU =r$ )r&   io  a+  A non-persistent example database, implemented in terms of an in-memory
dictionary.

This can be useful if you call a test function several times in a single
session, or for testing other database implementations, but because it
does not persist between runs we do not recommend it for general use.
r2   Nc                 0   > [         TU ]  5         0 U l        g re   )rT   ri   data)rV   rW   s    r>   ri    InMemoryExampleDatabase.__init__x  s    -/	rK   c                 $    SU R                   < S3$ )NzInMemoryExampleDatabase()r   rh   s    r>   __repr__ InMemoryExampleDatabase.__repr__|  s    )$))a88rK   otherc                 `    [        U[        5      =(       a    U R                  UR                  L $ re   )
isinstancer&   r   rV   r   s     r>   __eq__InMemoryExampleDatabase.__eq__  s"    %!89Udii5::>UUrK   rk   c              #   X   #    U R                   R                  US5       S h  vN   g  N7fNrY   )r   getrt   s     r>   ru   InMemoryExampleDatabase.fetch  s     99==b)))s    *(*rl   c                     [        U5      nU R                  R                  U[        5       5      nX#;  nUR	                  U5        U(       a  U R                  SX445        g g Nr-   )r   r   
setdefaultsetaddr   rV   rk   rl   valueschangeds        r>   r-   InMemoryExampleDatabase.save  sT    e%%c351%

5""FSL#9: rK   c                     [        U5      nU R                  R                  U[        5       5      nX#;   nUR	                  U5        U(       a  U R                  SX445        g g Nr.   )r   r   r   r   discardr   r   s        r>   r.   InMemoryExampleDatabase.delete  sQ    esCE*/u""Hsl#;< rK   c                     g re   rY   rh   s    r>   r   (InMemoryExampleDatabase._start_listening  s     	rK   c                     g re   rY   rh   s    r>   r   'InMemoryExampleDatabase._stop_listening      rK   r   r   )rZ   r[   r\   r]   r   ri   strr   objectr   r   r   r   ru   r-   r.   r   r   r^   r_   r`   s   @r>   r&   r&   o  s    09# 9VF Vt V* *8E? *; ;e ; ;=% = =$ = rK   r&   rk   c                 :    [        U 5      R                  5       S S $ )N   )r	   	hexdigestrk   s    r>   _hashr     s    #;  "3B''rK   c                   (  ^  \ rS rSr% SrSr\\   \S'   \	" \5      r
\\   \S'   S\SS4U 4S	 jjrS\4S
 jrS\S\4S jrS\S\4S jrS\S\S\4S jrS\S\\   4S jrS\S\SS4S jrS\S\S\SS4S jrS\S\SS4S jrSS jrSS jrSrU =r$ )r#   i  a  Use a directory to store Hypothesis examples as files.

Each test corresponds to a directory, and each example to a file within that
directory.  While the contents are fairly opaque, a
|DirectoryBasedExampleDatabase| can be shared by checking the directory
into version control, for example with the following ``.gitignore``::

    # Ignore files cached by Hypothesis...
    .hypothesis/*
    # except for the examples directory
    !.hypothesis/examples/

Note however that this only makes sense if you also pin to an exact version of
Hypothesis, and we would usually recommend implementing a shared database with
a network datastore - see |ExampleDatabase|, and the |MultiplexedDatabase| helper.
s   .hypothesis-keys_metakeys_name_metakeys_hashr1   r2   Nc                 ^   > [         TU ]  5         [        U5      U l        0 U l        S U l        g re   )rT   ri   r   r1   keypaths	_observer)rV   r1   rW   s     r>   ri   &DirectoryBasedExampleDatabase.__init__  s'    J	+-.2rK   c                 $    SU R                   < S3$ )NzDirectoryBasedExampleDatabase(r   r=   rh   s    r>   r   &DirectoryBasedExampleDatabase.__repr__  s    /		}A>>rK   r   c                 b    [        U[        5      =(       a    U R                  UR                  :H  $ re   )r   r#   r1   r   s     r>   r   $DirectoryBasedExampleDatabase.__eq__  s$    u;<XejjAX	
rK   rk   c                      U R                   U   $ ! [         a     Of = fU R                  [        U5      -  U R                   U'   U R                   U   $ re   )r   KeyErrorr1   r   rt   s     r>   	_key_path'DirectoryBasedExampleDatabase._key_path  sR    	==%% 		!YYs3c}}S!!s    
rl   c                 <    U R                  U5      [        U5      -  $ re   )r   r   rq   s      r>   _value_path)DirectoryBasedExampleDatabase._value_path  s    ~~c"U5\11rK   c              #     #    U R                  U5      nUR                  5       (       d  g  [        R                  " U5       H  n X#-  R	                  5       v   M     g ! [
         a     M*  f = f! [
         a     g f = f7fre   )r   r6   r7   listdir
read_bytesOSError)rV   rk   kpr1   s       r>   ru   #DirectoryBasedExampleDatabase.fetch  sr     ^^C yy{{	

290022 '   		sL   (A?A/ AA/ A?
A,(A/ +A,,A/ /
A<9A?;A<<A?c                    U R                  U5      nUR                  U R                  :w  a  U R                  U R                  U5         UR                  SSS9  U R                  X5      nUR                  5       (       dx  [        R                  " 5       u  pV[        U5      n[        R                  " XR5        [        R                  " U5         UR                  U5        UR                  5       (       a   eg g ! [         ai  nUR                   [         R"                  :X  a1   UR%                  UR'                  5       5        O! [         a     Of = fUR)                  5          S nANS nAff = f! [         a     g f = f)NTexist_okparents)r   namer   r-   r   mkdirr   r4   tempfilemkstempr   r7   writecloserenamer   errnoEXDEVwrite_bytesr   unlink)	rV   rk   rl   key_pathr1   fdtmpnametmppatherrs	            r>   r-   "DirectoryBasedExampleDatabase.save  s8   >>#&==D/// IId))3/
	NND$N7##C/D;;==
 '..0w-#
%NN4( #>>+++++) !  %yyEKK/! ,,W-?-?-AB& ! !NN$$%  		sa   	BE. C8 E. 8
E+E&!E E&
EE&EE&!E. &E++E. .
E;:E;ry   rz   c                    X:X  a  U R                  X5        g U R                  X5      nU R                  X#5      nU R                  U5      R                  5       (       d  U R                  U R                  U5         [
        R                  " XE5        g ! [         a%    U R                  X5        U R                  X#5         g f = fre   )	r-   r   r   r4   r   r7   renamesr   r.   )rV   ry   rz   rl   src_path	dest_paths         r>   r}   "DirectoryBasedExampleDatabase.move	  s    ;IIc!##C/$$T1	 ~~d#**,,IId))40	#JJx+ 	#KK#IId"	#s   ;B ,C Cc                      U R                  X5      R                  5          U R                  U5      R	                  5         U R                  U R                  U5        g ! [         a     g f = f! [         a     g f = fre   )r   r   r   r   rmdirr.   r   rq   s      r>   r.   $DirectoryBasedExampleDatabase.delete  su    	S(//1	2NN3%%' KK++S1  		  		s"   A A. 
A+*A+.
A;:A;c                 z  ^^^^^	^
^^^  SSK JmJmJmJmJm	Jm
Jn  SSKJ	n  U R!                  U R"                  5       Vs0 s H  n[%        U5      U_M     snmU R&                  mU R(                  m " UUUUU	U
UUU4	S jS	U5      nU R*                  R-                  S
S
S9  U" 5       U l        U R.                  R1                  U" 5       U R*                  S
TT	T
/S9  U R.                  R3                  5         g ! [         a5    [        R                  " SU R                  R                   S3[        SS9   g f = fs  snf )Nr   )DirCreatedEventDirDeletedEventDirMovedEventFileCreatedEventFileDeletedEventFileMovedEventFileSystemEventHandler)Observerzlistening for changes in a zR requires the watchdog library. To install, run `pip install hypothesis[watchdog]`r   rF   c                      >	 \ rS rSrS Y Y -  SS4U UUU4S jjrS Y Y-  SS4UUU4S jjrS Y Y-  SS4UUU4S jjrSrg)	?DirectoryBasedExampleDatabase._start_listening.<locals>.HandleriG  r   r2   Nc                   > [        UT5      (       a   e[        UR                  [        5      (       d   e[        UR                  5      nUR                  R
                  nUT:X  a   UR                  5       T	UR
                  '   g T	R                  U5      nUc  g  UR                  5       nT" SXE445        g ! [         a     g f = f! [         a     g f = fr   )	r   r   r   r   r5   r   r   r   r   )
_selfr   
value_pathkey_hashrk   rl   r  r   r   hash_to_keys
         r>   
on_createdJDirectoryBasedExampleDatabase._start_listening.<locals>.Handler.on_createdJ  s    %e_==== "%..#6666!%..1
%,,11~-7A7L7L7NJOO4 !ooh/; &113E "6C<"89% #    s$   (B8 C 8
CC
CCc                   > [        UT5      (       a   e[        UR                  [        5      (       d   e[        UR                  5      nTR	                  UR
                  R                  5      nUc  g T" SUS 445        g r   )r   r   r   r   r   r5   r   )rV   r   r  rk   r  r   r  s       r>   
on_deletedJDirectoryBasedExampleDatabase._start_listening.<locals>.Handler.on_deletedl  sn    %e_====!%..#6666!%..1
!ooj&7&7&<&<=;!8c4["9:rK   c                   > [        UT5      (       a   e[        UR                  [        5      (       d   e[        UR                  [        5      (       d   e[	        UR                  5      n[	        UR                  5      nT	R                  UR                  R                  5      nT	R                  UR                  R                  5      nUb  Uc  g  UR                  5       nT" SXF445        T" SXV445        g ! [         a     g f = f)Nr.   r-   )
r   r   r   r   r   r   r5   r   r   r   )
rV   r   r   r   k1k2rl   r  r   r  s
          r>   on_movedHDirectoryBasedExampleDatabase._start_listening.<locals>.Handler.on_movedw  s    %e];;;;!%..#6666!%//37777/ 1	 __X__%9%9: __Y%5%5%:%:;:%002E "8b["9:!6B;"78	  s   C: :
DDrY   )rZ   r[   r\   r]   r  r  r  r^   )	r  r  r  r  r  r  r   r   r  s	   r>   Handlerr  G  s^     :)9O)K  :PT  :  :D	;(8?(J 	;t 	; 	;9n}&D 9 9 9rK   r  Tr   )	recursiveevent_filter)watchdog.eventsr  r  r  r  r  r  r	  watchdog.observersr
  ImportErrorrH   rI   rW   rZ   r   ru   r   r   r   r   r1   r   r   schedulestart)rV   r	  r
  rk   r  r  r  r  r  r  r  r   r   r  s        @@@@@@@@@r>   r   .DirectoryBasedExampleDatabase._start_listening-  s*   	   4 37**T=P=P2QR2Q3uSz32QR,, 22C	9 C	9"C	9T 			t4!I II*,<nM 	  	
 	E  	MM-dnn.E.E-F G5 5 " 	 Ss   C6  D86<D54D5c                     U R                   c   eU R                   R                  5         U R                   R                  5         S U l         g re   )r   stopjoinrh   s    r>   r   -DirectoryBasedExampleDatabase._stop_listening  s9    ~~)))rK   )r   r   r1   r   )rZ   r[   r\   r]   r   r   r   r   __annotations__r   r   r   r*   ri   r   r   r   r   r   r   r   r   ru   r-   r}   r.   r   r   r^   r_   r`   s   @r>   r#   r#     s   & ':NHUO9$).$9NHSM93X 3$ 3?# ?
F 
t 

"U "t "2u 2U 2t 2 8E? # #e # #J# #U #5 #T #$2% 2 2$ 2$n` rK   r#   c                      ^  \ rS rSrSrS\SS4U 4S jjrS\4S jrS\	S\
4S	 jrS
\S\\   4S jrS
\S\SS4S jrS
\S\SS4S jrSS jrSS jrSrU =r$ )r(   i  a  A wrapper to make the given database read-only.

The implementation passes through ``fetch``, and turns ``save``, ``delete``, and
``move`` into silent no-ops.

Note that this disables Hypothesis' automatic discarding of stale examples.
It is designed to allow local machines to access a shared database (e.g. from CI
servers), without propagating changes back from a local or in-development branch.
dbr2   Nc                 \   > [         TU ]  5         [        U[        5      (       d   eXl        g re   )rT   ri   r   r$   _wrappedrV   r+  rW   s     r>   ri   ReadOnlyDatabase.__init__  s&    "o....rK   c                 $    SU R                   < S3$ )NzReadOnlyDatabase(r   r-  rh   s    r>   r   ReadOnlyDatabase.__repr__  s    "4=="3155rK   r   c                 b    [        U[        5      =(       a    U R                  UR                  :H  $ re   )r   r(   r-  r   s     r>   r   ReadOnlyDatabase.__eq__  s"    %!12Vt}}7VVrK   rk   c              #   V   #    U R                   R                  U5       S h  vN   g  N7fre   )r-  ru   rt   s     r>   ru   ReadOnlyDatabase.fetch  s     ==&&s+++s   )')rl   c                     g re   rY   rq   s      r>   r-   ReadOnlyDatabase.save  r   rK   c                     g re   rY   rq   s      r>   r.   ReadOnlyDatabase.delete  r   rK   c                     g re   rY   rh   s    r>   r   !ReadOnlyDatabase._start_listening  s    rK   c                     g re   rY   rh   s    r>   r    ReadOnlyDatabase._stop_listening  r   rK   r1  r   )rZ   r[   r\   r]   r   r$   ri   r   r   r   r   r   r   r   ru   r-   r.   r   r   r^   r_   r`   s   @r>   r(   r(     s    ? t 
6# 6WF Wt W, ,8E? , e  %  $  rK   r(   c                      ^  \ rS rSrSrS\SS4U 4S jjrS\4S jrS\	S\
4S	 jrS
\S\\   4S jrS
\S\SS4S jrS
\S\SS4S jrS\S\S\SS4S jrSS jrSS jrSrU =r$ )r'   i  a  A wrapper around multiple databases.

Each ``save``, ``fetch``, ``move``, or ``delete`` operation will be run against
all of the wrapped databases.  ``fetch`` does not yield duplicate values, even
if the same value is present in two or more of the wrapped databases.

This combines well with a :class:`ReadOnlyDatabase`, as follows:

.. code-block:: python

    local = DirectoryBasedExampleDatabase("/tmp/hypothesis/examples/")
    shared = CustomNetworkDatabase()

    settings.register_profile("ci", database=shared)
    settings.register_profile(
        "dev", database=MultiplexedDatabase(local, ReadOnlyDatabase(shared))
    )
    settings.load_profile("ci" if os.environ.get("CI") else "dev")

So your CI system or fuzzing runs can populate a central shared database;
while local runs on development machines can reproduce any failures from CI
but will only cache their own failures locally and cannot remove examples
from the shared database.
dbsr2   Nc                 `   > [         TU ]  5         [        S U 5       5      (       d   eXl        g )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7fre   )r   r$   ).0r+  s     r>   	<genexpr>/MultiplexedDatabase.__init__.<locals>.<genexpr>  s     ASr:b/22Ss   )rT   ri   allr-  )rV   r@  rW   s     r>   ri   MultiplexedDatabase.__init__  s*    ASAAAAArK   c                 r    SR                  SR                  [        [        U R                  5      5      5      $ )NzMultiplexedDatabase({})z, )formatr'  mapreprr-  rh   s    r>   r   MultiplexedDatabase.__repr__  s'    (//		#dDMM:R0STTrK   r   c                 b    [        U[        5      =(       a    U R                  UR                  :H  $ re   )r   r'   r-  r   s     r>   r   MultiplexedDatabase.__eq__  s$    u12Vt}}7V	
rK   rk   c              #      #    [        5       nU R                   H7  nUR                  U5       H  nXB;  d  M
  Uv   UR                  U5        M!     M9     g 7fre   )r   r-  ru   r   )rV   rk   seenr+  rl   s        r>   ru   MultiplexedDatabase.fetch  sB     u--B#$KHHUO '  s
   1AArl   c                 L    U R                    H  nUR                  X5        M     g re   )r-  r-   rV   rk   rl   r+  s       r>   r-   MultiplexedDatabase.save  s    --BGGC  rK   c                 L    U R                    H  nUR                  X5        M     g re   )r-  r.   rS  s       r>   r.   MultiplexedDatabase.delete  s    --BIIc!  rK   ry   rz   c                 N    U R                    H  nUR                  XU5        M     g re   )r-  r}   )rV   ry   rz   rl   r+  s        r>   r}   MultiplexedDatabase.move  s    --BGGCu%  rK   c                 `    U R                    H  nUR                  U R                  5        M      g re   )r-  r   r   rV   r+  s     r>   r   $MultiplexedDatabase._start_listening  s"    --BOOD223  rK   c                 `    U R                    H  nUR                  U R                  5        M      g re   )r-  r   r   rZ  s     r>   r   #MultiplexedDatabase._stop_listening
  s$    --Bt556  rK   r1  r   )rZ   r[   r\   r]   r   r$   ri   r   r   r   r   r   r   r   ru   r-   r.   r}   r   r   r^   r_   r`   s   @r>   r'   r'     s    2_  
U# U
F 
t 

$ $8E? $   e    "% " "$ "& &U &5 &T &47 7rK   r'   c                   @  ^  \ rS rSrSrS\" SS9S4S\S\S	\S
\S\S-  4
U 4S jjjrS\4S jr	S\
S\4S jrS S jrS S jrS\S\S-  4S jrS\S-  4S jr\\S\S\4S j5       5       rS\S\\   4S jrS\S\SS4S jrS\S\S\SS4S jrS\S\SS4S jrSrU =r$ )!r%   i  a  
A file-based database loaded from a `GitHub Actions <https://docs.github.com/en/actions>`_ artifact.

You can use this for sharing example databases between CI runs and developers, allowing
the latter to get read-only access to the former. This is particularly useful for
continuous fuzzing (i.e. with `HypoFuzz <https://hypofuzz.com/>`_),
where the CI system can help find new failing examples through fuzzing,
and developers can reproduce them locally without any manual effort.

.. note::
    You must provide ``GITHUB_TOKEN`` as an environment variable. In CI, Github Actions provides
    this automatically, but it needs to be set manually for local usage. In a developer machine,
    this would usually be a `Personal Access Token <https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens>`_.
    If the repository is private, it's necessary for the token to have ``repo`` scope
    in the case of a classic token, or ``actions:read`` in the case of a fine-grained token.


In most cases, this will be used
through the :class:`~hypothesis.database.MultiplexedDatabase`,
by combining a local directory-based database with this one. For example:

.. code-block:: python

    local = DirectoryBasedExampleDatabase(".hypothesis/examples")
    shared = ReadOnlyDatabase(GitHubArtifactDatabase("user", "repo"))

    settings.register_profile("ci", database=local)
    settings.register_profile("dev", database=MultiplexedDatabase(local, shared))
    # We don't want to use the shared database in CI, only to populate its local one.
    # which the workflow should then upload as an artifact.
    settings.load_profile("ci" if os.environ.get("CI") else "dev")

.. note::
    Because this database is read-only, you always need to wrap it with the
    :class:`ReadOnlyDatabase`.

A setup like this can be paired with a GitHub Actions workflow including
something like the following:

.. code-block:: yaml

    - name: Download example database
      uses: dawidd6/action-download-artifact@v9
      with:
        name: hypothesis-example-db
        path: .hypothesis/examples
        if_no_artifact_found: warn
        workflow_conclusion: completed

    - name: Run tests
      run: pytest

    - name: Upload example database
      uses: actions/upload-artifact@v3
      if: always()
      with:
        name: hypothesis-example-db
        path: .hypothesis/examples

In this workflow, we use `dawidd6/action-download-artifact <https://github.com/dawidd6/action-download-artifact>`_
to download the latest artifact given that the official `actions/download-artifact <https://github.com/actions/download-artifact>`_
does not support downloading artifacts from previous workflow runs.

The database automatically implements a simple file-based cache with a default expiration period
of 1 day. You can adjust this through the ``cache_timeout`` property.

For mono-repo support, you can provide a unique ``artifact_name`` (e.g. ``hypofuzz-example-db-frontend``).
zhypothesis-example-db   )daysNownerrepoartifact_namecache_timeoutr1   c                 .  > [         TU ]  5         Xl        X l        X0l        X@l        [        S5      U l        Uc(  [        [        SU R                   S35      5      U l
        O[        U5      U l
        SU l        SU l        S U l        S U l        SU l        g )NGITHUB_TOKENzgithub-artifacts//Fz{This database is read-only. Please wrap this class with ReadOnlyDatabasei.e. ReadOnlyDatabase(GitHubArtifactDatabase(...)).)rT   ri   ra  rb  rc  rd  r   tokenr   r   r1   _initialized	_disabled	_artifact_access_cache_read_only_message)rV   ra  rb  rc  rd  r1   rW   s         r>   ri   GitHubArtifactDatabase.__init__U  s     	
	** "(!7
<"!$5d6H6H5I"KLDI T
DI #($ '+CGB 	rK   r2   c                 \    SU R                   < SU R                  < SU R                  < S3$ )NzGitHubArtifactDatabase(owner=z, repo=z, artifact_name=r   )ra  rb  rc  rh   s    r>   r   GitHubArtifactDatabase.__repr__  s6    +DJJ> :II= 01C1C0FaI	
rK   r   c                 "   [        U[        5      =(       ay    U R                  UR                  :H  =(       aY    U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R
                  UR
                  :H  $ re   )r   r%   ra  rb  rc  r1   r   s     r>   r   GitHubArtifactDatabase.__eq__  sn    u45 (

ekk)(		UZZ'( ""e&9&99( 		UZZ'	
rK   c                    U R                   c   S5       eU R                  (       a  g  [        U R                   5       nUR                  5       (       a  [        e S S S 5        0 U l        [        U R                   5       nUR                  5       nU H  nUR                  U5      nUR                  5       (       a"  [        5       U R
                  [        U5      '   MK  [        U5      R                  nU R
                  U   R                  [        U5      5        M     S S S 5        SU l        g ! , (       d  f       N= f! , (       d  f       N'= f! [         a$    [        R                  " S[        SS9  SU l         NWf = f)NzArtifact not loaded.zThe downloaded artifact from GitHub is invalid. This could be because the artifact was corrupted, or because the artifact was not created by Hypothesis. rE   rF   T)rk  ri  r   testzipr   rl  namelistgetinfor6   r   r   r5   r   rH   rI   r   rj  )rV   r   zfru  filenamefileinfokeypaths          r>   _prepare_for_io&GitHubArtifactDatabase._prepare_for_io  s6   ~~)A+AA)	"(A99;;$$  ) "$D(B;;= (H!zz(3H((AD**8H+=> #+8"4";";**73778JK !) ), !A )( )(  	"MMJ " "DN	"sG   E D,$E >BD=E ,
D:6E =
EE E +E<;E<c                    [        U R                  R                  5        U R                  R                  SSS9  [	        U R                  R                  S5      S S9nUS S  H  nUR                  5         M      US   nUbj  [        R                  " [        R                  5      [        R                  " UR                  R                  SS5      5      -
  U R                  :  a  X0l        OzU R#                  5       nU(       a  Ub  UR                  5         X@l        OIUb$  [$        R&                  " S	U 3[(        S
S9  X0l        O"[$        R&                  " S[(        S
S9  SU l        g U R-                  5         g ! [         a    S n GNf = f)NTr   z*.zipc                 b    [         R                  " U R                  R                  SS5      5      $ )N_:)r   fromisoformatstemreplaceas    r>   <lambda>7GitHubArtifactDatabase._initialize_db.<locals>.<lambda>  s    (00S1IJrK   r   r  r  z:Using an expired artifact as a fallback for the database:    rF   z@Couldn't acquire a new or existing artifact. Disabling database.)r   r1   r   r   sortedglobr   
IndexErrorr   nowr   utcr  r  r  rd  rk  _fetch_artifactrH   rI   r   rj  r{  )rV   cached_artifactsartifactfound_artifactnew_artifacts        r>   _initialize_db%GitHubArtifactDatabase._initialize_db  sa   $))..)		t4 "IINN7#J
 )"-HOO .	"-b1N
 %LL&$$^%8%8%@%@c%JKL  ! ,N  //1L!-"))+!-+P%&(% 	 "0V% 
 "&G  	"!N	"s   ;E8 8FFurlc                    [        USSSU R                   3S.S9nS nS n [        U5       nUR                  5       nS S S 5        Ub  [        R                  " U[        SS9  g U$ ! , (       d  f       N.= f! [         a/  nUR
                  S:X  a  SnOSnUR                  5          S nANeS nAf[         a    S	n Nv[         a    S
n Nf = f)Nzapplication/vnd.github+jsonz2022-11-28 zBearer )AcceptzX-GitHub-Api-VersionAuthorization)headersi  zAuthorization failed when trying to download artifact from GitHub. Check that you have a valid GITHUB_TOKEN set in your environment.zpCould not get the latest artifact from GitHub. This could be because the repository or artifact does not exist. z8Could not connect to GitHub to get the latest artifact. zNCould not connect to GitHub to get the latest artifact (connection timed out).r   rF   )r   rh  r   readr   coder   r   TimeoutErrorrH   rI   r   )rV   r  requestwarning_messageresponse_bytesresponsees          r>   
_get_bytes!GitHubArtifactDatabase._get_bytes  s    7(5#*4::,!7
 '+	!X!) "0 &MM/+<K9 "! 	vv}X  3   GGII 	YXO 	* 	s?   A6 A%A6 %
A3/A6 3A6 6
C	 %B**C	;C	C	c                 l   SU R                    SU R                   S3nU R                  U5      nUc  g [        R                  " U5      S   nU Vs/ s H  oDS   U R
                  :X  d  M  UPM     nnU(       d  g [        US S9nUS   nU R                  U5      nUc  g [        R                  " [        R                  5      R                  5       R                  S	S
5      nU R                  U S3-  n UR                  U5        U$ s  snf ! [         a    [         R"                  " S[$        SS9   g f = f)Nzhttps://api.github.com/repos/rg  z/actions/artifacts	artifactsr   c                     U S   $ )N
created_atrY   r  s    r>   r  8GitHubArtifactDatabase._fetch_artifact.<locals>.<lambda>'  s    ,rK   r   archive_download_urlr  r  z.zipz0Could not save the latest artifact from GitHub. rE   rF   )ra  rb  r  jsonloadsrc  maxr   r  r   r  	isoformatr  r1   r   r   rH   rI   r   )	rV   r  r  r  r  r  artifact_bytes	timestampartifact_paths	            r>   r  &GitHubArtifactDatabase._fetch_artifact  s0   -djj\499+EWX-!JJ~.{;	 )M	1vY$:L:L-LQ		M y&?@-. -!
 LL.88:BB3L			yk$66	%%n5 ; N*  	MMB!
 	s   D*D4D $D32D3rk   c                 0    [        [        U 5      S-   5      $ )Nrg  )r   r   r   s    r>   r    GitHubArtifactDatabase._key_path@  s     c
S())rK   c              #   4  #    U R                   (       a  g U R                  (       d"  U R                  5         U R                   (       a  g U R                  c   eU R                  c   eU R                  U5      n[        U R                  5       nU R                  R                  US5      nU H=  nUR                  UR                  5       5       nUR                  5       v   S S S 5        M?     S S S 5        g ! , (       d  f       MY  = f! , (       d  f       g = f7fr   )rj  ri  r  rk  rl  r   r   r   openas_posixr  )rV   rk   r   rw  	filenamesrx  r   s          r>   ru   GitHubArtifactDatabase.fetchE  s     >>  !~~~~)))!!---^^C T^^$**..r26I%WWX..01Q&&(N 21 & %$ 21	 %$s7   B
DADC5 D,	D5
D?D
DDrl   c                 ,    [        U R                  5      ere   RuntimeErrorrm  rq   s      r>   r-   GitHubArtifactDatabase.save[      42233rK   ry   rz   c                 ,    [        U R                  5      ere   r  r|   s       r>   r}   GitHubArtifactDatabase.move^  r  rK   c                 ,    [        U R                  5      ere   r  rq   s      r>   r.   GitHubArtifactDatabase.deletea  r  rK   )rl  rk  rj  ri  rm  rc  rd  ra  r1   rb  rh  r   )rZ   r[   r\   r]   r   r   r   r*   ri   r   r   r   r   r{  r  r   r  r   r  staticmethodr   r   r   r   ru   r-   r}   r.   r^   r_   r`   s   @r>   r%   r%     sH   CR 5#,!#4 $(
(
 (
 	(

 !(
 o(
 (
T
# 

F 
t 
(!T5n(c (edl (T% %N *u * *  *# #8E? #,4 4e 4 44 4U 45 4T 44% 4 4$ 4 4rK   r%   c                      ^  \ rS rSrSrS\SS4U 4S jjrS rS\4S jr	S	\
S\4S
 jrSS jrSS\S-  SS4S jjrS\S\\   4S jrS\S\SS4S jrS\S\SS4S jrS\S\S\SS4S jrSS jrSS jrSrU =r$ )BackgroundWriteDatabaseie  zA wrapper which defers writes on the given database to a background thread.

Calls to :meth:`~hypothesis.database.ExampleDatabase.fetch` wait for any
enqueued writes to finish before fetching from the database.
r+  r2   Nc                 Z   > [         TU ]  5         Xl        [        5       U l        S U l        g re   )rT   ri   _dbr   _queue_threadr.  s     r>   ri    BackgroundWriteDatabase.__init__l  s#    <AG&*rK   c                     U R                   cU  [        U R                  SS9U l         U R                   R                  5         [        R
                  " X R                  S5        g g )NT)targetdaemong?)r  r   _workerr#  weakreffinalize_joinrh   s    r>   _ensure_thread&BackgroundWriteDatabase._ensure_threadr  sI    <<!dCDLLL  T::s3  rK   c                 $    SU R                   < S3$ )NzBackgroundWriteDatabase(r   )r  rh   s    r>   r    BackgroundWriteDatabase.__repr__z  s    )$((Q77rK   r   c                 b    [        U[        5      =(       a    U R                  UR                  :H  $ re   )r   r  r  r   s     r>   r   BackgroundWriteDatabase.__eq__}  s"    %!89Sdhh%))>SSrK   c                      U R                   R                  5       u  p[        U R                  U5      " U6   U R                   R	                  5         MQ  re   )r  r   getattrr  	task_done)rV   methodrO   s      r>   r  BackgroundWriteDatabase._worker  s?    ;;??,LFDHHf%t,KK!!# rK   timeoutc                    U R                   R                     U R                   R                  (       aB  U R                   R                  R                  U5        U R                   R                  (       a  MB  S S S 5        g ! , (       d  f       g = fre   )r  all_tasks_doneunfinished_taskswait)rV   r  s     r>   r  BackgroundWriteDatabase._join  sR    [[''++..**//8 ++... (''s   AA>>
Brk   c                 X    U R                  5         U R                  R                  U5      $ re   )r  r  ru   rt   s     r>   ru   BackgroundWriteDatabase.fetch  s    

xx~~c""rK   rl   c                 `    U R                  5         U R                  R                  SX445        g r   r  r  putrq   s      r>   r-   BackgroundWriteDatabase.save  s%    #./rK   c                 `    U R                  5         U R                  R                  SX445        g r   r  rq   s      r>   r.   BackgroundWriteDatabase.delete  s%    C<01rK   ry   rz   c                 b    U R                  5         U R                  R                  SXU445        g )Nr}   r  r|   s       r>   r}   BackgroundWriteDatabase.move  s(    #U!345rK   c                 N    U R                   R                  U R                  5        g re   )r  r   r   rh   s    r>   r   (BackgroundWriteDatabase._start_listening  s    d445rK   c                 N    U R                   R                  U R                  5        g re   )r  r   r   rh   s    r>   r   'BackgroundWriteDatabase._stop_listening  s      !7!78rK   )r  r  r  r   re   )rZ   r[   r\   r]   r   r$   ri   r  r   r   r   r   r   r  floatr  r   r   ru   r-   r.   r}   r   r   r^   r_   r`   s   @r>   r  r  e  s    +? +t +48# 8TF Tt T$9UT\ 9T 9# #8E? #0 0e 0 02% 2 2$ 26 6U 65 6T 669 9rK   r  rl   c                     [        5       nU S:  d   e U S-  nU S-  n U (       a  US-  nUR                  U5        U (       d  OM1  [        U5      $ )z
Serialize an integer into variable-length bytes. For each byte, the first 7
bits represent (part of) the integer, while the last bit indicates whether the
integer continues into the next byte.

https://en.wikipedia.org/wiki/LEB128
r            )	bytearrayr   r   )rl   partsbytes      r>   _pack_uleb128r    s\     KEA::
%!FNDT  <rK   bufferc                 r    Sn[        U 5       H   u  p#US-  nXUS-  -  -  nUS-	  (       a  M     O   WS-   U4$ )zY
Inverts _pack_uleb128, and also returns the index at which at which we stopped
reading.
r   r  r  r_  )	enumerate)r  rl   ir  ns        r>   _unpack_uleb128r    sP    
 EV$L!q1uqyy % E5>rK   choicesc                    / nU  GHe  n[        U[        5      (       a  UR                  U(       a  SOS5        M5  [        U[        5      (       a  Sn[        R
                  " SU5      nO}[        U[        5      (       a(  SnUR                  SUR                  5       S-  -   SS	S
9nO@[        U[        5      (       a  SnO([        U[        5      (       d   eSnUR                  SS9n[        U5      nUS:  a$  UR                  X4-  R                  SS5      5        O>UR                  US-  R                  SS5      5        UR                  [        U5      5        UR                  U5        GMh     SR                  U5      $ )zISerialize a list of choices to a bytestring.  Inverts choices_from_bytes.           !d@   r_     bigTsigned`   r  surrogatepasserrors   rK   )r   r   r   r  structpackintto_bytes
bit_lengthr   r   encodelenr  r'  )r   r  choicetagsizes        r>   choices_to_bytesr    s@    Efd##LL&e4 fe$$C[[v.F$$C__Q):):)<)A%A5QU_VF&&Cfc****C]]/]:F6{'>LL#*..q%89LL#-11!U;<LLt,-V5 8 88E?rK   .c                Z   / nSnU[        U 5      :  Ga  X   S-	  nX   S-  nUS-  nUS:X  a  UR                  [        U5      5        ME  US:X  a  [        XS  5      u  pTX%-  nXX$-    nX$-  nUS:X  a4  US:X  d   S5       eUR	                  [
        R                  " SU5      5        OiUS:X  a%  UR                  [        R                  US	S
S95        O>US:X  a  UR                  U5        O&US:X  d   eUR                  UR                  SS95        U[        U 5      :  a  GM  [        U5      $ )Nr      r  r_  r  zexpected float64r  r  r  Tr	  rE   r   r  r  )r  r   r   r  extendr  unpackr  
from_bytesdecodetuple)r  r  idxr  r  offsetchunks          r>   _choices_from_bytesr%    s%   E
C
F
kQ{W$q!8LLd$7?*6$<8LFMCSZ(!8190009LLtU34AXLLuTBCAXLL!8O8LL_=>/ F
0 <rK   c                :     [        U 5      $ ! [         a     gf = f)z
Deserialize a bytestring to a tuple of choices. Inverts choices_to_bytes.

Returns None if the given bytestring is not a valid serialization of choice
sequences.
N)r%  	Exception)r  s    r>   choices_from_bytesr(    s&    "6**  s   
 
re   )gr   r   r  r7   r  sysr   rH   r  collections.abcr   r   r   r   r   	functoolsr   hashlibr	   r
   r   pathlibr   r   queuer   	threadingr   typingr   r   r   r   r   r   urllib.errorr   r   urllib.requestr   r   zipfiler   r   hypothesis.configurationr   hypothesis.errorsr   r   %hypothesis.internal.conjecture.choicer   hypothesis.utils.conventionsr    r!   hypothesis.utils.deprecationr"   __all__watchdog.observers.apir)   r   r*   r)  r!  r   r+   r,   r/   r0   r   r?   rJ   ABCMetarM   modulessphinx.ext.autodocra   	signature'sphinx.ext.autodoc._dynamic._signaturesextautodoc_dynamic_signatures_moduler!  r   _METACLASS_CALL_BLACKLIST	frozensetr   r'  r$   r&   r   r#   r(   r'   r%   r  r  r  r  r  r%  r(  rY   rK   r>   <module>rG     s      	  
    . 2 2    "    - + ' 6 D 9 B 9 3HSM)) )UE\*	9 *uedl23Y 3	'&/9
$%gh.?.L(MM 	    0# 56	9 6h 4 & FJ/
%
%
(;
;d
B//61ckk 1H s{{=!:		)EE
 g77CC070Q0QU 1G- --44Y?
A
 A
H/o /d(u ( (|O |~$ $NA7/ A7HS4_ S4l
;9o ;9|  0E eCHo %hw/ %u %P U7C<-@ >u E'3,,?$,F i#  	)jj((G	)  s<   I2 I .-I2 I2 I/+I2 .I//I2 2I;:I;