summaryrefslogtreecommitdiff
path: root/rsa/parallel.py
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2016-01-22 11:36:06 +0100
committerSybren A. Stüvel <sybren@stuvel.eu>2016-01-22 11:36:06 +0100
commitd3d10345b47c2b17922bb91059cfceea82f82338 (patch)
tree6a336d74ee41a4ba98b6b3d97f123cd0c5f4e9b7 /rsa/parallel.py
parent541ee468b6b33c7ae27818bbfea63df9622f9d8a (diff)
downloadrsa-git-d3d10345b47c2b17922bb91059cfceea82f82338.tar.gz
Big refactor to become more PEP8 compliant.
Mostly focused on docstrings (''' → """), indentation, empty lines, and superfluous parenthesis.
Diffstat (limited to 'rsa/parallel.py')
-rw-r--r--rsa/parallel.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/rsa/parallel.py b/rsa/parallel.py
index 17a10ed..36c06ba 100644
--- a/rsa/parallel.py
+++ b/rsa/parallel.py
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-'''Functions for parallel computation on multiple cores.
+"""Functions for parallel computation on multiple cores.
Introduced in Python-RSA 3.1.
@@ -22,7 +22,7 @@ Introduced in Python-RSA 3.1.
Requires Python 2.6 or newer.
-'''
+"""
from __future__ import print_function
@@ -31,6 +31,7 @@ import multiprocessing as mp
import rsa.prime
import rsa.randnum
+
def _find_prime(nbits, pipe):
while True:
integer = rsa.randnum.read_random_int(nbits)
@@ -43,8 +44,9 @@ def _find_prime(nbits, pipe):
pipe.send(integer)
return
+
def getprime(nbits, poolsize):
- '''Returns a prime number that can be stored in 'nbits' bits.
+ """Returns a prime number that can be stored in 'nbits' bits.
Works in multiple threads at the same time.
@@ -55,12 +57,12 @@ def getprime(nbits, poolsize):
True
>>> rsa.prime.is_prime(p+1)
False
-
+
>>> from rsa import common
>>> common.bit_size(p) == 128
True
-
- '''
+
+ """
(pipe_recv, pipe_send) = mp.Pipe(duplex=False)
@@ -79,20 +81,19 @@ def getprime(nbits, poolsize):
return result
+
__all__ = ['getprime']
-
if __name__ == '__main__':
print('Running doctests 1000x or until failure')
import doctest
-
+
for count in range(100):
(failures, tests) = doctest.testmod()
if failures:
break
-
+
if count and count % 10 == 0:
print('%i times' % count)
-
- print('Doctests done')
+ print('Doctests done')