a
    db                     @   s   d Z ddlmZ ddlZddlZddlZdd Zdd Z	dgZ
edkred	 ddlZed
D ]4Ze \ZZerv qer^ed dkr^ede  q^ed dS )zFunctions for parallel computation on multiple cores.

Introduced in Python-RSA 3.1.

.. note::

    Requires Python 2.6 or newer.

    )print_functionNc                 C   s,   t j| }t j|r || d S q d S )N)rsaZrandnumZread_random_odd_intprimeZis_primesend)nbitspipeinteger r	   ]/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python3.9/site-packages/rsa/parallel.py_find_prime#   s    
r   c                    s   t jdd\}zF fddt|D }|D ]}|  q.| }W |    n|    0 |D ]}|  qn|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)Zduplexc                    s   g | ]}t jt fd qS ))targetargs)mpProcessr   ).0_r   Z	pipe_sendr	   r
   
<listcomp>D   s   zgetprime.<locals>.<listcomp>)r   ZPiperangestartrecvclose	terminate)r   ZpoolsizeZ	pipe_recvZprocspresultr	   r   r
   getprime-   s    




r   __main__z'Running doctests 1000x or until failured   
   z%i timeszDoctests done)__doc__
__future__r   multiprocessingr   Z	rsa.primer   Zrsa.randnumr   r   __all____name__printdoctestr   counttestmodZfailurestestsr	   r	   r	   r
   <module>   s"   

)