
    &ge	                        d Z ddlZddlmZ ddlZddlZdededdfdZ	dededefd	Z
d
gZedk    rY ed           ddlZ ed          D ]1Z ej                    \  ZZer nedz  dk    rer edez             2 ed           dS dS )zFunctions for parallel computation on multiple cores.

Introduced in Python-RSA 3.1.

.. note::

    Requires Python 2.6 or newer.

    N)
Connectionnbitspipereturnc                     	 t           j                            |           }t           j                            |          r|                    |           d S V)N)rsarandnumread_random_odd_intprimeis_primesend)r   r   integers      >/var/www/api/venv/lib/python3.11/site-packages/rsa/parallel.py_find_primer       sR    +11%88 9g&& 	IIgF    poolsizec                     t          j        d          \  }	  fdt          |          D             }|D ]}|                                 |                                }|                                                                  n-# |                                                                  w xY w|D ]}|                                 |S )aU  Returns a prime number that can be stored in 'nbits' bits.

    Works in multiple threads at the same time.

    >>> p = getprime(128, 3)
    >>> rsa.prime.is_prime(p-1)
    False
    >>> rsa.prime.is_prime(p)
    True
    >>> rsa.prime.is_prime(p+1)
    False

    >>> from rsa import common
    >>> common.bit_size(p) == 128
    True

    F)duplexc                 J    g | ]}t          j        t          f            S ))targetargs)mpProcessr   ).0_r   	pipe_sends     r   
<listcomp>zgetprime.<locals>.<listcomp>A   s-    bbbQ;eY5GHHHbbbr   )r   Piperangestartrecvclose	terminate)r   r   	pipe_recvprocspresultr   s   `     @r   getprimer(   *   s    &  WE222Y		bbbbbRWX`RaRabbb 	 	AGGIIII!! 	   	Ms   A	B *B8r(   __main__z'Running doctests 1000x or until failured   
   z%i timeszDoctests done)__doc__multiprocessingr   multiprocessing.connectionr   	rsa.primer   rsa.randnumintr   r(   __all____name__printdoctestr   counttestmodfailurestests r   r   <module>r;      sE        1 1 1 1 1 1        s *     %C %3 %3 % % % %P ,z	E
3444NNNs & &+GO--5 	E2:??u?E*u$%%%	E/ r   