Skip to content

Commit e24c027

Browse files
authored
Merge pull request #182 from hugovk/fix-flake8-2020
Fix for Python 3.10, 4 and 10
2 parents 7a24229 + 0cbfad8 commit e24c027

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/ecdsa/keys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
import binascii
7070
from hashlib import sha1
71-
from six import PY3, b
71+
from six import PY2, b
7272
from . import ecdsa
7373
from . import der
7474
from . import rfc6979
@@ -823,7 +823,7 @@ def from_pem(cls, string, hashfunc=sha1):
823823
"""
824824
# the privkey pem may have multiple sections, commonly it also has
825825
# "EC PARAMETERS", we need just "EC PRIVATE KEY".
826-
if PY3 and isinstance(string, str):
826+
if not PY2 and isinstance(string, str):
827827
string = string.encode()
828828
privkey_pem = string[string.index(b("-----BEGIN EC PRIVATE KEY-----")):]
829829
return cls.from_der(der.unpem(privkey_pem), hashfunc)

src/ecdsa/numbertheory.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from __future__ import division
1313

14-
from six import integer_types, PY3
14+
from six import integer_types, PY2
1515
from six.moves import reduce
1616
try:
1717
xrange
@@ -198,11 +198,11 @@ def square_root_mod_prime(a, p):
198198
return (2 * a * pow(4 * a, (p - 5) // 8, p)) % p
199199
raise RuntimeError("Shouldn't get here.")
200200

201-
if PY3:
202-
range_top = p
203-
else:
201+
if PY2:
204202
# xrange on python2 can take integers representable as C long only
205203
range_top = min(0x7fffffff, p)
204+
else:
205+
range_top = p
206206
for b in xrange(2, range_top):
207207
if jacobi(b * b - 4 * a, p) == -1:
208208
f = (a, -b, 1)

src/ecdsa/util.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import binascii
66
import sys
77
from hashlib import sha256
8-
from six import PY3, int2byte, b, next
8+
from six import PY2, int2byte, b, next
99
from . import der
1010
from ._compat import normalise_bytes
1111

@@ -17,7 +17,7 @@
1717
oid_ecPublicKey = (1, 2, 840, 10045, 2, 1)
1818
encoded_oid_ecPublicKey = der.encode_oid(*oid_ecPublicKey)
1919

20-
if sys.version > '3':
20+
if sys.version_info >= (3,):
2121
def entropy_to_bits(ent_256):
2222
"""Convert a bytestring to string of 0's and 1's"""
2323
return bin(int.from_bytes(ent_256, 'big'))[2:].zfill(len(ent_256)*8)
@@ -27,7 +27,7 @@ def entropy_to_bits(ent_256):
2727
return ''.join(bin(ord(x))[2:].zfill(8) for x in ent_256)
2828

2929

30-
if sys.version < '2.7':
30+
if sys.version_info < (2, 7):
3131
# Can't add a method to a built-in type so we are stuck with this
3232
def bit_length(x):
3333
return len(bin(x)) - 2
@@ -76,10 +76,10 @@ def __init__(self, seed):
7676
def __call__(self, numbytes):
7777
a = [next(self.generator) for i in range(numbytes)]
7878

79-
if PY3:
80-
return bytes(a)
81-
else:
79+
if PY2:
8280
return "".join(a)
81+
else:
82+
return bytes(a)
8383

8484
def block_generator(self, seed):
8585
counter = 0

0 commit comments

Comments
 (0)